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

PostBack(Object) from select option

Status
Not open for further replies.

mike10101

Vendor
May 6, 2005
13
GB
Hi,

here is the javascript i'm using,

<script language="JavaScript">
<!--
function PostBack(Object)
{document.form1.yourTextField.value=Object.value}
//-->
</script>

here is the option list,

<select name="frm_agency" onClick="PostBack(this)">
<option value="1">OPTION1</option>
</select>


What I want to do is return the Option content ie 'OPTION1' into document.form1.yourTextField and not the value, how can I do this? any help would be greatly appreciated.


 
Code:
<script language="JavaScript">
<!--
function PostBack(o) {
    document.forms['form1'].elements['yourTextField'].value=o.innerText;
}
//-->
</script>

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Thanks for the quick response,

how can I do it so it only returns the selected option content and not all the options
 
Code:
<script language="JavaScript">
<!--
function PostBack(o) {
    var theVal = o.options[o.selectedIndex].innerText;
    document.forms['form1'].elements['yourTextField'].value=theVal;
}
//-->
</script>

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
nice one!!! that would have taken me about 2 years to have worked out... do you know of any good books so I can learn this stuff myself.
 
Note: innerText is not cross-browser - it appears not to work in NN or FF.

You could use .innerHTML (which works in most browsers even though it's not part of any standard, AFAIK), or ".firstChild.nodeValue" (assuming a text node already exists).

Hope this helps,
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top