Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.value will not read multi-select fields correctly...what will?

Status
Not open for further replies.

rem736

Programmer
Mar 18, 2003
5
US
hi,

on client-side, i have a form with 2 fields and 2 buttons (1 text, 1 multi-select list, next button, submit button). after the user enters the info, clicking on the "next" button will allow the user additional iterations of the same entry form. clicking on the submit button will send data to server-side for processing.

behind the scenes i created hidden inputs to store the info for each iteration. i used the document.formname.fieldname.value property to assign values to the hidden fields.

this works for the first field (text). however, for the second field (if i chose two items from the multi-select list), it only assigns the top-most item chosen to the hidden field.

is there a way around this?

thank you for any ideas.

rem736.
 
It sounds like problem is more with JavaScript than VBScript. Here's an example of how to get ALL the values:

<html>
<head>

<script type=&quot;text/javascript&quot;>
function validate()

{
var x = new Array();
for (var i = 0; i < document.Form1.numbers.options.length; i++)
if (document.Form1.numbers.options.selected)
x[x.length] = document.Form1.numbers.options.value;
alert(x)
}
</script>
</head>

<body>
<form name=&quot;Form1&quot; action=&quot;tryjs_submitpage.htm&quot; onsubmit=&quot;return validate()&quot;>

<select multiple name=&quot;numbers&quot;>
<option value=&quot;one&quot;>One
<option value=&quot;two&quot;>Two
<option value=&quot;three&quot;>Three
<option value=&quot;four&quot;>Four
</select>
<br>
<input type=&quot;submit&quot; value=&quot;Send&quot;>

</form>
</body>
</html>

Let me know if this works.
 
hi khazmir,

thank you. after looking at your code, i decided to look for an equivalent in VBScript. the options.selected property in javascript is the same as the Item(n).selected property in VBScript.

the following is my code:

<html>
<head>
<script language = &quot;VBScript&quot;>
Sub new_iteration_onClick
test.first1.value = test.first.value
for n = 0 to test.hobby.options.length-1
if test.hobby.Item(n).selected = true then
test.hobby1.value = test.hobby1.value & &quot;, &quot; & test.hobby.Item(n).value
end if
next
Msgbox(&quot;Name: &quot; & test.first1.value & &quot;. &quot; & &quot;Hobby: &quot; & test.hobby1.value & &quot;.&quot;)
End Sub
</script>

</head>
<body>
<form name = &quot;test&quot; id = &quot;test&quot;>
first name <input type = text name = &quot;first&quot;><br>
hobby<br>
<select multiple name=hobby size=4>
<option value=&quot;TV&quot; selected>TV
<option value=&quot;Stereo&quot;>Stereo
<option value=&quot;Movies&quot;>Movies
<option value=&quot;Games&quot;>Games
</select><br><br>

<input name=&quot;new_iteration&quot; type=button value=&quot;Next&quot;><br><br>

<input type = hidden name = &quot;first1&quot;>
<input type = hidden name = &quot;hobby1&quot;>
</form>
</body>
</html>


thanks again for pointing me in the right direction.

<rem736>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top