JavaScript - Javascript Phone Directory Help
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> Similar TutorialsHi, 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 Hi there, I would like to allow the "+" sign in my 3 textboxes. When the user does not put the "+" sign in the textboxes, and it is being validated, the system will allow it to pass. Also, it must check that it has at least 8 digits. 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> <link rel="stylesheet" type="text/css" href="CSS files/specialAlignment.css" /> <link rel="stylesheet" type="text/css" href="CSS files/externalCSS.css"/> <script language = "javascript" type = "text/javascript"> function check() { var fields = new Array("Office Telephone", "Mobile Telephone","Fax Number"); var telnr = /(^[\+]?[\d]{8,20}$)/; var index = new Array(); for(var i = 0; i < fields.length; i++) { var arrayFields = document.getElementsByName(fields[i]); for(var j = 0; j < arrayFields.length; j++) if(!(arrayFields[j].value) == "") { arrayFields[j].className = "defaultColor"; } else { arrayFields[j].className ="changeToRed"; index.push(fields[i]); } } if(index != 0) { joinComma = index.join(', '); alert('The field(s) corresponding to '+ joinComma + ' is/are not filled in.'); } } function noSpace(e, dec) { var key; var keychar; if (window.event) { key = window.event.keyCode; } else if (e) { key = e.which; } else { return true; } keychar = String.fromCharCode(key); if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) /*|| (key==107)*/) { return true; } else if ((("0123456789").indexOf(keychar) > -1)&& check(telnr.test(tfld))) { return true; } else if (dec && (keychar == ".")) { return true; } else return false; } </script> </head> <body> <label> *Office Telephone:</label> <input id="Text16" type="text" name="Office Telephone" onkeydown="return noSpace(event)" /> <br /> <br /> <label> *Mobile Telephone:</label> <input id="Text17" type="text" name="Mobile Telephone" onkeydown="return noSpace(event)" /><br /> <br /> <label> *Fax Number:</label> <input id="Text18" type="text" name="Fax Number" onkeydown="return noSpace(event)" /> <br /> <br /> <input id="Submit17" type="submit" value="Submit" onclick="return check()"/> </body> </html> Hi, I'm attempting to add the following functionality to my site. Essentially, two images are displayed with a link "View More". The user clicks "View More" and the two images are replaced by two new images. This can be repeated as required. It's a basic form of slideshow I guess, but after some googling all the tutorials etc available seem to be more aimed at fully blown shows, whereas I believe my problem is much more simple. The images are contained in a directory and are numbered like so: img1.jpg, img2.jpg. img3.jpg and so on. the code I came up with so far is PHP Code: <script type="text/javascript" language="JavaScript"> start = '<img src="gallery/img'; end = '.jpg" width="150" height="200" />'; function getImage() { var n = Math.ceil(Math.random() * 10); // i have 10 images var FirstImg=(start+n+end); var n = Math.ceil(Math.random() * 10); var SecondImg=(start+n+1+end); } /* so now I think I have two variables: FirstImg = <img src="gallery/img1.jpg" width="150" height="200" /> SecondImg = <img src="gallery/img4.jpg" width="150" height="200" /> but i'm now unsure how i'd go about displaying this on the page. ideally the HTML generated would be: <div class="pics"> <p><FirstImg></p> <p><SecondImg></p> <a href="#" onClick="return getImage()">View More</a> </div> */ </script> Am I on the right lines here or am I way off?? Appreciate some pointers. thanks a lot. I would like to use functionality similar to DirectoryInfo and FileInfo using server-side javascript in ASP.NET, but neither are recognized. What are the equivalents, if they exist, in javascript?
is there some way to searching through multiple path or recursively searching through a path (folders and subfolders) using the code below which seems to search only one node in the tree? Many Thanks. there are basically subfolders in \documents and then subfolders therein. i would like to search it therein for all kinds of files/filenames based on "search criteria". one more thing - is it ok/advisable to use active x objects considering most modern browsers have it disabled or give warnings? Code: <script> var Fo =new ActiveXObject("Scripting.FileSystemObject"); var StrOut = new String(); var FileName = new String(); var Extention = new String(); function FindFile(FOo) { var FSo = new Enumerator(FOo.Files); for(i=0;!FSo.atEnd();FSo.moveNext()) { if(FileName == "*" || FSo.item().name.slice(0,FSo.item().name.lastIndexOf(".")).toLowerCase().indexOf(FileName)>-1) if(Extention == "*" || FSo.item().name.slice(FSo.item().name.lastIndexOf(".")+1).toLowerCase().indexOf(Extention)>-1){ StrOut += "<tr "+ ((i%2)? "":"bgcolor=#C4E3F2") +"><td width=50%><font class=find>" + FSo.item().name + "</font></td><td width=25%><font class=find>" + FSo.item().type + "</font></td><td width=50%><font class=find>"+ String(FSo.item().size/(1024*1024)).slice(0,3) +" MB</font></td></tr>"; i++ } } } function Search() { FileName = (search.value.lastIndexOf(".")>-1)? search.value.slice(0,search.value.lastIndexOf(".")):(search.value.length>0)? search.value.toLowerCase():"*"; //Get Searched File Name Extention = (search.value.lastIndexOf(".")>-1)? search.value.slice(search.value.lastIndexOf(".")+1).toLowerCase():"*"; // Get Searched File Extention Name if(path.value.length>0 && Fo.FolderExists(path.value)){ StrOut = "<table border=0 width=100% cellspacing=0>" FindFile(Fo.GetFolder(path.value)); outPut.innerHTML = StrOut+"</table>"; } else alert("Insert Correct Path Address"); } </script> Code: <BODY topmargin="0" leftmargin="0"> <table border=0 width=100% cellspacing="0" style="border-collapse: collapse" cellpadding="2"><tr> <td dir="ltr" bgcolor="#FFD9D9"><b><font face="Verdana" size="2">Filename : </font></b> </td> <td dir="ltr" bgcolor="#C4E3F2"> <input size=50 type=text id=search name=search class="Find"></td> </tr><tr> <td dir="ltr" bgcolor="#C4E3F2"> <p dir="ltr"></td> <td bgcolor="#FFD9D9"><input size=50 type=hidden value="\Documents" id=path name=path class="Find" > <input type=button value="Search" onClick=Search() class="Find"></td> </tr><tr> <td colspan=2 align=left bgcolor="#FFFFFF"><font face=Verdana size=2><b>Search Result</b></font><hr></td> </tr><tr> <td colspan=2 bgcolor="#FFFFFF"><div id=outPut></div></td> </tr></table> </BODY> </HTML> 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> 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; } 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 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 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? 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?
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 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 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? 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; } Hi. I need help in adding a parenthesis in the area code of the phone number and validating it also. I made some javascript code but it is not working. Can somebody please help? I just need the code in adding () in the area code. For example: When user enter 10 digit number no spaces or dashes such as 0000000000 or 000-000-0000, I would like to have this format right away (000)000-0000. I know how to replace the characters but adding it is a tricky one for me. Can somebody please help? Thanks. I have more than a hundred images (small ones though), which is a cut-to-pieces large image arranged in tables that I want to preload. I have been looking for a preload script that could possibly load all images in a folder by wildcard and if possible via JavaScript. Any suggestions? Any other language will be welcome as long as it will run on Linux. I have a good preload javascript here that I downloaded from hotscripts.com that displays a progress bar, percentage of download, and number of images downloaded. The bad thing is that creating an array out of a hundred images will be tedious especially with computer genereted filenames! If anyone knows of a program that could automate the process then we can forget the wildcard! Hehe! Hope someone has ideas . Thanks in advance. |