Computing.Net > Forums > Web Development > Show words of array in a diff line

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Show words of array in a diff line

Reply to Message Icon

Name: antgaudi
Date: March 21, 2009 at 01:05:13 Pacific
OS: Windows XP
CPU/Ram: 1.5 GHz / 495 MB
Product: Hewlett-packard / Hp pavilion notebook pc
Subcategory: General
Comment:

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))
next

The 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.value

dim 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.



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: March 21, 2009 at 15:37:06 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Show words of array in a diff line

Getting third line from file www.computing.net/answers/webdevel/getting-third-line-from-file/2416.html

height of elements in css www.computing.net/answers/webdevel/height-of-elements-in-css/2186.html

instance array in flash mx? www.computing.net/answers/webdevel/instance-array-in-flash-mx/807.html