Solved

submitting a form to optional url's

Posted on 2004-04-22
8
226 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Text Web Page rendering differently on IE versus Chrome 3 85
xml attribute DTD attribute differences 3 65
Animated .jpg? 13 61
Randomize in Owl Carousel v1.3.2 6 20
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 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

24 Experts available now in Live!

Get 1:1 Help Now