javascript - Perform a clean submit by removing hidden divs -
i trying perform 'clean' submit, i.e. submit invoked after removing hidden divs form field.
since feature going use more often, shifted code extend-part:
$.fn.extend({ bindcleansubmit: function() { $(this).submit( function(event) { event.preventdefault(); $(this).find("div:hidden").remove(); console.log("trying commit..."); return true; }); } });
now, divs removed, console event triggered @ end submit has not performed.
do problem here?
i'm not sure trying preventdefault()
, if remove bindcleansubmit()
, hidden divs removed form , submitted normally. given following html:
<form id="myform" method="post" action="/"> <input type="text" name="displayedinput" value="1"/> <div style="display: none"> <input type="text" name="hiddeninput" value="1"/> </div> <button type="submit">submit</button> </form>
...and updated plugin:
$.fn.extend({ bindcleansubmit: function() { $(this).submit( function(event) { $(this).find("div:hidden").remove(); console.log("trying commit..."); return true; }); } }); $('#myform').bindcleansubmit();
...only displayedinput
value submitted server when myform
submitted.
Comments
Post a Comment