jquery - Unable to submit form using Javascript -
i trying submit form named 'vform' using javascript , ajax.here button named 'show' being used show 'div' containing form named vform , form calls codevalidate function , there submits form using ajax code..where getting error vform.submit().here's html , js code(i know error in if condition not know where)
html:
<button id="show" onclick="javascript:codefield(); return false";>apply discount</button> <div id="apply" style="display:none">voucher code<br> <form id="vform" name="vform" action="" method="post" onsubmit="javascript:codevalidate(); return false;" > <input type="text" name="code" id="code"><br> <span id="error" style="color:red"></span><br> <input type="submit" name="btn" value="apply" id="btn" ></form> </div>
javascript:
function codevalidate() { if(document.getelementbyid('code').value!=="") { $.post("couponajax.php",{code:$("#code").val()}, function(data) { if(data=='1') { //alert("success"); vform.submit(); return true; } else { document.getelementbyid('error').innerhtml="you have entered wrong code!"; return false; } }); } else { document.getelementbyid('error').innerhtml="code can't empty!"; return false; } return false;
}
codefield function displaying div on onclick event , ajax call checking whether code exists in database or not..if exists returns 1 else 0. problem alert message being displayed form not being submitted. how can fix problem?
i think missing jquery selector.
try replace
vform.submit();
with
$("#vform").submit();
or can call submit button click event like
$("#btn").click();
Comments
Post a Comment