473,387 Members | 3,821 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,387 software developers and data experts.

Javascript -- go to URL based on radion button sets selection

Hello, I'd trying to write a script that would on clicking submit go to various URLs based on selected radio buttons. I have three sets of radio buttons, and depending on the combination (one button from every set), there will be a different .html page to go on submit.
Is it possible?
I an new to javascript and appreciate any help/directions!
Attached Images
File Type: jpg javascript.jpg (15.9 KB, 379 views)
Jul 24 '11 #1
3 3494
Dormilich
8,658 Expert Mod 8TB
nope, won’t work this way.

if you submit a form, it will always go to the URL given in the form’s action attribute (which is exactly one). after that, you have left the page and JS cannot work on that same page.

However, if you use AJAX, you can send form data to as many URLs as you want, since you don’t leave the page. the "downside" is that you have to collect and pass the data to send yourself.
Jul 24 '11 #2
Thanks for your answer. I was hoping to use something similar to this script:

Expand|Select|Wrap|Line Numbers
  1. function checkInput(){
  2.     var val = document.getElementById('myText').value;
  3.     var myForm = document.getElementById('myForm');
  4.     if(val=="valueX")
  5.     myForm.action="page1.html";
  6.             else
  7.                     myForm.action="page2.html";
  8.             }
But I'd need to validate all the radio buttons first and based on the values select the appropriate html page. That's where I get stuck.
Jul 24 '11 #3
Dormilich
8,658 Expert Mod 8TB
if you want to change the action URL based on a selection, that’s something different.

I’m not sure how the 3 different lists come into play, but for a single list that would be easy. all you need is make a radio button change the action URL when being clicked.
Expand|Select|Wrap|Line Numbers
  1. // not taking the page layout into account
  2. <form action="">
  3.   <input type="radio" name="targeturl" value="page1.html" id="url1">
  4.   <label for="url1">Choice 1</label>
  5.  
  6.   <input type="radio" name="targeturl" value="page2.html" id="url2">
  7.   <label for="url2">Choice 2</label>
  8.  
  9.   <input type="radio" name="targeturl" value="page3.html" id="url3">
  10.   <label for="url3">Choice 3</label>
  11.  
  12.   <input type="radio" name="targeturl" value="page4.html" id="url4">
  13.   <label for="url4">Choice 4</label>
  14. </form>
Expand|Select|Wrap|Line Numbers
  1. // the event handler
  2. function changeAction()
  3. {
  4.     this.form.action = this.value;
  5. }
  6.  
  7. // assign the handlers
  8. var i, radio = document.getElementsByName("targeturl");
  9. for (i = radio.length; i--;) {
  10.     radio[i].onclick = changeAction;
  11. }
Jul 24 '11 #4

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

Similar topics

3
by: Robert Bull | last post by:
I am trying to add a radio button at runtime in an asp.net web form but I keep getting the error message "type 'RadioButton' must be placed inside a form tag with runat=server". I use the following...
1
by: puja | last post by:
hi all, I have a form which has checkbox list which has items as below 1) Input 1 2) Input 2 3) Input 3 4) Input 4 5) Input 5
1
by: George Ter-Saakov | last post by:
I am trying to set class property of the radio button. but no mater what i do .NET moves it to <SPANtag aroung that radio button. So my <asp:RadioButton id="chkAllUpdates" cssClass="radio"...
6
by: lucyh3h | last post by:
Hi, In one of my pages, I use javascript (AJAX) to populate one mulitple select field based on user's click event on another control. I noticed that when I navigate back to this page by clicking...
2
by: mnms | last post by:
Hi, I'm trying to create an "overview" form. And I haven't been able to figure out how to get Access to do what I want yet. Basicly what I want, is to populate a subform based on a field...
15
by: javelin | last post by:
I need to be able to create a javascript based drawing/signature box, and be able to save it. Can someone refer me to a script that will allow this, or even a 3rd party package for sale? It can't...
3
by: Venturini | last post by:
I am trying to put together a web page where the customer makes choices of products and is then given a total. I am extremely new to Javascript and have managed to get as far as I have from web...
6
Claus Mygind
by: Claus Mygind | last post by:
I have 3 radio buttons - isPartOf, isNotPartOf, and delete I do some onscreen subtotaling when the buttons are clicked. This a list of contacts and each contact has these 3 radio buttons with a...
11
by: rakabuku | last post by:
I have this form called "switchboard" and in it are two combo boxes: Organization and Staff Initials (cboOrganization, cboStaff_init). There is also a search button called "OK". See picture "DB1" ...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.