Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

redirect with values from radio buttons

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
rick101396
Asked:
rick101396
1 Solution
 
chrisboltCommented:
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
 
ptrumanCommented:
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
 
rick101396Author Commented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
rick101396Author Commented:
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
 
ptrumanCommented:
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
 
rick101396Author Commented:
   "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
 
sybeCommented:
<input type=radio onClick="document.myLink.href='anotherpage.htm'">

<a name="myLink" href="whateveryouwant.htm">link text</a>
0
 
ptrumanCommented:
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
 
rick101396Author Commented:
Thanks for your help.
0
 
ptrumanCommented:
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now