Helping ordinary people create extraordinary websites!

Go Back   Web Development Forum > Website Programming > Client-Side Scripting
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-24-2008, 09:54 PM
Junior Member
 
Join Date: Jan 2008
Posts: 22
Default JavaScript Dual Submit

Hi,
I have a form that I want submitting data to different pages based on the submit button the user clicks. For example if they click on submit#1 then it posts the data to page1.php and if they click on submit#2 it posts to page2.php.

What would be the javascript code to accomplish this.

Tah.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-03-2008, 01:15 AM
Member
 
Join Date: Sep 2008
Posts: 67
Default

Hmm its can be done just by redirecting the page on th click event..
_________________
Golf shop cooking wine
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-03-2008, 06:05 AM
Junior Member
 
Join Date: Dec 2008
Posts: 25
Default

create a function which submits the page

pass the form action flag as an argument

example... (not tested)

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script>
// function
function submitter(a){
 // set form target in var
 form = document.getElementById('form1');
 // use switch to determin which button has been clicked and set what results page to use
 switch(a){
  case '1': var act = "page1.php"; break;
  case '2': var act = "page2.php"; break;
 }
 
 // set action of form
 form.action = act;
 
 // submit form
 form.submit();
 
}
 
</script>
 
</head>
<body>
<form id="form1" name="form1" method="post" action="">
  <p><input type="text" name="textfield2" /></p>
 
  <p><input type="text" name="textfield" /></p>
 
  <p>
    <input name="button1" type="button" id="button1" value="Button1" onclick="submitter('1')"/>
    <input name="button2" type="button" id="button2" value="Button2" onclick="submitter('2')"/>
  </p>
 
</form>
</body>
</html>
__________________
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development time.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

All times are GMT -5. The time now is 11:37 PM.


Website Design by Ducani Media Group
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.