asp.net mvc 4 - How to pass the javascript value while submitting the form? -
i new asp.net mvc4. want pass java script value when submitting form. want pass value of random field in javascript along text box values. please me. in advance. javascript code generating , validating captcha:
<script type="text/javascript"> var captchastring = ''; function getcaptcha() { var chars = "0aa1bb2cc3dd4ee5ff6gg7hh8ii9jj0kk1ll2mm3nn4oo5pp6qq7rr8ss9tt0uu1vv2ww3xx4yy5zz"; var string_length = 7; captchastring = ''; (var = 0; < string_length; i++) { var rnum = math.floor(math.random() * chars.length); captchastring += chars.substring(rnum, rnum + 1); } document.getelementbyid("randomfield").innerhtml = captchastring; document.getelementbyid("forgot_password_form").submit(); } function validation() { var text2 = document.getelementbyid("txtcode").value; if (text2 == captchastring) { var email = document.getelementbyid("useremail").value; x = document.getelementbyid("demo"); // find element x.innerhtml = "valid"; x.style.color = "#ff0000"; } else { x = document.getelementbyid("demo"); // find element x.innerhtml = "invalid captcha. try again"; x.style.color = "#ff0000"; return false; } } </script>
code submiting form:
@using (html.beginform("forgotpassword", "login", formmethod.post, new { @class="forgot_password_form"})) { @html.textboxfor(u => u.useremail, new { @class = "form-control", placeholder = "email" }) <input type="text" name="txtcaptcha" id="txtcaptchaid" class="form-control" placeholder="enter code here" /> <input type="submit" class="btn btn-success btn-block" style="float: right; width:30%;" value="reset password" onclick="validation()" /> <p id="demo"> </p> }
Comments
Post a Comment