Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to show each word in an array on each line in vbscript.
I've tried:
dim ray(2)
ray(0)="ray1"
ray(1)="ray2"
ray(2)="ray3"for i=0 to 2
document.write("
" & ray(i))
nextThe code above works but I now need to get words in an array and show each word on a different line in a span block named answer3.
The answer I currently get is only "tools" from the "john" string..
The code I have is:<html>
<head>
<script language="vbscript">
<!--
sub fred
john_val=window.document.alice.john.valuedim joarsp
joarsp=split(john_val, " ")
answer2.innerHTML=joarsp(0)+cstr(" ")+joarsp(12)
for i=0 to 12
answer3.innerHTML=(joarsp(i) & "
")
next
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="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>
<input type="button" value="GO" onClick="fred">
</body>
</html>Thanks.

for ... answer3.innerHTML=(joarsp(i) & "")If the code is as you've posted, then the above looks as though it would store and overwrite each element of joarsp with each iteration of i, so the final value of answer3 would be joarsp[12] or whatever element was the last to have a valid result.
You'd *probably* want answer3.innerHTML = answer3.innerHTML & joarsp(i) & "<br />"
However, that would store whatever value answer3 had prior to calling fred(), so you'd need to erase its value whenever you call the routine.
I'm not sure on the correct syntax of vbs though as I'm not used to it.
HTH

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |