0

Before my HTML form submission, I am putting some values in my hidden input element, which is not submitted with my form, any error or something?

For ex:

Below is my form function:

<form id="clientForm" name="clientForm" method="post" enctype="multipart/form-data" action="clients.php" onClick="beforeSubmit(); return false;">
    <input type="text" name="OLD_BRANCH_FILTERS_ALL" id="OLD_BRANCH_FILTERS_ALL" value="">
</form>

Below is my JS function:

<script language="javascript" type="text/javascript">

    function beforeSubmit(){

        $('#OLD_BRANCH_FILTERS_ALL').attr('value', 'xyz');

        alert(document.getElementById('OLD_BRANCH_FILTERS_ALL').value);

        document.clientForm.action = 'clients.php?saveBtn=Save';
        document.clientForm.submit();
    }

</script> 

Now, When I check the form request $_REQUEST in PHP, it shows no value in element.

Any clue why its not working.

Thanks in advance !

2
  • 1
    Tried using onSubmit instead of onClick? Commented Nov 4, 2013 at 12:19
  • I tried your code on my local XAMP and it is working. The submit page did show value xyz. Check that you don't have any error somewhere else Commented Nov 4, 2013 at 12:55

1 Answer 1

1

your onlick is not called in time to set the values, try it this way

<form id="clientForm" name="clientForm" method="post" enctype="multipart/form-data" action="clients.php">
    <input type="text" name="OLD_BRANCH_FILTERS_ALL" id="OLD_BRANCH_FILTERS_ALL" value="">
</form>

and the jquery

$('#clientform').submit(function() {
    beforeSubmit();
});

Also, if you also wanted to provide validation to the field you could use,

$('#clientform').submit(function(e) {
    beforeSubmit();
    if (!{VALID}) {
       e.preventDefault();
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.