Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Change the form action before submit

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.29k
    Comment on it

    How to change the form action before submit on the basis of element/input field click.

     

    The html sample code for form having radio button and submit button :

    <form action="" id="myformID">
    
    <input type="radio" name="changeaction" value="male" id="ifmale"/>Male<br>
    
    <input type="radio" name="changeaction" value="female" id="iffemale">Female<br>
    
    <button type="submit" form="form1" value="Submit">Submit</button>
    
    </form>


    The script code to change the form action button on click of radio button :

    <script type="text/javascript">
    
        $('#ifmale').click(function(){
           $('#myformID').attr('action', '/abc.php');
        });
    
    
        $('#iffemale').click(function(){
           $('#myformID').attr('action', '/xyz.php');
        });
    
    
    </script>

    You can customize the above script for any input field like select, text, checkbox etc.
    First match the value on click event of the element and then change the action attribute of the form by passing form's id.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: