JavaScript - Wanted Table Tennis Scorer For My Phone
Similar TutorialsTake a variable... var time = "12:00" split it... var hour=time.split(":"); ...then add or subtract from the numeric value of hour[0] based on timezone. ie. EST = -5 PST = -8 What would be the best way of doing this? Hello I have a question for you guys and I hope someone could help me: I am trying to build a site , classified ads. And one of the features is selecting/making ads that you want to see in a separate page later on(something like a shopping cart) BUY way simpler after a user search for something he gets a LIST of numbered ads(different ID for each) and a button SELECT/MARK this ad. This select/mark button suppose to add the specific ad ID to a coockie and then when the user clicks "go to see my ads" its will pass ALL the ID numbers to aPHP page that will print what it should. what I was trying to do is try to use a "shopping cart" script and just use the part that each product has a "add to cart" button and in the "my cart" page it will show the selected products, but as I have no clue about javascript in this way I was willing to pass the variables(ID numbers) with JS and $_GET them with PHP and from there I can continue so what I need is : Asimple <form> that when u submit it , it sends a variable(ID) to a coockie and STAYS ON THE SAME PAGE then when you decide to see the selected list it will pass all the ID variables to the page with the link it self and I can GET it with PHP Any help Hi all, I want to find a Javascript if possible that emmulates the fuctionality shown under Editor's choice on either of these sites. http://www.irishtimes.com www.cnn.com I won't be using video but I would like the user to be able to click on a Left or Right arrow and upon doing this a new batch of Images with associated URL links will slide in. Problem I have is that I do not know what I should search for. Have tried keywords such as "Image Link Scroller", "Slideshow" but have not found a script that does something like what is on these websites. Any ideas? How can i go about showing on screen a count from an initial value to an end value over a set time period. Initial value = 0 End value = 2000 Time = 25 seconds I cant find an example of this anywhere, so I'm trying here to see if somebody can help Hi there, I have a search function on my website. When a user types something, options (including his characters) are displayed in a box (layer) as hyperlinks using Ajax, a very common feature these days. My problem is that if the user clicks somewhere else in page the links display stays on screen. I tried to fix the issue by adding an onBlur event to the search box (different id that the "display" div): Code: document.getElementById('livesearch').style.display = 'none'; where livesearch is the id of the hyperlinks displaying div. Job done but...the hyperlink "box" dissapear and the problem now is that the links are not working (if you click on one, the div dissapear first (I SUPPOSE) and no redirection to link is made....) I tried a couple of if else tricks I could think of with no success. No need to say that I am not a javascript wizz....hope you like the js1 username Any help will be appreciated. Thank you in advance, Julian Hello Everyone! How can I write a string in JavaScript that will accept any phone number. Thanks I am trying to validate textboxes on my form. I got everything but phone number. I have three different textboxes. One for area, one for first three, and last one for last 4numbers. everything just need to be digit numbers I guess. What is REGEX expression should be for those three different area?
Hi, I have a form on my website and I want to validate the phone field. I found a good script to do it but I need to combine the script with the other validation that I have on my form. Can you help me add this phone validation script into the other validations that I have so that it is just one javascript? Here is the phone validation script: <script language = "Javascript"> /** * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */ // Declaring required variables var digits = "0123456789"; // non-digit characters which are allowed in phone numbers var phoneNumberDelimiters = "()- "; // characters which are allowed in international phone numbers // (a leading + is OK) var validWorldPhoneChars = phoneNumberDelimiters + "+"; // Minimum no of digits in an international phone no. var minDigitsInIPhoneNumber = 10; function isInteger(s) { var i; for (i = 0; i < s.length; i++) { // Check that current character is number. var c = s.charAt(i); if (((c < "0") || (c > "9"))) return false; } // All characters are numbers. return true; } function trim(s) { var i; var returnString = ""; // Search through string's characters one by one. // If character is not a whitespace, append to returnString. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (c != " ") returnString += c; } return returnString; } function stripCharsInBag(s, bag) { var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function checkInternationalPhone(strPhone){ var bracket=3 strPhone=trim(strPhone) if(strPhone.indexOf("+")>1) return false if(strPhone.indexOf("-")!=-1)bracket=bracket+1 if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false var brchr=strPhone.indexOf("(") if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false s=stripCharsInBag(strPhone,validWorldPhoneChars); return (isInteger(s) && s.length >= minDigitsInIPhoneNumber); } function ValidateForm(){ var Phone=document.frmSample.txtPhone if ((Phone.value==null)||(Phone.value=="")){ alert("Please Enter your Phone Number") Phone.focus() return false } if (checkInternationalPhone(Phone.value)==false){ alert("Please Enter a Valid Phone Number") Phone.value="" Phone.focus() return false } return true } </script> Here are the validations for the other fields: <script type="text/JavaScript"> function validate_form(){ err = 'The following fields are not correct filled:\n'; if (document.form1.name.value == ''){ err += 'No First Name.\n'; } if (document.form1.from.value == ''){ err += 'No Email Address.\n'; } if (document.form1.elements['custom State'].value == ''){ err += 'No State.\n'; } if (document.form1.elements['custom Phone'].value == ''){ err += 'No Phone.\n'; } if (emailCheck(document.form1.from.value) == false){ err += 'No Valid email.\n'; } if (document.form1.terms.checked != true){ err += 'You did not agree with the terms.\n'; } if (err != 'The following fields are not correct filled:\n'){ alert (err); return false; } else{ return true; } } var str_vars = ''; function all_fields(){ str_vars = ''; el = document.form1; for (var i = 0; i < el.elements.length; i++) { if (el.elements[i].value != '') str_vars += el.elements[i].name+'='+el.elements[i].value+'&'; } str_vars = str_vars.substr(0,str_vars.length-15);; } </script> Thank you, Leroy Need Phone Number Validation for my JavaScript, i can't work it out It currently has E-mail, Surname, Address and Name validation, This is my code at the moment: Code: <script language="JavaScript"> function echeck(str) { var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(at,(lat+1))!=-1){ alert("Please Enter a Valid E-mail") return false } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(dot,(lat+2))==-1){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(" ")!=-1){ alert("Please Enter a Valid E-mail") return false } return true } function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") { alert(alerttxt);return false; } else { return true; } } } function validate_form(thisform) { with (thisform) { if (validate_required(Name,"Name must be filled out!")==false) {Name.focus();return false;} if (validate_required(Surname,"Surname must be filled out!")==false) {Surname.focus();return false;} if (validate_required(Country,"Address must be filled out!")==false) {Country.focus();return false;} } { var emailID=document.submitting.email if ((emailID.value==null)||(emailID.value=="")){ alert("Please Enter a Valid E-mail") emailID.focus() return false } if (echeck(emailID.value)==false){ emailID.value="" emailID.focus() return false } return true } } function verifyEmail(form) { checkEmail = form.email.value if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) {alert("You have entered an invalid email address. Please try again."); form.email.select(); return false; } else { form.method="get"; form.rel="nofollow" target="_self"; form.action="myscript.cgi"; form.submit(); } } </script> Code: <form action="submit.htm" onsubmit="return validate_form(this)" method="post" name="submitting"> <span class="style5">Select Plant: <form id="form1" name="form1" method="post" action=""> <label> <select name="Item" id="Item"> <option>OMGwoopwoop Plant</option> <option>I'm Blue Plant </option> <option>Anonymous Plant</option> <option>Rawr Plant</option> <option>Chicka Plant </option> <option>Fruitopola Plant</option> <option>Whitoe Plant</option> <option>Wukidoo Plant </option> </select> </label> </p> <p>Name:<span class="style1"> <input type="text" name="Name" size="30"> <br> <br> </span>Surname: <span class="style1"> <input type="text" name="Surname" size="30"> <br> <br> </span>Address:<span class="style1"> <input type="text" name="Country" size="30"> <br> <br> </span>Email:<span class="style1"> <input type="text" name="email" size="30"> <br></span></p> Phone Number:<span class="style1"> <input type="text" name="phone" size="30"> <form action="submit.htm" onSubmit="return validate_form(this)" method="post"> <input type="submit" value="Submit"> </form> Arrrgggghhhhhhhhh - help.... - LOL Now I've got that over with, hope someone can help. Am just learning regular expressions and am trying to validate UK format telephone numbers (have had an extensive look on the web and only examples I can find are US tests). Anyway, I want to learn to do it myself. UK phone number rules a Must start with a 0 in position 1 Next 2 to 4 characters must be a number Next character can be a space or a dash Next 6 to 9 characters can be a number, space or dash only Anyway, as I say, am new to regular expressions and trying to learn so I tried to write the expression to fit the rules above - see below: Code: ^[0]{1}\d{2,4}\s|-{1}\d|\s|-{6,9}$ My logic (for what it's worth - LOL) tells me this should work, but it doesn't - it accepts letters as well - which I really don't understand yet. Anyway - hope someone can help. Thanks Dominic Hi there, I need to validate three textboxes and it will validate for numbers. How should I change my code to validate three textboxes? 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> <title>Untitled Page</title> <script type='text/javascript' language="javascript"> var validPhoneChar = "+"; // Minimum no of digits in an international phone no. var minDigitsInPhoneNumber = 10; function isInteger(s) { var i; for (i = 0; i < s.length; i++) { // Check that current character is a number. var c = s.charAt(i); if (((c < "0") || (c > "9"))) return false; } // All characters are numbers. return true; } function stripCharsInBag(s, bag) { var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function checkRequirements(strPhone) { if(strPhone.indexOf("+") > 1) return false; s = stripCharsInBag(strPhone,validPhoneChar); return (isInteger(s) && s.length >= minDigitsInPhoneNumber); } function ValidateForm() { var Phone = document.getElementById("Text1"); //var Phone1 = document.getElementById("Text23"); if ((Phone.value == null)||(Phone.value == "")) //if match failed { alert("Please Enter your Phone Number."); Phone.focus(); return false; } /*if ((Phone1.value == null)||(Phone1.value == "")) //if match failed { alert("Please Enter your Phone Number0."); Phone.focus(); return false; }*/ if (checkRequirements(Phone.value) == false) { alert("Please Enter a Valid Phone Number."); Phone.value = ""; Phone.focus(); return false; } else alert("YAY!"); return true; } function NotAllowSpace() { // Get the ASCII value of the key that the user entered var key = window.event.keyCode; // Verify if the key entered was a Space if ( key == 32 ) { // If it was, then dispose the key and continue with entry window.event.returnValue = null; alert("Invalid,Please check") } else // If it was not, then allow the entry to continue return; } </script> </head> <body> <label>Office Telephone:</label> <input id="Text1" type="text" onkeydown = "return (event.keyCode != 32)"/><br /> <input id="Button1" type="button" value="button" onclick="return ValidateForm();" /><br /> </body> </html> I need to use Javascript to validate 3 textboxes, whereby the users can only key in numbers (because they are phone numbers related fields). If any of the textbox is empty, display an alert message to show which textbox is empty. I do not want to show many alert messages to show that, for example, text1 and text2 are empty, it will show two alert messages. I would need to show one "summarized" alert message instead. Next, check if the textbox matches the pattern (which is to check if it has the skeleton of a phone number). If it is, show an alert message that it is alright. Else, show that it does not match. I need someone to point me in the right direction... I have been tasked with creating a phone directory at work. I found an example that kind of works for what I need he http://www.mollerus.net/development/..._directory.cfm But we have a larger number of employees and I need to be able to sort the directory by first name, last name, or department. Can anyone show me where to go? Is there a download somewhere? I'll post the code below of what we're currently using. It is functional, but not pretty by any means, and needs altered to produce what we need. I don't know JavaScript, this is something I found a couple years ago that suited our purpose, but now it doesn't anymore. The Script: Code: function setUp(info) { var v = document.getElementById('phonesearch').selectedIndex.toString(); var ln, fn, ext; var arr = new Array(); var sel = document.getElementById('phonelist'); for (var i = sel.options.length-1; i >= 0 ; i--) { sel.options[i] = null; } for(i = 0; i < phonelist.length; i++ ) { fn = phonelist[i][0]; ln = phonelist[i][1]; ext= phonelist[i][2]; switch (v) { // case "1" : zo = ln+', '+fn; zv = zo +' : '+ext; break; case "2" : zo = fn+' '+ln; zv = zo +' : '+ext; break; case "3" : zo = ext+' : '+ln+', '+fn; zv = zo; break; default: zo = ln+', '+fn; zv = zo +' : '+ext; break; } if (info != '') { if (zo.toUpperCase().indexOf(info.toUpperCase(),0) == 0) { arr.push(zo+'||'+zv); } } else { arr.push(zo+'||'+zv); } } arr.sort(); // Like the original order, comment out this line! var z = []; for (i=0; i<arr.length; i++) { z = arr[i].split('||'); sel.options[i] = new Option(z[0],z[1],false,false); } var z = 13; if (phonelist.length < z) { z = phonelist.length; } sel.size = z; if (info == '') { sel.focus(); } } The Form Code: <form name="menuform" onSubmit="return false"> <p class="style1">Select to search by first name, last name, or extension. Then click in the text box on the bottom and type in the first few letters of who/what it is you're looking for.</p> <p class="style1">Then, simply click the entry you need.</p> <select id="phonesearch" onchange="setUp('')" size="4"> <option value=""><i>Choose one</i></option> <option value="1">Last name</option> <option value="2" selected>First name</option> <option value="3">Extension</option> </select> <br /><br /> <select id="phonelist" onclick="alert(this.value)"></select> <br /><br /> <input type="text" id="srch" value="" onkeyup="setUp(this.value)" size="20"> <br /><a href="#" onclick="sel=document.getElementById('srch');sel.value='';setUp('');sel.focus()">Search Clear</a> </form> I would like to use Javascript to format a UK telephone number to this layout: 00000 000000, preferably as the user enters it in the form. I am using Actinic's ecommerce system, and have already used the code in this link to format the postcode. http://community.actinic.com/showthread.php?t=45487 I have found the code here http://javascript.internet.com/forms...ne-number.html but it is for American telephone formats, and seems far too complicated! Has anyone come across any code that will do this for UK phone numbers? It would need to remove all white space, and then insert a space after 5 numbers. I am not bothered about validation checks etc. Thanks for your help Just wondering what the code is for a phone number to be displayed nn-nnnnnnnn for example: 67 43289482 current code is Code: var pn = document.contact_form.phonenum.value; if ((pn.length != 10) || (/[^0-9]/g.test(pn))) { // 10-digit phone number alert ( "Please fill in your 10-digit telephone number" ); return false; } Good Afternoon All, I am slowly learning how to validate forms and the next topic I'm learning is the phone feature! My code isn't working and not sure why! I read other opinions and tried to follow some templates but again.. Nothing is working out for me.. Here is the code function validatePhone(fld) { var stripped = document.validatePhone.phoneNumber(/[\(\)\.\-\ ]/g, ''); if (document.validatePhone.phoneNmbr == "") { alert("Do not leave this field blank"); } else if (isNaN(parseInt(stripped))) { alert("Only enter numerical digits only"); } else if (!(stripped.length == 10)) { alert("No More or Less than 10 Digits"); } return error; } <body> <form name="validatePhone" action="" method="get"><br /> <br /> <input type="text" name="phoneNumber" value="" onClick="return validatePhone(fld)"> <br /> <br /> <input type="button" name="button" value="Validate Phone Number" > </form> </body> </html> If you have any suggestions or can provide links of how I can 1-Provide an alert if the field is blank 2-Provide an alert if non numerical digits are entered 3-Provide an alert if more than 10 digits are entered I think I am on the right track but need more of a push.. I'm not seeking a solution, just information to get me on that right track as I am extremely confused. Also.. I feel like I should be using a isDigit function? Hi, I am trying to write a small web app that is used to do some plots for over-the-time-collected data (children's growth measurements). The current objective is to re-use entered data. As I do not want to store anything on the server (which would lead to all the annoying username-password-stuff), nor in cookies, I would like put measurements into a local file and reload them into the HTML entering form. I know and fully appreciate that javascript is not able to read or write files; it is on the other hand obvious that this can be bypassed if I upload the respective file to the server which returns it in an ajax fashion. My main question is now: Is it possible to do some kind of internal upload, that ends up in a read of a local file? Something like a <form method="post" action="localscriptname" ...> with an <input type="file"...> field? Another (off-topic) question: My plots are in PDF format. I accidentally appended some data to the PDF file which did not cause any problems for the pdf readers. Can I rely on the fact that any pdf reader will ignore data after the %%EOF mark, but will keep it if a file is downloaded, directly opened by acroread or whatever, and later saved from the reader program? This would allow it to keep the plot and the raw data in one file and might be helpful for the not-so-computer-affine target audience of my program. Greetings! i see alot of forms where the phone number field is split into 3 boxes and you can type smoothly from the first box to the last....here is the beginning code i have now for my form Code: <form id="contactform" action="contact-submit.php" method="post"> <!-- form fields --> <div class="form"> <label for="name">Name<em>•</em></label> <input class="textbox required" type="text" name="name" id="name" /><br /> <label for="email">E-Mail<em>•</em></label> <input class="textbox required email" type="text" name="email" id="email" /><br /> how do i add a phone number field in there that has 3 connected fields? This is what I have so far, it is a template I copied from my working E-mail validation. I'm assuming I have to make it so it's just an array of numbers but I really don't know Java too well. Essentially I just want numbers only to be accepted into the phone field. Code: else if(fieldType == 'phone') { if((required == 1 && fieldObj.value=='') || (fieldObj.value!='' && !validate_phone(fieldObj.value))) { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } function validate_phone(phoneStr) { apos=phoneStr.indexOf("@"); if (apos<1||dotpos-apos<2) { return false; } else { return true; } } Hi everyone, Is it possible to determine at the startup of the page if the visitor is using a computer or a phone to access the site? I would like to make the intro process much better than a simple "click here for HTML version or click here for Flash version". I would like for it to simply redirect to the page I set it to go to depending on whether or not they're using a regular browser or a mobile browser. How would I go about this? Thank you all very much in advance. I have a phone number field on my form that needs validation, but I'm not sure how to code this. I have the following function to validate a first name is entered and last name. The phone number field must match a 7 digit or 10 digit(with area code)phone number. I want to be able to include paranthese and/or hyphens for the valid phone number. function checkForm1() { if (document.forms[0].firstname.value.length == 0) { alert("You must put in a first name"); return false; } else if (document.forms[0].lastname.value.length == 0) { alert("You must put in a last name"); return false; } |