I have a form posting values to the server, but i wish to be able to control which inputs are included as request parameters in the post.
So if i have a basic text input, how can I stop it getting included in the submit?
The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the <input> element usable. Tip: Disabled <input> elements in a form will not be submitted!
To disable form fields, use the CSS pointer-events property set to “none”.
If a field is disabled , the value of the field is not sent to the server when the form is submitted. If a field is readonly , the value is sent to the server.
Projects In JavaScript & JQuery We can easily disable input box(textbox,textarea) using disable attribute to “disabled”. $('elementname'). attr('disabled','disabled'); To enable disabled element we need to remove “disabled” attribute from this element.
for jquery 1.6 an higher do
$("#formField").prop("disabled",true);
You could insert input fields with no "name" attribute:
<input type="text" id="something" />
Or you could simply remove them once the form is submitted (in jquery):
$("form").submit(function() {
$(this).children('#something').remove();
});
if you omit the "name" attribute value you can't access that value through any method..
Hope this helps.
Generally if you do jQuery("#{input id}").attr("disabled","disabled");
it should prevent it from being sent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With