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!

Set Radio Button Value to a Predefined Jaavscript Value?

Status
Not open for further replies.

hulkamani

IS-IT--Management
Mar 29, 2007
1
US
Hi I have what seems like a simple question but it has baffled me for hours now. How do I set the value of an HTML radio button to a predefined javascript value? I am trying to get the value of radioButton to = the javascript variable named countryText which is defined earlier in the page.

The following does not work obviously:

<input name="radioButton" type="radio" class="box" value="javascript:countryText" checked="checked" "/>

Any advice? thanks.
 
without using a server side language, you can't do it "on-the-fly".

However you can set the value = AFTER the HTML element exists. Done like so:

Code:
<input id="thisButton" name="radioButton" type="radio" class="box" value="javascript:countryText" checked="checked" "/>
<script type="text/javascript">
   document.getElementById("thisButton").value = countryText;
</script>

You can put that code directly beneath your button, or (better practice) put in on the onload function of the page.




[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top