Solved

Targeting different pgs from 1 form

Posted on 1998-06-04
11
210 Views
Last Modified: 2010-05-18
My form has 5 radio buttons and I want each of the buttons to take you to a different page in the site whenever  the submit button is pushed. Is this possible ? Please include example if possible, I'm new at this

                                                                       Thank You
                                                                             Big Al
0
Comment
Question by:ablogan
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 6

Expert Comment

by:Holger101497
ID: 1844079
Your question is not 100% clear...
"take you to a different page in the site whenever  the submit button is pushed"... does that mean that you want to go to a "page" or does it mean that you want to change the URL the form submits its data to??
0
 
LVL 8

Expert Comment

by:jhurst
ID: 1844080
I assume that you just want the user to load another page, but the page being selected should be dependant on which button was selected:

In your form, for the button:
<INPUT type=button onClick=doMyForm()>

then you create the function:
function doMyForm()
  { // we arrive here when he presses the submit button
    // we look through the button values with
    if (document.forms......   // see if this is the one checked
        window.location.href='http:// .... // wherever you want to go for this one
  }

Good luck - have fun
   
  }
0
 
LVL 6

Expert Comment

by:Holger101497
ID: 1844081
That's what you give as an example because somebody tells you he's new at this??
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:ablogan
ID: 1844082
Thank You for responding. Yes I'm trying to get different pages loaded in the same web site. There is a particular reason why I'm doing it this way. Please excuse my ignorance but I'm a graphics guy and just learning html.  Here is the code I'm using. I'm not quite sure how to apply what you've just shown me.  In your "do my form"( )..line of code, does the location for the page I want loaded, go in between the brackets. My ' form action' makes every button in the form go to my 'index1.html, wher as I want each one to hit a different page


<form action="index1.html">
<input type="radio" name="individual" value="">Individual<br>
<input type="radio" name="scientist" value="">Scientist<br>
<input type="radio" name="organization" value="">Organization<br>
<input type="radio" name="media" value="">Media<br>
</td><td width="33%" height="33%"></td></tr></table>

<center>
<hr size=5 width=70%>
<input  type="submit" value="send info"><input type="reset">

I hope I'm not confusing you.
Thanks Al

0
 

Author Comment

by:ablogan
ID: 1844083
Holger,
 
Thanks for the interest. Please see my new post. I hope the inclusion of the bit of lousy code and my explaination makes things a little clearer. I don't need this to go to another server or anything.

Thanks Al
0
 

Author Comment

by:ablogan
ID: 1844084
I have to leave now, I'll be back on 2 morrow. Thanks Guys
Big Al
0
 
LVL 5

Accepted Solution

by:
Christian_Wenz earned 50 total points
ID: 1844085
Hi ablogan, try this:

a) give each of these radio buttons the same name attribute (name="something") so that the user can only select one of them.
b) now put the following in the <HEAD> part of your page:
<SCRIPT LANGUAGE="JavaScript"><!--
function doit(){
  if (document.forms[0].elements[0].checked) then location.href="individual.html"
  if (document.forms[0].elements[1].checked) then location.href="scientist.html"
  if (document.forms[0].elements[2].checked) then location.href="organization.html"
  if (document.forms[0].elements[3].checked) then location.href="media.html"
}
//--></SCRIPT>

c) remove the ACTION="index1.html" from your form tag
d) instead of <input type=submit value="send info">, use
<input type="button" value="send info" onClick="doit()">

if there is something unclear, please leave a comment.
0
 

Author Comment

by:ablogan
ID: 1844086
Hello Christian,

Thank you for your java code. Something isn't working right though, so maybe you could tell me what I'm doing wrong. Here is my code for the page,

<html><head><Title>Submit Page</title>
   <SCRIPT LANGUAGE="JavaScript"><!--  
   function doit(){
     if (document.forms[0].elements[0].checked) then location.href="typeform.html"
     if (document.forms[0].elements[1].checked) then location.href="scientist.html"
     if (document.forms[0].elements[2].checked) then location.href="organization.html"
     if (document.forms[0].elements[3].checked) then location.href="media.html"
     if (document.forms[0].elements[4].checked) then location.href="Country.html"
   }
   //--></SCRIPT>

  </head>

<body>
<body background="blue col.gif">
<center>
<img src="senda.gif">
<hr size=5 width=70%>
<h2>Please Select One of The Following</h2>
</center>

<table><tr>
<td width="33%" height="33%"></td>
<td width="34%" height="33%">

<form>
 <input type="radio" value="send info" onClick="doit()">Individual<br>
 <input type="radio" value="send info" onClick="doit()">Scientist<br>
 <input type="radio" value="send info" onClick="doit()">Organization<br>  
 <input type="radio" value="send info" onClick="doit()">Media<br>
 <input type="radio" value="send info" onClick="doit()">Country<br>  
</td><td width="33%" height="33%"></td></tr></table>></form>

<center>
<hr size=5 width=70%>
<br><br

</body>
</html>
 
Thanks, Al






0
 
LVL 6

Expert Comment

by:Holger101497
ID: 1844087
This is not my question and it's locked, but here's a hint:

Some HTML for beginners *g*:
1) JavaScript doesn't know THEN... it should be if (condition) statement;
=> just delete the "then"'s
2) Don't use 2 <BODY> tags
3) Don't open the form IN the table and close it outside... proper nesting shows you that you should close the form before you close the table cell that contains it
4) Close your <BR at the end :-))
5) Lastly and most inportantly: Your radio buttons need a name (Christian mentioned it) - all the same one. Just add "name=choosedest" to each one

That should actually do it.
Not all of the above are a problem for Netscape 4, but they might be for other browsers... and you just shouldn't upload bad HTML...

Good luck!

0
 
LVL 5

Expert Comment

by:Christian_Wenz
ID: 1844088
Of course Holger's right about the THEN; when I wrote this, I just came from programming in another language for some hours :-(

0
 

Author Comment

by:ablogan
ID: 1844089
Thanks for the help. It now works
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

772 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