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

Select box error

Status
Not open for further replies.

Albuckj

Programmer
Jan 10, 2002
11
GB
This piece of script does exactly what I want it to but it comes up with an error on the

following line: ops = document.form1.poss.options.text;
error = 'document.form1.poss.options[...].text' is not an object

poss is the name of my select box. If I put a number in the error line in place of i (at

options), say 4, it prints out the text of select box value number 4, and there are no

errors.

With the way I have done it, it is perfect except that this error comes up. Why?????

<script>
ops = new Array();
var total = document.form1.poss.options.length;
var temp;
document.write(&quot;Select box option numbers: &quot;+total+&quot;<BR>&quot;);
for (i=0;i<=total;i++)
{
ops = document.form1.poss.options.text;
document.write(ops+&quot;<BR>&quot;);
}
</script>
 
Try this:

<script>
ops = new Array();
var total = document.form1.poss.options.length;
var temp;
document.write(&quot;Select box option numbers: &quot;+total+&quot;<BR>&quot;);
for (i=0;i<=total;i++)
{
ops = document.form1.poss.options.text;
document.write(ops+&quot;<BR>&quot;);
}
</script> My site: msn/email: matthiasdeschagt@hotmail.com
icq: 123118841
online
 
I've noticed that in my original message it missed out any occurance where I wrote 'i' in square brackets, and it turned my text into italic from that moment onwards. Anyone know why?
Cyberwolf14 => I think you had the same problem. From a square brackets with an i in onwards, your text is italic.
 
Hang on, I know the problem now, an i with square brackets around changes everything to italic. I've changed it to x now. Cyberwolf => Can u re-reply with your suggested code? Cheers:

<script>
ops = new Array();
var total = document.form1.poss.options.length;
document.write(&quot;Select box option numbers: &quot;+total+&quot;<BR>&quot;);
for (x=0;x<=total;x++)
{
ops[x] = document.form1.poss.options[x].text;
document.write(ops[x]+&quot;<BR>&quot;);
}
</script>
 
Hello again,

if you use this:

<form name=&quot;form1&quot;>
<select name=&quot;poss&quot;>
<option value=&quot;test1&quot;>test1</option>
<option value=&quot;test2&quot;>test2</option>
</select>
</form>

than document.form1.poss.options[x].text is wrong, use
document.form1.poss.options[x].value My site: msn/email: matthiasdeschagt@hotmail.com
icq: 123118841
online
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top