Hello, I am working with a form which has a lot of text fields which submits some data via POST. I would like some of this data to ONLY be sent if the user actually has entered something in the textfield, and if the user didn't I would like that variable not to even be sent via POST (not even an empty value)... Is this possible somehow? Thanks
check user input data before POST, you can use the JavaScript examples in the link below: http://www.javascriptbank.com/javascript/form/validation-limitation/ Free JavaScript Code | HTML-JS-CSS Encoding | CSS Menus
This can be done by removing the elements whose value is not entered , from the form, and then submitting the form. The following code helps to do so. <html> <head> <script> function validateRemove(eId) { if(document.getElementById(eId).value=="") { var t = document.getElementById(eId); t.parentNode.removeChild(t); } } function submitFunc() { validateRemove('abc'); validateRemove('bcd'); document.testform.action = "cssExample.html"; document.testform.submit(); } </script> </head> <body onload="document.testform.reset();"> <form name="testform"> <input type="text" name="abc" id="abc" /><br> <input type="text" name="bcd" id="bcd" /><br> <input type="button" onClick="submitFunc();" value="Submit"/> <form> </body> </html> Code (markup): Hope this helps.