[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Targeting different pgs from 1 form

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
ablogan
Asked:
ablogan
  • 5
  • 3
  • 2
  • +1
1 Solution
 
Holger101497Commented:
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
 
jhurstCommented:
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
 
Holger101497Commented:
That's what you give as an example because somebody tells you he's new at this??
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
abloganAuthor Commented:
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
 
abloganAuthor Commented:
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
 
abloganAuthor Commented:
I have to leave now, I'll be back on 2 morrow. Thanks Guys
Big Al
0
 
Christian_WenzCommented:
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
 
abloganAuthor Commented:
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
 
Holger101497Commented:
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
 
Christian_WenzCommented:
Of course Holger's right about the THEN; when I wrote this, I just came from programming in another language for some hours :-(

0
 
abloganAuthor Commented:
Thanks for the help. It now works
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now