Solved

redirect with values from radio buttons

Posted on 1998-11-26
10
359 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell script help 5 73
Need help to rewrite script 3 67
Linux Scripting 3 102
powershell command to get a dll version remotely for many server 12 14
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 …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

920 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

13 Experts available now in Live!

Get 1:1 Help Now