djbuddhi Posted February 15, 2008 Share Posted February 15, 2008 I need a script for validation email and user id in server side validations using ajax ? Quote Link to comment Share on other sites More sharing options...
shankar23 Posted April 19, 2008 Share Posted April 19, 2008 In php script page save as "ajaxError.php" use this alone a <?php $email =$_GET["email"]; if($email) { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { echo "<p align=center><font face='Verdana' size='1' color=red> <b>^</b> Re-enter the Email address in the proper format (username@domain.com). </font></p>"; } } ?> in Html page use this.. <input type="text" onblur="return validateEmail(this.value)"> <div id="emailError"></div> in javaScript use this.... function validateEmail(str) { var xmlHttp; xmlHttp=getXml(); if(xmlHttp==null) { alert("Your Browser Won't support Ajax "); return; } function Ready() { if(xmlHttp.readyState == 4) { document.getElementById("emailError").innerHTML=xmlHttp.responseText; } } var url ="ajaxError.php"; url = url + "?email="+str; xmlHttp.onreadystatechange= Ready xmlHttp.open("GET",url,true); xmlHttp.send(null); } function getXml() { var xmlHttp = null; try { xmlHttp=new XMLHttpRequest(); } catch(e) { try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp;s } thanks Shang.. Quote Link to comment Share on other sites More sharing options...
djbuddhi Posted April 20, 2008 Author Share Posted April 20, 2008 hey thanks .this is alright , let say u have another two fileds how do u validate like this . lets say u have zipcode filed, how do u change the js file as according my question .this is where i get stuick Quote Link to comment Share on other sites More sharing options...
shankar23 Posted April 22, 2008 Share Posted April 22, 2008 Hi, do you want to validate all the seperately field?? (or) want to validate all the fields in single click?? thanks, Shang.. Quote Link to comment Share on other sites More sharing options...
djbuddhi Posted April 22, 2008 Author Share Posted April 22, 2008 filed by filed i think validate by separately is better how 3 do it .need sample code Quote Link to comment Share on other sites More sharing options...
shankar23 Posted April 22, 2008 Share Posted April 22, 2008 in onBlur function you shall write the code.. <input type="text" onBlur="call some function to validate"> thanks, Shang.. Quote Link to comment Share on other sites More sharing options...
djbuddhi Posted April 22, 2008 Author Share Posted April 22, 2008 where to put the function in ajax file can mention the place where the function going 2 put //Browser Support Code var noOfSubmits = 0; function initForm() { noOfSubmits = 0; } function dome() { noOfSubmits = 0; } function clear_data(){ document.getElementById("title").value=0; document.getElementById("surname").value=""; document.getElementById("initials").value=""; document.getElementById("name_d_inintials").value=""; document.getElementById("nic_no").value=""; document.getElementById("FrmDate").value=""; document.getElementById("comp_usb_div").value=""; document.getElementById("emp_no").value=""; document.getElementById("add_1").value=""; document.getElementById("add_2").value=""; document.getElementById("town_city").value=""; document.getElementById("province").value=""; if (document.getElementById("chkagree").checked ){ document.getElementById("chkagree").checked = false; document.getElementById('row11').style.display="none"; document.getElementById('row12').style.display="none"; document.getElementById('row13').style.display="none"; } document.getElementById("mob_no").value=""; document.getElementById("office_telno").value=""; document.getElementById("res_tel_no").value=""; document.getElementById("email_add").value=""; } function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert(" Your browser Broke ..!Pls Try Again ...!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('div_Add_emp_info'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var com_tbl_id= document.getElementById("hdd_comp_id").value; var title=document.getElementById("title").value; var surname= document.getElementById("surname").value; var inintials= document.getElementById("initials").value; var name_d_initials= document.getElementById("name_d_inintials").value; var nic_no= document.getElementById("nic_no").value; var date_of_birth= document.getElementById("FrmDate").value; var sub_com_name=document.getElementById("comp_usb_div").value; var emp_no = document.getElementById("emp_no").value; var address_1= document.getElementById("add_1").value; var address_2= document.getElementById("add_2").value; var tow_city= document.getElementById("town_city").value; var province= document.getElementById("province").value; var agree= document.getElementById("chkagree").value; var new_add_1= document.getElementById("new_add_1").value; var new_add_2= document.getElementById("new_add_2").value; var new_town_city= document.getElementById("new_town_city").value; var mob_no= document.getElementById("mob_no").value; var office_telno= document.getElementById("office_telno").value; var res_telno= document.getElementById("res_tel_no").value; var emailno= document.getElementById("email_add").value; noOfSubmits++; if(noOfSubmits>1) { alert("Submission already done. Please wait while system is updating..!"); return false; } else{ emailno //var queryString = "?setle_agent_name="+settle_argent +"&set_address="+set_address+"&set_ag_telno="+set_telno +"&set_ag_fax_no="+set_faxno +"&set_ag_email_no="+set_email +"&set_ag_web="+set_web; var queryString = "?surname="+surname +"&comp_tblid="+com_tbl_id+"&initilas="+inintials +"&p_title="+title + "&name_denote_by_initials="+name_d_initials +"&NIC_NO="+nic_no +"&DOb="+date_of_birth +"&sub_com_name="+sub_com_name +"&p_emp_no="+emp_no +"&adress1="+address_1 +"&adress2="+address_2 + "&towncity="+tow_city + "&province="+province + "&my_agree="+agree + "&new_address1="+new_add_1 + "&new_address2="+new_add_2 + "&new_town_city="+new_town_city + "&office_telno="+office_telno + "&mob_no="+mob_no + "&residance_telno="+res_telno + "&email="+emailno; ajaxRequest.open("GET", "ajax_add_employee_infor.php" + queryString, true); ajaxRequest.send(null); clear_data(); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.