Solved

submitting a form to optional url's

Posted on 2004-04-22
8
225 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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 about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

707 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

18 Experts available now in Live!

Get 1:1 Help Now