473,224 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

How to make a Radio ButtonValue = A javascript variable

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.
Mar 29 '07 #1
1 1266
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <body onload="setvalue();">
  2. <script>
  3. function setvalue() {
  4. document.getElementById("radioButton").value = country
  5. }
  6. </script>
  7. <input name="radioButton" id="radioButton" type="radio" class="box" value="" checked="checked" "/>
  8.  
You need to make sure that country is a global variable... meaning setting it out of a function EX.
This would work
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. var country = '';
  3. function blah() {
  4. country = "USA";
  5. }
  6. </script>
  7.  
This wouldn't work
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function blah() {
  3. country = "USA";
  4. }
  5. </script>
  6.  
because it was set inside the function only so when another function tries to call that variable it will return nothing. But since in the first code it was first declared outside of the function it can be used again on the page outside of that function.
Mar 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Phil Powell | last post by:
<b>Agency 4</b> <input type="radio" name="permission" value="1" checked> Yes <input type="radio" name="permission" value="0" > No <br> <b>Agency 5</b> <input type="radio" name="permission"...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
2
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
4
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1>...
1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
2
by: Mark Haase | last post by:
Hey All-- I'm rusty on my JavaScript but I'm pulling it back out to do a PHP/MySQL database application. I'm doing all the validation in PHP, but I'm using JavaScript to show/hide questions...
2
by: Karl | last post by:
Hi experts, I have a little problem with datagrid needing your expertise. In database, I have a column called "Active" which has only 2 values "Yes" and "No". In my application, I want to show...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
5
by: satyabhaskar | last post by:
hi all, In my web page i have created radio buttons dynamically on to the page .....following is my code string Course, Semester, Section; int rowsCount; string con =...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.