Solved

redirect with values from radio buttons

Posted on 1998-11-26
10
362 Views
Last Modified: 2013-12-25
Hi,

I need to find a method (using VBscript, JavaScript, or DHTML) to send the value of a radio button to a hyperlinked web page.  

What I have is a list of hyperlinks that the users can click to view a web page with that particular type of forms.  I wanted to know of a script that would allow me to read in the value of a radio button from a form without having to summit the form.  This way, I could use the value and pass it as a parameter for a redirect method.

I hope my question is clear and that there is solution to my problem.  Thanks.  
0
Comment
Question by:rick101396
10 Comments
 
LVL 2

Expert Comment

by:chrisbolt
ID: 1829791
Can you be more specific? Is there an example on the net of what you want to accomplish...

To get the value of a radio button, you must name the form by adding NAME="yourform" to the <FORM> tag then the value can be found with this:

document.yourform.fieldname.value
0
 
LVL 1

Expert Comment

by:ptruman
ID: 1829792
You can do this, as I use it on my pages :)

You need to add the following Javascript to your radiobuttons
so you have something like :

<INPUT TYPE=RADIO NAME=PAGE onclick="document.forms[0].elements[0].value="http://www.yoursite.com/pagewhatever.html')">

Then on your <FORM> you need a HIDDEN item, so
<FORM ACTION="http://www.yoursite.com/cgi-bin/redirect.pl" METHOD="POST">
<INPUT TYPE=HIDDEN NAME=PAGE VALUE="">

for the above script to work, the HIDDEN field MUST be the
first one in the form, else you have to change the element
number....

So, if you click a radiobutton, it passes the URL you wish to
redirect to into the HIDDEN form field, which is submitted to
the redirect script....then you simply use the PAGE
value from the redirect script to do the final "jump" :)

0
 

Author Comment

by:rick101396
ID: 1829793
Hi

What I was hoping to do was to read the value of the radios button without having to submit the form.  For example, I want to let the users choose a sorting option with radio buttons.  After one of the radio buttons is selected the users could view one of the webpage by clicking one of the link, like one shown below:  

<a href="http://www.mysite.com/forms.asp">Forms</a>

Now, what I want to do is add the value of the selected radio button to the link such that the sorting option is included in the hyperlink like so:

<a href="http://www.mysite.com/forms.asp" & document.form[0].element[0].value>Forms</a>

This way I don't have to submit the form to a script or having to redirect the from a different web page.

Is this possible?

Thanks for your help.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:rick101396
ID: 1829794
Hi

What I was hoping to do was to read the value of the radios button without having to submit the form.  For example, I want to let the users choose a sorting option with radio buttons.  After one of the radio buttons is selected the users could view one of the webpage by clicking one of the link, like one shown below:  

<a href="http://www.mysite.com/forms.asp">Forms</a>

Now, what I want to do is add the value of the selected radio button to the link such that the sorting option is included in the hyperlink like so:

<a href="http://www.mysite.com/forms.asp" & document.form[0].element[0].value>Forms</a>

This way I don't have to submit the form to a script or having to redirect the from a different web page.

Is this possible?

Thanks for your help.
0
 
LVL 1

Expert Comment

by:ptruman
ID: 1829795
You dont have to submit the form.
Use
<INPUT TYPE=BUTTON> with an onclick to read the values
and then use
document.location to change the page location (refer)

0
 

Author Comment

by:rick101396
ID: 1829796
   "Use <INPUT TYPE=BUTTON> with an onclick to read the values
    and then use document.location to change the page location (refer) "

Can you show me the codes to do this?  I am not a quite an expert on scripting languages.

Thanks.
0
 
LVL 28

Expert Comment

by:sybe
ID: 1829797
<input type=radio onClick="document.myLink.href='anotherpage.htm'">

<a name="myLink" href="whateveryouwant.htm">link text</a>
0
 
LVL 1

Accepted Solution

by:
ptruman earned 100 total points
ID: 1829798
or :

<FORM NAME=Redirect>
<INPUT TYPE=HIDDEN NAME="LOCATION">
<INPUT TYPE=RADIO NAME=SELECT VALUE="http://www.microsoft.com">Microsoft<BR>
<INPUT TYPE=RADIO NAME=SELECT VALUE="http://www.netscape.com">Netscape<BR>
<INPUT TYPE=BUTTON onClick="document.location='document.Redirect.LOCATION'">
</FORM>

Click the button should take you to the chosen site.

0
 

Author Comment

by:rick101396
ID: 1829799
Thanks for your help.
0
 
LVL 1

Expert Comment

by:ptruman
ID: 1829800
Having tried my answer on MS IE 4.01 last night, I
a) realised I forgot the onClick javascript for the radiobuttons
b) found out form element naming isnt working on my browser...

So, you'll need to use :

<form name="Redirect">
<input type=HIDDEN name="LOCATION" VALUE="">
  <input type=RADIO name="SELECT" value="http://www.microsoft.com" onClick="document.Redirect.elements[0].value=document.Redirect.elements[1].value">
  Microsoft<br>
  <input type=RADIO name="SELECT" value="http://www.netscape.com" onClick="document.Redirect.elements[0].value=document.Redirect.elements[2].value">Netscape<br>
  <input type=BUTTON onClick="document.location=document.Redirect.LOCATION.value" name="BUTTON" value="Go!">
</form>

clicking a radiobutton will set LOCATION (elements[0]) to the
required URL, and clicking the button will jump to that location.
I think the naming is failing as "SELECT" is the name of two
(or more) buttons....

As long as you keep the hidden field as the FIRST form item,
you're laughing....
(you may want to implement a check to make sure they have
got a site checked when they click the button, or give LOCATION
a default value....)

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
The viewer will learn how to count occurrences of each item in an array.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question