asp.net - Javascript code is not working second time -
I am newbie in javascript I have two text boxes
I am using JavaScript validation here so that the user could not enter zero value. I'm using this code on my Javascript code OK button. The problem is now that when the user leaves the text box blank and clicks on the button, the error message is displayed and then the user corrects it on the mistakes and then on the button Click if the button is not working. Nothing happens EDIT: My Javascript code The input is in their content attributes, when an user has modified an input value has changed and there is clue you have to use the input value. If you are in a small amount to get a piece of code, then I choose not to use inline function assignment and as mentioned in other comments, a required flag Use, then check the DOMready form for the required fields. Then you can deal with them, on-site, on-change this will give you a little more flexibility. ps you have to tell what this does ... & asp: textbox id = "Txtbox1" class = "txt" runat = "server" /> & Lt; Asp: textbox id = "txtbox2" class = "txt" runat = "server" />
& lt; Asp: button id = "btn_add" runat = "server" OnClientClick = "validate ();" OnClick = "btn_add_Click" text = "submit" />
& lt; Script type = "text / javascript" & gt; Validate the function () {var error = 0, value, A, Q, I; Value = document.getElementsByClassName ("txt"); (I = 0; i & lt; value.length; i ++) {if (value [i] .textContent == '') {document.getElementById ("errmsg") InnerHTML = "text box can not be empty"; Error = 1; break; }} If (error == 0) {return true} and {return}}
& lt; Script type = "text / javascript" & gt; Validate the function () {var error = 0, value, A, Q, I; Value = document.getElementsByClassName ("txt"); (I = 0; i & lt; value.length; i ++) {if (value [i] .value == '') {document.getElementById ("errmsg"). InnerHTML = "text box can not be empty"; Error = 1; break; }} If (error == 0) {returns true} and {return false}} < / Script & gt; `& Lt; Form action = "form_action.php" method = "meet" & gt; & Lt; Div id = "errmsg" & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; Label & gt; First name & lt; / Label & gt; & Lt; Input class = "txt" type = "text" name = "fname" value = "" /> & Lt; Input type = "submit" onclick = "validate return ()" value = "submit" /> & Lt; / Div & gt; & Lt; / Form & gt;
var error = 1, value, a, q, i
Comments
Post a Comment