Solved

submitting a form to optional url's

Posted on 2004-04-22
8
227 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
  • 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
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.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

773 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