473,385 Members | 1,764 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,385 software developers and data experts.

radio button

26
scribes

I have the following code for radio buttons
dim line
<input type ="radio" name="line_type" value="isdn"> isdn
<input type ="radio" name="line_type" value="lse"> lse

what i want is that for a button when clicked
if isdn is checked then line=isdn
else
if lse is checked then line=lse
else
alert ("no option selected")
Apr 10 '08 #1
1 1137
DrBunchman
979 Expert 512MB
Hi change,

There are actually two parts to your question here; assiging a value from a radio button & validating your form.

If you want to assign a value to the variable sLine then you need to submit your form back to the same page and request the value of the radio button. Here is an example:

thispage.asp:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim sLine
  3. sLine = request.form("line_type")
  4. %>
  5. <form name="form1" action="thispage.asp" method="post">
  6.      <input type ="radio" name="line_type" value="isdn">isdn</input>
  7.      <input type ="radio" name="line_type" value="lse">lse</input>
  8.      <input type="submit" value="Submit" /> 
  9. </form>
  10.  
If you want to add some validation (in this case checking whether a radio button has been selected) then you could use some javascript. You could add something like this in between your head tags:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3. function RadioChecked()
  4. {
  5. var checked = false;
  6. for (var i=0;i<document.form1.line_type.length;i++)
  7. {
  8.     if (document.form1.line_type[i].checked)
  9.     {
  10.      checked = true; 
  11.     }
  12. }
  13. if (checked == true)
  14.     {
  15.     return true;
  16.     }
  17. else
  18.     {
  19.     alert('No option selected') 
  20.     return false;
  21.     }    
  22. }
  23. </script>
  24.  
  25.  
Then add OnClick="return RadioChecked();" to your submit button.

The above script loops through all the check boxes in the list and returns a value of 'true' to your form if it finds one that is checked, allowing it to submit.

Does this all make sense? Let me know how it goes,

Best regards,

Dr B
Apr 10 '08 #2

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

Similar topics

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>...
5
by: Digital Puer | last post by:
I have the following HTML form: - radio button A (default selected) - radio button B - input field, of type "file" with "Choose" button - submit button I would like to have it so that if the...
3
by: John Davis | last post by:
I created a ASP.NET Web Form using VB.NET with a text box, 2 radio buttons. When the user click the first radio button, the text will change to uppercase. If the user clicks the other radio button,...
3
by: Amelyan | last post by:
When we want radio button to belong to a group name we say, radio1.GroupName="GroupA". In this case, radio1 will be unselected if another radio button is selected in "GroupA". Is there a way...
8
by: David Cameron | last post by:
I noticed that using an HTMLInputRadioButton and specifying a value to be an empty string (""), this is overridden by ASP.Net which set the value of the control to be the same as the ID of the...
1
by: Joe Attardi | last post by:
Hi all, On a form on one of my pages I have two <select> elements, and each one is paired up with a radio button. The idea is to choose an item from one list or the other and select the radio...
9
by: IchBin | last post by:
I can not see what the problem is with this script. I am just trying to set a radio button by calling setCheckedValue('abbr_letter', 'V'). Sorry I am new to javascript. <html> <head> <script...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
0
by: jehugaleahsa | last post by:
Hello: I have radio buttons bound to boolean properties in a business object. private void bindRadioButton(RadioButton button, string propertyName) { Binding binding =...
8
by: photoboy | last post by:
I have racked by brain long enough on this, so now I need the help of someone who knows what they are doing. Here is what I am trying to achieve: First, I have two radio buttons (both unchecked)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.