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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listboxes and javascript

Status
Not open for further replies.

farazmit

Programmer
Jan 3, 2005
14
0
0
US
Hi
I have a listbox and I am using javascript to fill in the values. I have a function which takes an array as input and is supposed to put them inside the drop-down listbox.
I donno how to add the <option> and </option> html tags while I am using javascript.
Here is the code I have:
<select name="select2">
<script type="text/javascript">
function cArray(x)
{
for (loop5 = 0; loop5 < x.length; loop5++){
// I can't use <option> and </option> in here
// cause I am in middle of javascript
// I can't use it outside of script either because
// number of options depend on number of values in
// the array
<option> x[loop5]</option>
}
}
</script>
</select>

Thanks for your help
 
In this case, you would use
Code:
document.writeln("<option>" + x[loop5] + "</option>");

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Hi Again
I tried it but it only gives me the list of array values in a new page but I wasnt the values to go into my dropdown list/menu on the current page.
Thanks again
 

Try this

function cArray(x)
{
for (loop5 = 0; loop5 < x.length; loop5++)
{
var jText = "display text";
var jVal = x[llop5];
var fldOption = new Option(jText,jVal,false,false);
fieldName.options[fieldName.length] = fldOption;

}
}



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top