jquery form validation does not conform to rule background discoloration tips

Source: Internet
Author: User
Tags button type jquery form validation

Note: In the ID everyone in the debugging must pay attention to, and I did not load the jquery package, you can download the following code to use.


jquery Code

The code is as follows Copy Code
$ ("#qrd_form"). Submit (function () {





var Iserr=false;





if ((!$ (' #customersname '). Val ()) | | $ (' #customersname '). val () = ' Please enter friend name '


$ (' #customersname '). CSS (' Background-color ', ' #ffcccc ');


Iserr=true;


}else{


$ (' #customersname '). CSS (' Background-color ', ' #f0f0f0 ');


}





if ((!$ (' #customersmobile '). Val ()) | | $ (' #customersmobile '). val () = ' Please enter contact telephone '


$ (' #customersmobile '). CSS (' Background-color ', ' #ffcccc ');


Iserr=true;


}else{


$ (' #customersmobile '). CSS (' Background-color ', ' #f0f0f0 ');


}


if ($ (' #house_city '). val () = = ' 0 ') {


$ (' #house_city '). CSS (' Background-color ', ' #ffcccc ');


Iserr=true;


}


if ((!$ (' #customersmobile '). Val ()) | | $ (' #customersmobile '). val () = = ' 13875884450 ') {


if (Confirm (' agent can't recommend himself, buy a house, please go "I want to Purchase" channel ")) {


location.href= '/user/tuijian_me ';


}


Iserr=true;


}





Get Intent Property


var strlp= ';


$ ('. Yxlp '). each (function () {


if ($ (this). Val () && $ (this). Val ()!= ' Enter Intent property ') {


strlp+=$ (This). Val () + ';


}


});


$ (' #houseid '). Val (STRLP);


alert (STRLP);





if (ISERR) return;


var postdata = $ ("#qrd_form"). Serialize ();





$.ajax ({


Type: "POST",


URL: "/ajax/sendqrd1",


Data:postdata,


Success:function (msg) {


if (msg==1) {


TJ ();


}else if (msg==2) {


Alert (' Unfortunately, the customer already exists ');


}else if (msg==3) {


Alert (' Sorry, brokers can only recommend up to 10 clients per day! ');


}else{


Alert (' Sorry customer recommendation failed! ');


}


}


});


});


});

Html

The code is as follows Copy Code

<form id= "Qrd_form" name= qrd_form "method=" POST "onsubmit=" return false; " >


<ul>


<li><span class= "name" ><b>*</b> friend Name: </span><input class= "Input_user" type= "text" Autocomplete= "Off" onblur= "if (this.value==") this.value= ' Please enter friend name '; "onfocus=" if (this.value== ' Please enter friend name ') this.value = '; "value=" Please enter your friend's name "Name=" Customersname "id=" Customersname "></li>


<li><span class= "Name" ><b>*</b> Tel: </span><input class= "Input_user" type= "text" Autocomplete= "Off" onblur= "if (this.value==") this.value= ' Please enter contact telephone '; "onfocus=" if (this.value== ' Please enter contact telephone ') this.value = '; "value=" Please enter the contact phone "name=" Customersmobile "id=" Customersmobile "></li>


<li><span class= "name" ><b>*</b> Intent Total Price:</span>


<select name= "YXJG" id= "YXJG" >


<option value= "1" >0-100 million </option>


<option value= "2" >100-300 million </option>


<option value= "3" >300-1000 million </option>


<option value= "4" >1000-3000 million </option>


<option value= "5" >3000 million </option>


</select>

</li>


<li><span class= "name" ><b>*</b> intention City:</span>





<select name= "Yxcs" class= "City" id= "house_city" >


<option value= ' 0 ' > Please select </option>


<option value= "1" > Suzhou </option>


<option value= "2" > Nantong </option>


<option value= "3" > Changzhou </option>


<option value= "4" > Nanjing </option>


<option value= "5" > Wuxi </option>


<option value= "6" > Xuzhou </option>


<option value= "7" > Jinhua </option>


<option value= "8" > Suqian </option>


<option value= "9" > Chongqing </option>


<option value= "Ten" > Fuzhou </option>


<option value= "One" > Changsha </option>


<option value= "A" > Chengdu </option>


<option value= "" > Guiyang </option>


<option value= > Kunming </option>


<option value= > Qingdao </option>


<option value= > Nanchang </option>


<option value= > Jiujiang </option>


<option value= "A" > Ganzhou </option>


<option value= > Dalian </option>


<option value= > Datong </option>


<option value= > Wenzhou </option>


<option value= > Hangzhou </option>


<option value= > Ningbo </option>


<option value= > Wuhan </option>


<option value= > XI ' an </option>


<option value= > Hefei </option>


<option value= > Changchun </option>


<option value= > Harbin </option>


<option value= > Urumqi </option>


<option value= "Wuyi" > Shenyang </option>


<option value= > Shanghai </option>


<option value= > Jinan </option>


</select>


<select name= "yxqy" class= "City" id= "House_area" >


<option value= ' 0 ' > Please select </option>


</select></li>


<li id = "0" ><span class= "name" > Intent property: </span><input class= "Input_user yxlp" type= "text" Autocomplete= "Off" onblur= "if (this.value==") this.value= ' input intention property '; "onfocus=" if (this.value== ' input intention property ') this.value= ' '; "value=" Input intention property "><div class=" Add "tabindex=" 5 "id=" AddOne "></div></li>


<li></li>


<ul class= "More_lf" id= "TestTable" >


</ul>


<li><span class= "Name" > Note: </span><textarea class= "Tie-textarea js-postbox" cols= "8" rows= " Name= "Beizhu" id= "Beizhu" ></textarea></li>


<input name= "Houseid" id= "Houseid" value= "type=" hidden "/>"


<li><span class= "name" ></span><button type= "Submit" tabindex= "5" class= "Button_sub" > Submit recommended Information </button> </li>


</ul>


</form>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.