Go Premium for a chance to win a PS4. Enter to Win

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

submitting a form to optional url's

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
NHBFighter
Asked:
NHBFighter
  • 4
  • 2
  • 2
1 Solution
 
llcooljayceCommented:
<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
 
llcooljayceCommented:
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
 
NHBFighterAuthor Commented:
WIll this allow all the input values that were set on the form to be read form both urls?

David
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
llcooljayceCommented:
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
 
llcooljayceCommented:
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
 
thirdCommented:
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
 
NHBFighterAuthor Commented:
Thanks third that is exactly what I needed sorry I wasn't more clear.

David
0
 
thirdCommented:
glad i could help. thanks for the A!

regards,

third ;-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now