JavaScript - Validate Email Field To Reject Certain Domains
here is my current email validation code:
function validateEmail(strValue) { var objRegExp = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i; return objRegExp.test(strValue); } what should i add to reject email addresses from hotmail.com and yahoo.com? Similar TutorialsHello: I have an expression validating email addresses but it seems there is a loophole. If a user enters a comma this is accepted. Can anyone tell me how i can modify the following to disallow commas? validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i; strEmail = document.form1.df_email1.value; if (strEmail.search(validRegExp) == -1) { alert("A valid e-mail address is required."); document.form1.df_email1.focus(); return false; } hiiii, im new to javascripts . Can anyone help me to know that a javascript which is validating a phone number accepts only digits but if the text field is left empty it should accept the entry as an empty entry.... plz share knowledge u will be more knowledgeable [ICODE] <html> <head> <title>ABS</title> <?php $j="dove"; ?> <script language="JavaScript" type="text/javascript"> <!-- function checkform ( form ) { if (form.Name.value == "") { alert( "Please enter your email address." ); form.Game.value="<?php echo $j;?>"; form.Name.focus(); return false ; } if (form.Game.value == "") { alert( "Please enter your game address." ); form.Game.focus(); return false ; } if (document.form.Shame[0].value== "") { alert( "Please enter your game address." ); form.Game.focus(); return false ; } return true ; } </script> </head> <body> <form name="form" action="Store_it.php" method="post" onSubmit="return checkform(this);"> <input type="text" name="Name" /> <input type="text" name="Game" /> <input type="text" name="Shame[]" /> <input type="text" name="Shame[]" /> <input type="text" name="Shame[]" /> <input name="submit" type="submit"> </form> </body> </html> [icode] I need to use the array's shame and just check if the third one is not empty. I have searched DOM and other stuff but i cannot get to the 2 element of the array shame. How do i check the value of the array. The below code works ok but need our help to get it perfect. I want the function to validate that after the "@" the user types "wendys.com". Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>New Page 1</title> <SCRIPT> function validateLP(theForm){ if(theForm.DM_Email){ var checkEmail =theForm.DM_Email.value; var invalidChars = " /:,;" if (checkEmail == "") { alert("Please enter a valid Wendys DM email address."); theForm.DM_Email.style.backgroundColor='#FFFF99'; theForm.DM_Email.focus(); return false; } if (checkEmail != "") { // can be empty for (i=0; i<invalidChars.length; i++) { // does it contain any invalid characters? var badChar = invalidChars.charAt(i) if (checkEmail.indexOf(badChar,0) > -1) { alert("Please enter a valid Wendys DM email address."); theForm.DM_Email.style.backgroundColor='#FFFF99'; theForm.DM_Email.focus(); return false; } } var periodPos1 =checkEmail.indexOf(".",1) // there must be one "." symbol var atPos = checkEmail.indexOf("@",periodPos1-1) // there must be one "." symbol before "@" var periodPos2 = checkEmail.indexOf(".",atPos) //periodPos2 = checkEmail.indexOf(".",atPos) if ( (atPos == -1) || (periodPos2 == -1)){ //return false alert("Please enter a valid Wendys DM email address."); theForm.DM_Email.style.backgroundColor='#FFFF99'; theForm.DM_Email.focus(); return false; } } } } </SCRIPT> </head> <body> <form method="POST" NAME="theForm" onSubmit="return validateLP(theForm)" action="--WEBBOT-SELF--"> <p><input type="text" name="DM_Email" size="20"></p> <p> </p> <p> </p> <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body> </html> I have this script to validate contact form fields. It works fine for checking that fields are not blank. I added the valid email code, which I copied from the w3schools web site. But, it does not work. I am confused about how to reference the email form field name. That is really the only thing I changed, that is, I added the frm.elements to the email variable. Can anyone please help? Thanks! Code: function validate_form(frm) { frm.elements.name.className = "input"; frm.elements.email.className = "input"; frm.elements.subject.className = "input"; frm.elements.comments.className = "input"; var errors=0; // // NAME cannot be blanks // if (isBlank(frm.elements.name.value)) { frm.elements.name.className = "inputreq"; errors++; } // // EMAIL ADDRESS cannot be blanks // if (isBlank(frm.elements.email.value)) { frm.elements.email.className = "inputreq"; errors++; } // // SUBJECT cannot be blanks // if (isBlank(frm.elements.subject.value)) { frm.elements.subject.className = "inputreq"; errors++; } // // COMMENTS cannot be blanks // if (isBlank(frm.elements.comments.value)) { frm.elements.comments.className = "inputreq"; errors++; } // // EMAIL ADDRESS appears invalid // if (validate_email(frm.elements.email.value,"Not a valid e-mail address!")==false) { alert("TEST"); frm.elements.email.focus(); return false; } // // Errors // if (errors>0) { alert("Please enter all fields!"); return false; } //No errors //frm.submit(); } function isBlank(value) { regexp = /^\s*$/ return (value==null || regexp.test(value)); } // Validate email address function validate_email(field,alerttxt) { with (field) { apos=value.indexOf("@"); dotpos=value.lastIndexOf("."); if (apos<1||dotpos-apos<2) {alert(alerttxt);return false;} else {return true;} } } I am Gururaj. I have written a form in HTML which contains username,lastname,email,password and submit. I have written a javascript to validate this form [validate(username,lastname,email,password)]. On submit this javascript function will be called and hence form get validated. I am passing all the arguements(username,lastname,email and password) to the javascript function.. Is it possible to make me a code such that it should call an individual function for each field in the form.for ex:if i have not entered username, last name in the form and attempt to submit, only username arguement should be passed to the function as it comes first in the form. In other sense i want to validate individual text field validation of my form. So can anybody help me.It will be very needful to me. alright so i am trying to validate this form and if you do not fill out the Day of the week then it does not submit the form to email.... Code: <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Guest List Signup</title> <style type="text/css"> <!-- body,td,th { color: #FFF; } body { background-color: #000; } --> </style></head> <script type='text/javascript'> function madeSelection(elem, helperMsg){ if(elem.value == "Select"){ alert(helperMsg); elem.focus(); return false; }else{ return true; } } </script> <body bgcolor="#000000" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"> <form name="halo-gl" form method="POST" action="contactgl.php"> <p>If you want to have your name on the HALO guest list please fill out the form below before 9pm and you and your guests will be on the list at the door. <p>This will get you free entry* until 11:30pm (this means at 11:31pm the list is over) also on select events there will not be a list and we might not have it posted on the website. <p>Guest list does not guarantee entry. It is to the discression of Halo on wether someone is permitted or not. <p> <p>Your Name:<br> <input type="text" name="MyName"> (First and Last) <p>How Many People I Will Have:<br> <select name="HowManyPeopleIWillHave"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <p>What day to be on the list:<br> <select id='selection'> <option value="Select">Please Select</option> <option value="Wednesday">Wednesday</option> <option value="Thursday">Thursday</option> <option value="Friday">Friday</option> <option value="Saturday">Saturday</option> </select> <p><input type="submit" name="submit" value='Submit' onclick="madeSelection(document.getElementById('selection'), 'Please Choose Something')" > </form> <p> </body> </html> you can see this currently in action at http://www.haloclt.com/guestlist.html any help would be appreciated thank you Hi, I want to check the email address type in a contact form but want to reject it if it's from a certain domain I actually use this regexp : /^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/ (taken from the jquery validationengine) to check if the email address is correctly formated but I'd like to reject it if contains hotmail between the @ and the . I tried many things but couldn't get something that works. If anyone has an idea, it would be greatly appreciated. Chag Hi there, I would like to validate the email address typed into the prompt message by the user, but to no avail. Can some kind soul help? Code: function addOption() { var new = prompt("Enter New Item:"); if (!new == "") { var answer = confirm ("Are you sure you want to add? ") if (answer)//if answer is true { var lst = document.getElementById('lstBx'); // listbox control id // Now we need to create a new 'option' tag to add to MyListbox for (var i = 0; i < lst.options.length; i++) { arrTexts = lst.options[i].text; if (arrTexts.toLowerCase() == newItem.toLowerCase()) { alert ("That email address is already included in the list - please enter another one."); break; } else { validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i; strEmail = lst.value; // search email text for regular exp matches if (strEmail.search(validRegExp) == -1) { alert('A valid e-mail address is required.\nPlease retry.'); return false; } var optionNew = document.createElement("option"); optionNew.value = new; // The value that this option will have optionNew.innerHTML = new; // The displayed text inside of the <option> tags // Finally, add the new option to the listbox lst.appendChild(optionNew); //sort items in listbox in alpha order arrTexts = new Array(); for(i=0; i<lst.length; i++) { arrTexts[i] = lst.options[i].text; } arrTexts.sort(); for(i=0; i<lst.length; i++) { lst.options[i].text = arrTexts[i]; lst.options[i].value = arrTexts[i]; } } return false; } } } else { if(new == "") { alert("Key something to textbox please."); } else alert("Cancelled."); } } Code: <select id="lstBx" name="listBox" size="6" style="width: 580px;"> <option>a@hotmail.com</option> <option>b@hotmail.com</option> <option>c@yahoo.com</option> <option>d@gmail.com</option> <option>e@ymail.com</option> <option>f@msn.com</option> </select> Hi! I would like to show you guys the JavaScript that i using for my contact form /*----- Code goes here by clicking the link -----*/ http://web.ezenne.com/js/completeValid.js The above code was copied from a Youtube tutorial about JavaScript. I would like to ask, what additional code should be added in the existing code in order to validate the numbers only and an email format before the form to be submitted? Thanks! Regards, Ezenne Hello, I'm trying to make sure that my email field contains at least 5 characters and the @ symbol. I've been trying to do this using an if...else loop, but so far I've only been running into brick walls. I think my problem is I don't know what to use when it comes to document.form1.email.value This is the latest script I tried: Code: <html> <head> <title>Form Example</title> <script language="JavaScript" type="text/javascript"> function validate() { if (document.form1.yourname.value.length < 1) { alert("Please enter your full name."); return false; } if (document.form1.address.value.length < 3) { alert("Please enter your address."); return false; } if (document.form1.phone.value.length < 3) { alert("Please enter your phone number."); return false; } if (document.form1.email.value.length < 5) alert("Please enter at least 5 characters."); else if (document.form1.email.value.match(@)) alert("Please enter an @ symbol."); return false; return true; } </script> </head> <body> <h1>Form Example</h1> <p>Enter the following information. When you press the Submit button, the data you entered will be validated, then sent by email.</p> <form name="form1" action="mailto:user@host.com" enctype="text/plain" method="POST" onSubmit="return validate();"> <p><b>Name:</b> <input type="TEXT" size="20" name="yourname"> </p> <p><b>Address:</b> <input type="TEXT" size="30" name="address"> </p> <p><b>Phone: </b> <input type="TEXT" size="15" name="phone"> </p> <p><b>Email Address: </b> <input type="TEXT" size="30" name="email"> </p> <p><input type="SUBMIT" value="Submit"></p> </form> </body> </html> Hello I have a form validation script which checks for empty fields and an email address. The empty fields part seems to work, but not the validation (as long as I type characters in the email field, it seems to be acceptable). Here is what I have: Code: //function to check for empty fields function isEmpty(strfield1, strfield2, strfield3) { //change "name, email and subject" to your field names strfield1 = document.forms[0].ContactUs_Name.value strfield2 = document.forms[0].ContactUs_Email.value strfield3 = document.forms[0].ContactUs_Subject.value //name field if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ') { alert("\"Name\" is a mandatory field.\nPlease amend and retry.") return false; } //url field if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ') { alert("\"Email\" is a mandatory field.\nPlease amend and retry.") return false; } //title field if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ') { alert("\"Subject\" is a mandatory field.\nPlease amend and retry.") return false; } return true; } //function to check valid email address function isValidEmail(strEmail){ validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i; strEmail = document.forms[0].email.value; // search email text for regular exp matches if (strEmail.search(validRegExp) == -1) { alert('A valid e-mail address is required.\nPlease amend and retry'); return false; } return true; } //function that performs all functions, defined in the onsubmit event handler function check(form){ if (isEmpty(form.ContactUs_Name)){ if (isEmpty(form.ContactUs_Email)){ if (isEmpty(form.ContactUs_Subject)){ if (isValidEmail(form.email)){ return true; } } } } return false; } </script> </head> <body bgcolor="#ECECEC" text="#000000"> <h3>Form validation with JavaScript</h3> <form name="theform" method="post" action="#" onSubmit="return check(this);"> Name:<br /> <input name="ContactUs_Name" type="text" /><br /> E-Mail:<br> <input name="ContactUs_Email" type="text" id="ContactUs_Email" /> <br /> Subject:<br> <input name="ContactUs_Subject" type="text" id="ContactUs_Subject" /> <br> I just wondered, is it here that the problem lies: if (isValidEmail(form.email)){ Thanks. Steve i'm using a shopping cart template and i do NOT want to require that shoppers have to enter their email address. how do I disable the requirement, but still ensure if they do type it in, that the format is correct (i.e. person@website.com)? thanks! PHP Code: <?php if(! is_array($alladdresses)){ ?> if(frm.email.value==""){ alert("<?php print $xxPlsEntr?> \"<?php print $xxEmail?>\"."); frm.email.focus(); return (false); } validemail=0; var checkStr = frm.email.value; for (i = 0; i < checkStr.length; i++){ if(checkStr.charAt(i)=="@") validemail |= 1; if(checkStr.charAt(i)==".") validemail |= 2; } if(validemail != 3){ alert("<?php print $xxValEm?>"); frm.email.focus(); return (false); } I have a web form that requests a user full name and email address. What I would like to do is when the user fills in the full name in one input box, I would like to take the full name and populate the email address field as such. "first.last@allstate.com". So pretty much split the full name and popluate email address field "first.last@allstate.com". Tracy Hey All, Been having some trouble with this, I am trying to find a javascript or DHTML form field which is similar to the outlook web access email address fields which show an icon to identify the address, and the screen name of the address instead of the full email address, as a hyperlink. I was wanting to know if anyone knows of something like this already around or if I need to design my own. Thanks in advance. Hello all, I have a form that submits a POST request when data is submitted. A Servlet then processes this POST request and a JavaBean is used to make some calculations. The HTML response is not generated within the Servlet but instead I forward the request to a JSP to generate the response. - This all works fine, thankfully. However, I am stupidly suck trying to validate the form on the client side with a JavaScript function before the form is submitted. Here is my index.jps: Code: <%-- Document : index Created on : 19-Nov-2009, 13:41:30 Author : lk00043 --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/JavaScript"> <!-- Start hiding JavaScript Statements function validateForm() { var student; var score1, score2, score3, score4; student = document.getElementById('student'); s1 = document.getElementById('score1'); s2 = document.getElementById('score2'); s3 = document.getElementById('score3'); s4 = document.getElementById('score4'); score1 = parseInt(s1.value); score2 = parseInt(s2.value); score3 = parseInt(s3.value); score4 = parseInt(s4.value); if(student.value.length == 0) { document.getElementById('StudentError1').innerHTML = " Enter a student name!"; return false; } if ((isNaN(score1)) || (score1 < 0) || (score1 > 100)) { document.getElementById('Error1').innerHTML = " Enter a number between 0 and 100!"; return false; } if ((isNaN(score2)) || (score2 < 0) || (score2 > 100)) { document.getElementById('Error2').innerHTML = " Enter a number between 0 and 100!"; return false; } if ((isNaN(score3)) || (score3 < 0) || (score3 > 100)) { document.getElementById('Error3').innerHTML = " Enter a number between 0 and 100!"; return false; } if ((isNaN(score4)) || (score4 < 0) || (score4 > 100)) { document.getElementById('Error4').innerHTML = " Enter a number between 0 and 100!"; return false; } } // End hiding JavaScript Statements --> </script> <title>Lab Class 7 - Task 2</title> </head> <body> <h1>Lab Class 7</h1> <form name="collectgrades" action="AssessGrades" method="POST" onSubmit="validateForm()" > Name of Student: <input type="text" name="student" id="student"/><span id="StudentError1"> </span><br /> Presentation: <input type="text" name="score" id="score1"/><span id="Error1"> </span><br /> Writing style: <input type="text" name="score" id="score2"/><span id="Error2"> </span><br /> Technical content: <input type="text" name="score" id="score3"/><span id="Error3"> </span><br /> Depth of analysis: <input type="text" name="score" id="score4"/><span id="Error4"> </span><br /> Feedback:<select name="feedback" size="4" multiple="multiple"> <option>"Could be better structured."</option> <option>"Depth of analysis is good."</option> <option>"Very advanced material."</option> <option>"Very well structured."</option> </select><br /> <input type="submit" value="Submit" /> </form> </body> </html> Regardless of whether incorrect input is given, the data is still POSTed to the server and calculated on or a Server Side error is given. Am I correct in calling the function onClick? The validation essentially needs to be so that: - Student field contains a string - Score1, Score2, Score3 and Score 4 contain a number between 0 and 100 Any help is most appreciated, Cheers, Beetle. I'm trying to work with XML DOM for the first time as I need to grab a value from a SOAP request. I've been following this: http://www.w3schools.com/xml/xml_parser.asp, which says modern browsers won't parse xml files from another server for security reasons. How would I got about doing this then? I've been using the price of crude oil as an example (http://www.google.com/ig/api?stock=OIL) and want code portable enough to put on something like Tumblr, so I don't think I can actually save the file locally first. Any ideas? Thanks, Zach so that the form only submits when 2 fields are identical? this is the code I am trying to edit Code: <div class="title">ENROLLMENT</div> <p>You are on your way to receiving <strong>generous cash backs</strong> <em>PLUS</em> a <strong>steady stream of free dinners</strong> just for shopping at your favorite stores!</p> <br /> <form action="" class="registration" id="cform"> <div> To begin, please complete the following:<br /> <div class="f11"> <input type="text" name="name" value="Name:" onfocus="if(this.value=='Name:')this.value=''" /><br /> <input type="text" name="address" value="Address:" onfocus="if(this.value=='Address:')this.value=''" /><br /> <input type="text" name="phone" value="Phone:" onfocus="if(this.value=='Phone:')this.value=''" /><br /> <input type="text" name="email" value="E-mail:" onfocus="if(this.value=='E-mail:')this.value=''" /><br /> <input type="text" name="confirm" value="Confirm Email:" onfocus="if(this.value=='Confirm Email:')this.value=''" /><br /> <fieldset style="width:330px"> How would you like your free restaurant gift certificates sent to you? <br /> <input class="checkbox" name="gift_1" id="c1" type="checkbox" value="yes" /> <label for="c1">U.S. Mail</label> <input class="checkbox" name="gift_2" id="c2" type="checkbox" value="yes" /> <label for="c2">E-mail</label> </fieldset> </div> <br /> <div class="align-center"><a href="javascript:void(0);" id="sbm"><img alt="" src="images/button-submit.gif" /></a></div> </div> </form> <center><img src="/images/registration.jpg" ALT="registration" class="border" style="margin-top:20px" /></center> Code: /** * @author bob4ik */ $(document).ready(function(){ html = '<div id="displayResponse" style="display:none;"><div id="inner">Processing...</div></div>'; $('#cform').before(html); $('#sbm').click(function(){ $('#cform').submit(); }); var options = { target: '#displayResponse', // target element(s) to be updated with server response beforeSubmit: before, // pre-submit callback // success: success, // post-submit callback url: 'includes/mail.ctrl.php', // override for form's 'action' attribute type: 'post', // 'get' or 'post', override for form's 'method' attribute resetForm: true // reset the form after successful submit }; // bind to the form's submit event $('#cform').submit(function(){ error = '<div id="inner">Processing...</div>'; $('#displayResponse').empty(); $('#displayResponse').append(error); $('#displayResponse').toggle(); $(this).ajaxSubmit(options); return false; }); }); function before(formData, jqForm, options){ var error = ''; var form = jqForm[0]; if (!form.name.value && !form.email.value && !form.address.value && !form.phone.value && !form.hear.value && !form.confirm.value) { error = error + '<div style=""><b>Please fill all fields</b></div>'; } else { if (!form.name.value||form.name.value=="Name:")error = error + '<div style=""><b>Please fill "Name" field</b></div>'; if (!form.address.value||form.address.value=="Address:")error = error + '<div style=""><b>Please fill "Address" field</b></div>'; if (!form.phone.value||form.phone.value=="Phone:")error = error + '<div style=""><b>Please fill "Phone" field</b></div>'; if (!form.c1.checked && !form.c2.checked)error = error + '<div style=""><b>Please fill "How would you like your free restaurant gift certificates sent to you?" field</b></div>'; if (!form.email.value||form.email.value=="E-mail:")error = error + '<div style=""><b>Please fill "E-mail address" field</b></div>'; if (!form.confirm.value||form.confirm.value=="Confirm Email:")error = error + '<div style=""><b>Please fill "Confirm E-mail address" field</b></div>'; if ((form.email.value.match(/[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/i) == null) && form.email.value && (form.email.value.match(/^.+@.+\..+$/) == null)&& form.email.value!="E-mail:") { error = error + '<div style=""><b>Invalid e-mail</b></div>'; } if ((form.confirm.value.match(/[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/i) == null) && form.confirm.value && (form.confirm.value.match(/^.+@.+\..+$/) == null)&& form.confirm.value!="Confirm Email:") { error = error + '<div style=""><b>Invalid e-mail</b></div>'; } } if (error != '') { error = error + '<br><a href="#" onclick="javascript: $(\'#displayResponse\').toggle(); return false;"><img src="images/close.gif" border="0"></a>'; error = '<div id="inner">' + error + '</div>'; $('#displayResponse').empty(); $('#displayResponse').append(error); return false; } else { return true; } } Hi, I am trying to redirect a domain to a list of different domains. The code I found on this page works: http://javascriptsource.com/navigation/random-page.html However this provides a random redirect. Ideally I would like the redirect to work in chronological order so that each domain receives the same amount of visitors. For example: Visitors 1 is redirected to DOMAIN A Visitors 2 is redirected to DOMAIN B Visitors 3 to DOMAIN C Visitors 4 to DOMAIN D Once DOMAIN D is visited the sequence would repeat and the next visitor would be directed to DOMAIN A. Is this possible? Is there some way for me to tweak the code on the page above to make this happen? I am an idiot when it comes to coding, and have never have used JavaScript, so any help would be GREATLY APPRECIATED, thanks!! Hi folks. Looking to see if anyone could tell me where I'm going wrong with this script... I'm trying to have a field automatically filled with the day of the week ("Monday", "Tuesday", "Wednesday" and so on), upon the user selecting a date from the datepicker jQuery. If this isn't clear, I'll clarify further down the page. Here is the script: Code: <script type="text/javascript"> jQuery(document).ready(function($){ $('input[name="item_meta[428]"]').change(function(){ var d = $('input[name="item_meta[428]"]').val(); var n = new Date(d).getDay(); if(n == 0) val v = 'Sunday'; else if(n == 1) val v = 'Monday'; else if(n == 2) val v = 'Tuesday'; else if(n == 3) val v = 'Wednesday'; else if(n == 4) val v = 'Thursday'; else if(n == 5) val v = 'Friday'; else if(n == 6) val v = 'Saturday'; $('input[name="item_meta[429]"]').val(v).change(); }); }); </script> I'm basically trying to say, if the user selected today (15/05/2012) in the field 428 it would fill the field 429 with "Tuesday". Again, if the user selected 18/05/2012 in the field 428 then it would automatically fill field 429 with "Friday". It's being done to work in conjunction with a wordpress plugin called Formidable Pro hence the item_meta[428] etc. Any assistance would be greatly appreciated. Sam. |