Solved

redirect with values from radio buttons

Posted on 1998-11-26
10
358 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now