Solved

submitting a form to optional url's

Posted on 2004-04-22
8
229 Views
Last Modified: 2010-04-06
Hi

I have a single form that I want to be submitted to URL1 if the user clicks button1 and if the user clicks button2 I want it to go to URL2.  I don't know how to do that.

Thanks for the help
David
0
Comment
Question by:NHBFighter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 4

Expert Comment

by:llcooljayce
ID: 10895110
<script language = "javascript">
function goToURL1()
{
   window.location = "location1.html";
}

function goToURL2()
{
   window.location = "location2.html";
}
</script>


<form name = "blah">
<input type = "button" name = "URL1" onClick = "goToURL1()">
<input type = "button" name = "URL2" onClick = "goToURL2()">
</form>


That should work.  Cheers.

Jayce
0
 
LVL 4

Expert Comment

by:llcooljayce
ID: 10895117
And just so you know, the script section goes in the <head> section of your html

<html>
 <head>
  <title>URL Redirect</title>
  <script language = "javascript">
  function goToURL1()
  {
     window.location = "location1.html";
  }

  function goToURL2()
  {
     window.location = "location2.html";
  }
  </script>
 </head>
0
 
LVL 4

Author Comment

by:NHBFighter
ID: 10895123
WIll this allow all the input values that were set on the form to be read form both urls?

David
0
Independent Software Vendors: 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!

 
LVL 4

Expert Comment

by:llcooljayce
ID: 10895131
Damnit ... here:

<html>
<head>
<script language = "javascript">
function goToURL1()
{
   window.location = "location1.html";
}

function goToURL2()
{
   window.location = "location2.html";
}
</script>
</head>
<bod>
<form name = "blah">
<input type = "button" name = "URL1" onClick = "goToURL1()" value = "go to URL 1">
<input type = "button" name = "URL2" onClick = "goToURL2()" value = "go to URL 2">
</form>
</body>
</html>
0
 
LVL 4

Expert Comment

by:llcooljayce
ID: 10895156
You will be able to save all values that were saved but you have to declare them.  

<script language = "javascript">
 var Value1, Value2;
 
 Value1 = document.formName.fieldName.value;
 Value2 = document.formName.fieldName.value;

</script>
0
 
LVL 30

Accepted Solution

by:
third earned 250 total points
ID: 10895238
i guess what you are looking for is a from submission not a simple redirect. try this,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
  function search(obj){
    if(obj.name=='btnGoogle'){
        obj.form.txt1.name = 'q';
      obj.form.action = 'http://www.google.com/search';
      }
      else{
        obj.form.txt1.name = 'p';
        obj.form.action = 'http://search.yahoo.com/search';
      }
      obj.form.submit();
  }
</script>
</head>
<body>
<form name="form1" method="get" action="" onsubmit="">
  <input type="text" name="txt1">
  <input type="button" name="btnGoogle" value="Submit to Google" onclick="search(this);">
  <input type="button" name="btnYahoo" value="Submit to Yahoo" onclick="search(this);">
</form>
</body>
</html>
0
 
LVL 4

Author Comment

by:NHBFighter
ID: 10895337
Thanks third that is exactly what I needed sorry I wasn't more clear.

David
0
 
LVL 30

Expert Comment

by:third
ID: 10895385
glad i could help. thanks for the A!

regards,

third ;-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

738 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