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!

Accessing select boxes in JS functions???

Status
Not open for further replies.

Albuckj

Programmer
Jan 10, 2002
11
GB
I have realised that I can't access a select boxes' text values (using boxname.options[x].text) from within a Javascript function. The only place I can is just surrounding some JS code with the script tags int the body. Even if I put in in a function in the body it can't see it. It says:
'document.form1.boxname' is not an object

What am I doing wrong????
 
hi!!

i put in this document some example that will help you(i hope) to understand the select box.

note that you can change the text inside the box and its value, but adressing to options[0] will get you to the box header rather than its first element.....


<HTML>
<HEAD>
<TITLE></TITLE>
<script language=&quot;javascript&quot;>
function Calculate(){
var frm = document.forms[&quot;frm1&quot;];
frm.target.value =frm.from.value + frm.to.value;

}

</script>
</HEAD>
<BODY BGCOLOR=&quot;#FFFFFF&quot; TEXT=&quot;#000000&quot; LINK=&quot;#0000FF&quot; VLINK=&quot;#800080&quot;>
<form name=&quot;frm1&quot;>
<select size=&quot;1&quot; name=&quot;from&quot; onchange=&quot;Calculate();&quot;>
<option selected>-- Please Choose --</option>
<option value=&quot;a&quot;>a</option>
<option value=&quot;b&quot;>b</option>
</select>
<select size=&quot;1&quot; name=&quot;to&quot; onchange=&quot;Calculate();&quot;>
<option selected>-- Please Choose --</option>
<option value=&quot;1&quot;>1</option>
<option value=&quot;2&quot;>2</option>
</select>
<input type=&quot;text&quot; name=&quot;target&quot; size=&quot;20&quot;>
</form>
<script language=&quot;javascript&quot;>
document.forms[&quot;frm1&quot;].from.options[1].text = &quot;X&quot;;
document.forms[&quot;frm1&quot;].from.options[1].value = &quot;XaX&quot;;

</script>

</BODY>
</HTML>


goodluck!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top