Changing Value Of Hidden Input Fields Depending On Submit Button
I have multiple forms in my page and depending on the hidden input value, different sections are called. Now my issue is, I have 2 input buttons in one of my forms, and depending o
Solution 1:
The code to your onclick event could do that when confirming instead of just submitting the form. If you use jQuery:
if(confirm('Are you user you want to add this user?')){
$("input[name=target]").val('Generate password');
submit();
}
The one for the other input button should be very similar.
It is also possible that you have a way of knowing which button was pressed to submit the form another way. If I remember correctly, in PHP at least the name of the button is passed through in the _REQUEST variable.
Solution 2:
In HTML:
<inputtype="hidden"id="target" name="target" value="user_locked">
...
<inputtype="button" value="Generate Password"id="generate_button"/>
<inputtype="button" value="Lock User"id="lock_user"/>
In JS (jQuery):
$("#generate_password,#lock_user").click(function(){
("#target").val($(this).attr("id"));
$("form.myform").submit();
});
You can change around the IDs and classes of these elements, but make sure the JS and HTML match up.
Post a Comment for "Changing Value Of Hidden Input Fields Depending On Submit Button"