Changing FORM action url ....

Discussion in 'JavaScript' started by redhits, Feb 15, 2010.

  1. #1
    Can i change the form action url throw javascript?

    I want to do this, in order to protect myself from the massive spam bots attacks
     
    redhits, Feb 15, 2010 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    
    <form id="myForm" method="post" action="dumbyurl.php">
    </form>
    <script type="text/javascript">
    document.getElementById("myForm").setAttribute("action","realurl.php");
    </script>
    
    Code (markup):
    although some bots may get the action of the form after the window has loaded and executed javascripts... you could use a timer for a bit more protection... like:
    
    <form id="myForm" method="post" action="dumbyurl.php">
    </form>
    <script type="text/javascript">
    setTimeout(function() {
    document.getElementById("myForm").setAttribute("action","realurl.php");
    }, 2000);
    </script>
    
    Code (markup):
    This way it would wait 2 seconds (2000ms) after the page has loaded, and then the code to change the action is executed...
     
    camjohnson95, Feb 15, 2010 IP
  3. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #3
    thanks a lot
     
    redhits, Feb 15, 2010 IP
  4. brightyoursite

    brightyoursite Peon

    Messages:
    59
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if u use ajax post thats easy
     
    brightyoursite, Feb 22, 2010 IP