Javascript function not working on validating the form -



Javascript function not working on validating the form -

i have form

<tr> <td><h5> name</h5> <asp:textbox id="tb_name" clientidmode="static" cssclass="tb_orderbyphn" runat="server" /> </td> </tr> <tr> <td><h5>phone</h5> <asp:textbox id="tb_phone" clientidmode="static" cssclass="tb_orderbyphn" runat="server" /> </td> </tr> <tr> <td><h5>email</h5> <asp:textbox id="tb_email" clientidmode="static" cssclass="tb_orderbyphn" runat="server" /> </td> </tr> <tr> <td> <asp:linkbutton id="btn_order1" class="btn btn-lg btn-block btn-success btn_rad " onclick="btn_order" onclientclick=" homecoming validate_order();" runat="server" >order <i class=" glyphicon glyphicon-chevron-right " ></i></asp:linkbutton></td> </tr>

the form validated javascript as

function validate_order() { if (document.getelementbyid("tb_phone").value == "") { document.getelementbyid("tb_phone").style.bordercolor="red"; homecoming false; } if (document.getelementbyid("tb_email").value == "") { document.getelementbyid("tb_email").style.bordercolor="red"; homecoming false; } if (document.getelementbyid("tb_name").value == "") { document.getelementbyid("tb_name").style.bordercolor="red"; homecoming false; } homecoming true; }

but when click button keeping field empty reddish border on 1 textbox only(the first textbox in javascript function ie tb_phone) instead of three.please can explain this?

i created snippet you. it's faster save element in variable if utilize more 1 time. code remove border if input valid after 2nd submit.

if want better, can create 'validateinput' function, , validate each input same function.

class="snippet-code-js lang-js prettyprint-override">function validateorder() { var valid = true, name = document.getelementbyid("tb_name"), phone = document.getelementbyid("tb_phone"), email = document.getelementbyid("tb_email"); validateinput.call(name); validateinput.call(phone); validateinput.call(email); if (!validateinput.call(name) || !validateinput.call(phone) || !validateinput.call(email)) valid = false; homecoming valid; } function validateinput(){ if(this.value == ""){ this.style.border = "1px solid red"; homecoming false; } else{ this.style.border = "none"; homecoming true; } } class="snippet-code-html lang-html prettyprint-override"><tr><td><h5> name</h5> <input id="tb_name" onkeyup="validateinput.call(this);" /></td></tr> <tr><td><h5>phone</h5> <input id="tb_phone" onkeyup="validateinput.call(this);" /></td></tr> <tr><td><h5>email</h5> <input id="tb_email" onkeyup="validateinput.call(this);" /></td></tr> <tr><td><button onclick="validateorder();" >order now</button></td></tr>

javascript

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -