0

i am developing a gadget and i am using JavaScript to change innerHTML of span, but after some operations i need to read that value. Additionally i am using pre-entered value for spans but when i try to read new data function loads pre-entered one. Is there any solution for that?

JS:

function read_write(condition,filename){
    var fso  = new ActiveXObject('Scripting.FileSystemObject');
    var fh = fso.OpenTextFile(System.Gadget.path+'\\'+filename+'.txt',condition, true,-2);
    if (condition == 1) {
    var result = fh.ReadLine();
    return result;      
    } 
    else if (condition == 2) {
    var spn1 = document.getElementById('span1').innerHTML;
    fh.WriteLine(spn1+','+document.getElementById('span2').innerHTML);
    }
    fh.Close();
}

HTML:

<table id="sonuc">
  <tbody>
    <tr>
      <td style="width:50%" valign="top">
        <span class="result" id="span1"></span><br/>
        <span class="result" id="span2"></span>
      </td>
    </tr>
  </tbody>
</table> 
Alper
  • 1,085
  • 3
  • 20
  • 39
  • 1
    Can you post some code to show what you're trying to do? What type of gadget are you developing - Google Gadget, Windows Gadget, etc. – Andy E Mar 22 '10 at 19:10
  • @Alper .. for now you question doesn't make any sense ..maybe sharing some code would help – ant Mar 22 '10 at 19:14
  • I am sorry for insufficient information. I am trying to coding a Vista/7 Sidebar Gadget and trying to write a function for saving values to harddisk. Function: function read_write(){ var fso = new ActiveXObject('Scripting.FileSystemObject'); var fh = fso.OpenTextFile(System.Gadget.path+'\\fl.txt',2, true,-2); var spn1 = document.getElementById('span1').innerHTML; fh.WriteLine(spn1+','+document.getElementById('span2').innerHTML); } fh.Close(); } I used spn1 variable to try if using variable works... Thanks to everyone.. – Alper Mar 23 '10 at 08:26
  • HTML part of coding is:

    – Alper Mar 23 '10 at 08:43
  • @Alper: I've added your code to the question. There's a syntax error in your code (an extra `}` just before `fh.Close()`), I left it in because I thought something might be missing from what you've pasted. If so, you can edit it using the link right underneath the question tags. – Andy E Mar 23 '10 at 15:10
  • @Andy E: Yes i've not written all the function because unwritten part is just about reading, so i corrected the code part. Still problem is continued. – Alper Mar 25 '10 at 10:54

1 Answers1

0

If you're using innerHTML to write to the span element, you should be able to use it again to read. How are you trying to read until now?

Fábio Batista
  • 25,002
  • 3
  • 56
  • 68
  • I am using document.getElementById('span1').innerHTML = data[0]; to change inner part of span as you can guess, data is an array of some values... – Alper Mar 23 '10 at 09:51