javascript giving weird output -
i have weird problem javascript. wrote code checks if text input user good, , after while message saying if or not disappears, suggestions?
<%@ page language="c#" autoeventwireup="true" codefile="default2.aspx.cs" inherits="default2" %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <ul style="text-align:"right" dir="rtl"> <script type="text/javascript"> function validate() { var ok = true; if (firstname() == false) { ok = false; } } function firstname() { document.getelementbyid("firstname").innerhtml = ""; var firstname = document.getelementbyid("firstname").value; var length = firstname.length; if (length < 2) { document.getelementbyid("firstn").innerhtml = "not good"; return false; } else { document.getelementbyid("firstn").innerhtml = "good"; } return true; } </script> </head> <body> <form id="form1" runat="server" onsubmit="return validate()" action="default2.aspx"> <div> enter first name <input type="text" id="firstname" /> <label id="firstn"></label> <br /> <input type="submit" value="send"/> </div> </form> </body> </html>
well,
please remember have mentioned action in form, control transferred page mentioned in when "true" encountered. if still want see "good", can remove action.
so code working, can either change below,
<script type="text/javascript"> function validate() { if (firstname() == false) { return false; } else { return true; } } function firstname() { document.getelementbyid("firstname").innerhtml = ""; var firstname = document.getelementbyid("firstname").value; var length = firstname.length; if (length < 2) { document.getelementbyid("firstn").innerhtml = "not good"; return false; } else { document.getelementbyid("firstn").innerhtml = "good"; } return true; } </script>
or,
you can use jquery validation, way better , less time consuming,
Comments
Post a Comment