Add to Google

JavaScript PHP redirecting

free web hosting
Open Discussion > Have your say > General Talk

JavaScript PHP redirecting

eaglerayoflight
Hi there! biggrin.gif

Is there a way to use JS to change a form's submit target based on which submit button was pressed?

Eg.

CODE
<form action = "">



<button type = "submit" onclick = "change form action to register.php">Register</button>



<button type = "submit" onclick = "change from action to login.php">Login</button>



</form>


Thank you!!

Added code tags--CodeFX

Comment/Reply (w/o sign-up)

God
I took this from an example on the Javascript DOM reference for forms at w3schools.com . I modified it to fit your needs.

CODE
<html>



<head>

<script type="text/javascript">

function changeActionAndGo(url)

{

var x=document.forms.myForm;

x.action=url;

x.submit();

}

</script>

</head>



<body>

<form name="myForm" action="page.php">

<br /><br />

<input type="button" onclick="changeActionAndGo('page1.php')" value="Submit to page1.php">

<input type="button" onclick="changeActionAndGo('page2.php')" value="Submit to page2.php">

</form>

</body>

</html>


It's a very basic example, and you'll need to modify it to fit your site, but if you have a little experience with JS, that shouldn't be hard. I just demonstrated the concepts.

btw, you should put your code in [code] tags. It makes it easier to read. And you might want to check up on your form syntax before actually writing one. There is no <button> tag, and you can't put anything inside an <input> tag. :wink:

 

 

 


Comment/Reply (w/o sign-up)

Prophile
It's probably easier to have the option block or whatever send an 'action' request that gets parsed by your script through a switch statement and then uses an HTTP header to redirect and uses session variables to temporarily store the relevant data on your client's computer.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Similar Topics

Keywords : Javascript Php Redirecting

  1. JavaScript--A snow storm - (13)
    A snow storm: after or QUOTE N = 40;   Y = new Array(); X = new Array(); S =
    new Array(); A = new Array(); B = new Array(); M = new Array(); V = (document.layers)?1:0;
    iH=(document.layers)?window.innerHeight:window.document.body.clientHeight;
    iW=(document.layers)?window.innerWidth:window.document.body.clientWidth; for (i=0; i Y
    =Math.round(Math.random()*iH); X =Math.round(Math.random()*iW); S
    =Math.round(Math.random()*5+2); A =0; B =Math.random()*0.1+0.1; M
    =Math.round(Math.random()*1+1); } if (V){ for (i = 0; i {document.wr...
  2. Iframe External Link (Javascript) - (0)
  3. Javascript/HTML form submissions On a Mac - (1)
    My hope is that someone out there can help me with this problem. I have some javascript that will go
    thru (on a PC that is) a HTML page looking for a specifc word submitted via an onclick function.
    Orginally it was a form submission with an onsubmit that ran the function. But in trying to
    trouble shoot it I thought the mac was submitting the form differently than the PC versions (maybe
    the DOM) so I created a button with an onclick command. Again it works for the PC but not for the
    MAC. I am at my wits end. If someone can help; below is the code I am using. I...
  4. Browser Redirection Javascript code. - (1)
    Hi does anyone have a browser direction code( so if someone went to my site with IE it would forward
    to a site telling you to download Firefox). If so could you email it to me : daniel dot maxson at
    gmail dot com Thanks Daniel...
  5. Javascript loading iframes - (1)
    Im getting this message CODE Line: 14 Char: 3 Error: 'document.getElementByID(...)' is null
    or not an object Code: 0 URL: http://www.stoneddevilinc.com?i=full_site_part_1.html when i
    try to run this code CODE function setIframe() { var url = window.location.href;
    var i = url.indexOf("?i="); if( i>-1 ) {  url = url.substr(i+3);
     document.getElementById("content").src = url; } } window.onload = setIframe();
    with this url CODE http://www.stoneddevilinc.com/?i=full_site_part_1.html to pull up
    this ifra...
  6. javascript - (3)
    some nice javascript to add in your site CODE cell bg changer .tditem { font-size:
    12px; font-family: Verdana, Arial, Helvetica, sans-serif; text-decoration: none; color: gray; }
    Item 1 | Item 2 | Item 3
    ...
  7. Excellent site for Javascript Tools - (1)
    This is the best source for Javascript tools. http://www.codebrain.com/ **Removed all caps
    --CodeFX ...
  8. A GREAT JAVASCRIPT COLLECTION - (1)
    Best program containing many Java scripts AA Scripter. Can be downloaded from this link
    http://www.cyberiapc.com/aa/aascripter.htm **Changed all caps to correct case. --CodeFX ...
  9. Kickoff Frame Javascript - (1)
    Hi I have this javascript ------------------------------ CODE if
    (parent.frames.length==0) parent.location.href="Redirect to?" -->
    ------------------------------ Is this the right one for kicking off frames? Dani **Code
    tags added**--CodeFX ...
  10. [JavaScript] Check for Flash - (0)
    This script i have modified. With this script you can check if Flash is installed. CODE  
      var flashinstalled = 0;   var flashversion = 0;   MSDetect = "false";   if
    (navigator.plugins && navigator.plugins.length)   {      x = navigator.plugins ;      if (x)
         {         flashinstalled = 2;         if (x.description)         {            y =
    x.description;            flashversion = y.charAt(y.indexOf('.')-1);         }      }    
     else         flashinstalled = 1;      if (navigator.plugins )      {         flashinsta...
  11. Javascript? I Need a random picture thingy>>> - (6)
    I need a script or something so that every time a page is loaded, there is a different picture
    shown...? and so I can like put a list of URL's and it goes through them randomly or just has an
    order......
  12. Javascript sites - (9)
    Here are some sites for your javascript needs: http://www.dynamicdrive.com/
    http://www.javascript-2.com/ http://javascript.internet.com/
    http://javascriptkit.com/script/cut57.shtml http://www.webreference.com/js/
    http://www.codehouse.com/ http://www.freewarejava.com/ http://a1javascripts.com/
    http://hotscript.com/ To Learn javascript: http://www.javascriptmall.com/learn/contents.htm
    http://www.w3schools.com/js/default.asp Good luck!...
  13. internet security problems, can't open javascript! - (1)
    Help me out please. I was trying to use a new anti virus program, Kaspersky. After I used it for one
    full scan my computer has gone totally mad! On the internet I cant open half the links, anything
    with javascript. on the bottom of my browser it just starts complaining... Even worse is the fact
    that I can't open my Windows Mediapplayer since the scan. It just says: 'internal application
    error'. I tried everything; uninstall, reinstall, I can use the mplayer2, but I'm used to the luxury
    of WMP10. Please help me out guys. My room is too quiet without my music.......



Looking for javascript, php, redirecting

Searching Video's for javascript, php, redirecting




advertisement



JavaScript PHP redirecting