Solved

Targeting different pgs from 1 form

Posted on 1998-06-04
11
188 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
Comment Utility
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
Comment Utility
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
Comment Utility
That's what you give as an example because somebody tells you he's new at this??
0
 

Author Comment

by:ablogan
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:ablogan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the help. It now works
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

762 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

12 Experts available now in Live!

Get 1:1 Help Now