antgaudi Posted March 6, 2009 Share Posted March 6, 2009 I'm trying to use the for next loop to display on answer3.innerHTML the name of each array element from john's original string on a different line.Thanks.<html><head><script language="vbscript"><!--sub fred john_val=window.document.alice.john.value john_words=ubound(split(john_val)) +1 answer1.innerHTML=john_words dim joarsp joarsp=split(john_val, " ") answer2.innerHTML=joarsp(0)+cstr(" ")+joarsp(12) for i=1 to john_words john_words=joarsp&i&"<br>" next answer3.innerHTML=john_words end sub--></script></head><body><form name="alice">The string john = <input type="text" size="60" name="john" value="this is a string for the purpose of playing with string coding tools"></form><ol><li><span id="answer1">this is the contents of the span block with id answer1</span><li><span id="answer2">this is the contents of the span block with id answer2</span><li><span id="answer3">this is the contents of the span block with id answer3</span></ol><br><input type="button" value="GO" onClick="fred"></body></html> Link to comment Share on other sites More sharing options...
dsonesuk Posted April 1, 2009 Share Posted April 1, 2009 first: you are using the john_words total value of words, within the for loop to a store text array element value???second: you are overwriting the text array value with the next, instead of adding/joining to the next text array value plus html coding, and then showing total content together at the end.anyway, try this<html><head><script language="vbscript"><!--sub fredjohn_val=window.document.alice.john.valuejohn_words=ubound(split(john_val)) +1answer1.innerHTML=john_wordsdim joarspjoarsp=split(john_val, " ")answer2.innerHTML=joarsp(0)+cstr(" ")+joarsp(12)for i=0 to john_words-1john_words_temp=john_words_temp&joarsp(i)&"<br>"nextanswer3.innerHTML=john_words_tempend sub--></script></head><body><form name="alice">The string john = <input type="text" size="70" name="john" value="this is a string for the purpose of playing with string coding tools"></form><ol><li><span id="answer1">this is the contents of the span block with id answer1</span><li><span id="answer2">this is the contents of the span block with id answer2</span><li><span id="answer3">this is the contents of the span block with id answer3</span></ol><br><input type="button" value="GO" onClick="fred"></body></html> Link to comment Share on other sites More sharing options...
antgaudi Posted April 14, 2009 Author Share Posted April 14, 2009 I'll try that. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.