JavaScript - Get Client Mac Address With Javascript
hi,
how can i get client mac address OR hdd id with javascript for internet explorer? Similar TutorialsAC_ActiveX.js & AC_RunActiveContent.js is for java app that detect my client mac address I have java application running on my computer. I've tested on several pc, sometimes it detect the mac address, but sometimes nothing came out. In create_users.php, somehow im not able to store the mac address into a variable..( var mac = getMacAddress(); ) 1) Are my java coding would run on every pc? 2) I'm able to print out the mac address with "document.write(getMacAddress());" but why isit having stored in the variable is an issue? 3) which explorer would be the best to have the java running? IE/FF/Opera? create_users.php PHP Code: <script src="Scripts/AC_ActiveX.js" type="text/javascript"></script> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> <!--[if !IE]> Firefox and others will use outer object --> <embed type="application/x-java-applet" name="macaddressapplet" width="0" height="0" code="MacAddressApplet" archive="macaddressapplet.jar" pluginspage="http://java.sun.com/javase/downloads/index.jsp" style="position:absolute; top:-1000px; left:-1000px;"> <noembed> <!--<![endif]--> <!----> <script type="text/javascript"> AC_AX_RunContent( 'classid','clsid:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA','type','application/x-java-applet','name','macaddressapplet','style','position:absolute; top:-1000px; left:-1000px;','code','MacAddressApplet','archive','macaddressapplet.jar','mayscript','true','scriptable','true','width','0','height','0' ); //end AC code </script><noscript><object classid="clsid:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA" type="application/x-java-applet" name="macaddressapplet" style="position:absolute; top:-1000px; left:-1000px;" > <param name="code" value="MacAddressApplet"> <param name="archive" value="macaddressapplet.jar" > <param name="mayscript" value="true"> <param name="scriptable" value="true"> <param name="width" value="0"> <param name="height" value="0"> </object></noscript> <!--[if !IE]> Firefox and others will use outer object --> </noembed> </embed> <script> function getMacAddress(){ document.macaddressapplet.setSep( "-" ); return (document.macaddressapplet.getMacAddress()); } var mac = getMacAddress(); </script> AC_ActiveX.js Code: function AC_AX_RunContent(){ var ret = AC_AX_GetArgs(arguments); AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs); } function AC_AX_GetArgs(args){ var ret = new Object(); ret.embedAttrs = new Object(); ret.params = new Object(); ret.objAttrs = new Object(); for (var i=0; i < args.length; i=i+2){ var currArg = args[i].toLowerCase(); switch (currArg){ case "pluginspage": case "type": ret.embedAttrs[args[i]] = args[i+1]; break; case "data": case "codebase": case "classid": case "id": case "onafterupdate": case "onbeforeupdate": case "onblur": case "oncellchange": case "onclick": case "ondblClick": case "ondrag": case "ondragend": case "ondragenter": case "ondragleave": case "ondragover": case "ondrop": case "onfinish": case "onfocus": case "onhelp": case "onmousedown": case "onmouseup": case "onmouseover": case "onmousemove": case "onmouseout": case "onkeypress": case "onkeydown": case "onkeyup": case "onload": case "onlosecapture": case "onpropertychange": case "onreadystatechange": case "onrowsdelete": case "onrowenter": case "onrowexit": case "onrowsinserted": case "onstart": case "onscroll": case "onbeforeeditfocus": case "onactivate": case "onbeforedeactivate": case "ondeactivate": ret.objAttrs[args[i]] = args[i+1]; break; case "width": case "height": case "align": case "vspace": case "hspace": case "class": case "title": case "accesskey": case "name": case "tabindex": ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1]; break; default: ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1]; } } return ret; } AC_RunActiveContent.js Code: var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false; function ControlVersion() { var version; var axo; var e; // NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry try { // version will be set for 7.X or greater players axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"); version = axo.GetVariable("$version"); } catch (e) { } if (!version) { try { // version will be set for 6.X players only axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); // installed player is some revision of 6.0 // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29, // so we have to be careful. // default to the first public version version = "WIN 6,0,21,0"; // throws if AllowScripAccess does not exist (introduced in 6.0r47) axo.AllowScriptAccess = "always"; // safe to call for 6.0r47 or greater version = axo.GetVariable("$version"); } catch (e) { } } if (!version) { try { // version will be set for 4.X or 5.X player axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); version = axo.GetVariable("$version"); } catch (e) { } } if (!version) { try { // version will be set for 3.X player axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); version = "WIN 3,0,18,0"; } catch (e) { } } if (!version) { try { // version will be set for 2.X player axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); version = "WIN 2,0,0,11"; } catch (e) { version = -1; } } return version; } // JavaScript helper required to detect Flash Player PlugIn version information function GetSwfVer(){ // NS/Opera version >= 3 check for Flash plugin in plugin array var flashVer = -1; if (navigator.plugins != null && navigator.plugins.length > 0) { if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) { var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; var descArray = flashDescription.split(" "); var tempArrayMajor = descArray[2].split("."); var versionMajor = tempArrayMajor[0]; var versionMinor = tempArrayMajor[1]; var versionRevision = descArray[3]; if (versionRevision == "") { versionRevision = descArray[4]; } if (versionRevision[0] == "d") { versionRevision = versionRevision.substring(1); } else if (versionRevision[0] == "r") { versionRevision = versionRevision.substring(1); if (versionRevision.indexOf("d") > 0) { versionRevision = versionRevision.substring(0, versionRevision.indexOf("d")); } } var flashVer = versionMajor + "." + versionMinor + "." + versionRevision; } } // MSN/WebTV 2.6 supports Flash 4 else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4; // WebTV 2.5 supports Flash 3 else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3; // older WebTV supports Flash 2 else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2; else if ( isIE && isWin && !isOpera ) { flashVer = ControlVersion(); } return flashVer; } // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) { versionStr = GetSwfVer(); if (versionStr == -1 ) { return false; } else if (versionStr != 0) { if(isIE && isWin && !isOpera) { // Given "WIN 2,0,0,11" tempArray = versionStr.split(" "); // ["WIN", "2,0,0,11"] tempString = tempArray[1]; // "2,0,0,11" versionArray = tempString.split(","); // ['2', '0', '0', '11'] } else { versionArray = versionStr.split("."); } var versionMajor = versionArray[0]; var versionMinor = versionArray[1]; var versionRevision = versionArray[2]; // is the major.revision >= requested major.revision AND the minor version >= requested minor if (versionMajor > parseFloat(reqMajorVer)) { return true; } else if (versionMajor == parseFloat(reqMajorVer)) { if (versionMinor > parseFloat(reqMinorVer)) return true; else if (versionMinor == parseFloat(reqMinorVer)) { if (versionRevision >= parseFloat(reqRevision)) return true; } } return false; } } function AC_AddExtension(src, ext) { if (src.indexOf('?') != -1) return src.replace(/\?/, ext+'?'); else return src + ext; } function AC_Generateobj(objAttrs, params, embedAttrs) { var str = ''; if (isIE && isWin && !isOpera) { str += '<object '; for (var i in objAttrs) { str += i + '="' + objAttrs[i] + '" '; } str += '>'; for (var i in params) { str += '<param name="' + i + '" value="' + params[i] + '" /> '; } str += '</object>'; } else { str += '<embed '; for (var i in embedAttrs) { str += i + '="' + embedAttrs[i] + '" '; } str += '> </embed>'; } document.write(str); } function AC_FL_RunContent(){ var ret = AC_GetArgs ( arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" , "application/x-shockwave-flash" ); AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs); } function AC_SW_RunContent(){ var ret = AC_GetArgs ( arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000" , null ); AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs); } function AC_GetArgs(args, ext, srcParamName, classid, mimeType){ var ret = new Object(); ret.embedAttrs = new Object(); ret.params = new Object(); ret.objAttrs = new Object(); for (var i=0; i < args.length; i=i+2){ var currArg = args[i].toLowerCase(); switch (currArg){ case "classid": break; case "pluginspage": ret.embedAttrs[args[i]] = args[i+1]; break; case "src": case "movie": args[i+1] = AC_AddExtension(args[i+1], ext); ret.embedAttrs["src"] = args[i+1]; ret.params[srcParamName] = args[i+1]; break; case "onafterupdate": case "onbeforeupdate": case "onblur": case "oncellchange": case "onclick": case "ondblClick": case "ondrag": case "ondragend": case "ondragenter": case "ondragleave": case "ondragover": case "ondrop": case "onfinish": case "onfocus": case "onhelp": case "onmousedown": case "onmouseup": case "onmouseover": case "onmousemove": case "onmouseout": case "onkeypress": case "onkeydown": case "onkeyup": case "onload": case "onlosecapture": case "onpropertychange": case "onreadystatechange": case "onrowsdelete": case "onrowenter": case "onrowexit": case "onrowsinserted": case "onstart": case "onscroll": case "onbeforeeditfocus": case "onactivate": case "onbeforedeactivate": case "ondeactivate": case "type": case "codebase": case "id": ret.objAttrs[args[i]] = args[i+1]; break; case "width": case "height": case "align": case "vspace": case "hspace": case "class": case "title": case "accesskey": case "name": case "tabindex": ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1]; break; default: ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1]; } } ret.objAttrs["classid"] = classid; if (mimeType) ret.embedAttrs["type"] = mimeType; return ret; } I need to detect the client IP address and then redirect them to the apporiate page depending on their IP. This is on an Intranet site. Here's what I've been working with: var ip = '<!--#echo var="REMOTE_ADDR"-->'; if (ip == "10.256.85"); { url=("http://www.google.com"); window.location=url;("http://www.google.com"); } This works for the redirect but doesn't check the IP. Thank you! K. Bardolf I wish to change the dynamic text in a javascript to that which is in a MySQL database using PHP. this is then used in a flash scroller. currently i have hard coded the text in the javascript file. is there a way to have PHP run in the javascript file before it is sent to the endusers? or another way ? I am developing a mobile app. I have a script that will read the contents of a csv into an array. It works great, however I am not sure how to take that array and insert it into a db. The following is the script that reads the csv -- function IO(U, V) { var X = !window.XMLHttpRequest ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest; X.open(V ? "PUT" : "GET", U, false); X.setRequestHeader("Content-Type", "text/html"); X.send(V ? V : ""); return X.responseText; } var mycells = IO('data.csv').split(/\n/g).map(function(a){return a.split(/\t/g)} ) I want to insert the array 'mycells' into the db but do not know what the correct syntax would be. t.executeSql('INSERT INTO mytable (name, phone, street, city, state) VALUES (????????????... Thanks for any helps that is sent my way! Hi, The following code is not working whose purpose is to validate the form with javascript. Please Help . Code: <html> <head> <script type='text/javascript'> function formValidator() { // Make quick references to our fields var firstname = document.getElementById('firstname'); var addr = document.getElementById('addr'); var zip = document.getElementById('zip'); var state = document.getElementById('state'); var username = document.getElementById('username'); var password = document.getElementById('passwd'); var email = document.getElementById('email'); var cpassword=document.getElementById('pass2'); var txtar=document.getElementById('ta'); var rad=document.getElementById('r1'); var cbox =document.getElementById('r1'); // Check each input in the order that it appears in the form! if(isAlphabet(firstname, "Please enter only letters for your name")) { if(isAlphanumeric(addr, "Numbers and Letters Only for Address")) { if(isNumeric(zip, "Please enter a valid zip code")) { if(madeSelection(state, "Please Choose a State")) { if(lengthRestriction(username, 6, 8)) { if(plengthRestriction(password,4,6)) { if(confpass(cpassword,"Please confirm")) { if(emailValidator(email, "Please enter a valid email address")) { if(istextareablank(txtar,"Please enter some text")) { if(isradiobuttselected(rad,"Please select any one radio buttons")) { if(ischeckboxselected(cbox,"Please select at least one checkbox")) { return true; } } } } } } } } } } } return false; } function notEmpty(elem, helperMsg){ if(elem.value.length === 0){ alert(helperMsg); elem.focus(); // set the focus to this input return false; } return true; } function isNumeric(elem, helperMsg){ var numericExpression = /^[0-9]+$/; if(elem.value.match(numericExpression)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function isAlphabet(elem, helperMsg){ var alphaExp = /^[a-zA-Z]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function isAlphanumeric(elem, helperMsg){ var alphaExp = /^[0-9a-zA-Z]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function lengthRestriction(elem, min, max) { var uInput = elem.value; if(uInput.length >= min && uInput.length <= max){ return true; }else{ alert("Please enter username between " +min+ " and " +max+ " characters"); elem.focus(); return false; } } function plengthRestriction(elem, min,max) { var uInput = elem.value; if(uInput.length >= min && uInput.length <= max){ return true; }else{ alert("Please enter password between " +min+ " and " +max+ " characters"); elem.focus(); return false; } } function madeSelection(elem, helperMsg){ if(elem.value == "Please Choose"){ alert(helperMsg); elem.focus(); return false; }else{ return true; } } function emailValidator(elem, helperMsg){ var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/; if(elem.value.match(emailExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function confpass(elem,helperMsg) { if ( confPasswd === "" ) { alert("Please fill in the Confirm Password"); document.forms[0].elements[7].focus( ); return false; } else if (document.forms[0].elements[6].value != document.forms[0].elements[7].value) { alert( "Your passwords do not match. Please retype and try again."); return false; } } function isEmpty(s) { return ((s === null) || (s.length === 0)); } function istextareablank(elem,helperMsg){ var i; <!-- Is empty? --> if (isEmpty(s)) return true; <!-- Search through string's' characters one by one until we find a non-whitespace character. --> for (i=0; i < s.length; i++) { <!-- Check that current character isn't' whitespace.--> var currchar = s.charAt(i); if (whitespace.indexOf(currchar) == -1) return false; } <!-- All characters are whitespace. --> return true; } function isradiobuttselected(elem,helperMsg){ <!-- Check to see if atleast one is checkbox checked or not--> for (j=10; j<=11; j++) { if(document.forms[0].elements[j].checked) { break; } else if (j>=11) { alert("Atleast Check on one of the radio buttons"); document.forms[0].elements[j].focus(); return (false); } } return(true); } function ischeckboxselected(elem,helperMsg) { for (j=12; j<=13; j++) { if(document.forms[0].elements[j].checked) { break; } else if (j>=13) { alert("Atleast Check on One of Our Services"); document.forms[0].elements[j].focus(); return (false); } } return(true); } </script> </head> <body> <form onsubmit='return formValidator()' > <br /> First Name: <input type='text' id='firstname' /><br /><br /> Address: <input type='text' id='addr' /><br /><br /> Zip Code: <input type='text' id='zip' /><br /><br /> State: <select id='state'> <option>Please Choose</option> <option>AL</option> <option>KE</option> <option>TX</option> <option>CH</option> </select><br /> Username(6-8 characters): <input type='text' id='username' /><br /><br /> Password(min 4 chars):<input type="password" id='passwd' /> <br/><br /> Confirm Password: <input id="pass2" Type="password" /><br/><br /> Email: <input type='text' id='email' /><br /><br /> Something about Yourself : <textarea name="1" cols="17" rows="4" id="ta"></textarea><br/><br /> Free Membership <input type="radio" id="r1"/> Paid Membership <input type="radio" id="r1"/><br/><br/> Friendship<input type="checkbox" id="box1" /> Networking <input type="checkbox" id="box1" /><br /><br /> <input type='submit' value='Submit' /> </form> </body> </html> Hi, I have an array in JavaScript. How can I GROUPBY Branch, then by Client and then by Referral Type and COUNT DISTINCT LPS # in JavaScript. Please note I need to do this client side using JavaScript. Array Data: Branch Client Referral Type LPS # 402036 402430 Psychological File Review 30 402049 402805 In-Home Assessment 10.87927 402050 402993 Chiropractic Assessment 100 402049 402805 Chiropractic File Review 10.88054 402049 402806 Chiropractic File Review 10.88055 402049 402806 Defense Medical 20 402049 402807 Chiropractic Assessment 10 402049 402807 In-Home Assessment + Form 1 10.88054 402049 402807 Physiotherapy Assessment 10 402049 402808 Attendant Care Assessment 10 402049 402808 Chiropractic Assessment 10.88041 402049 402808 In-Home Assessment 10 402049 402816 Chiropractic Assessment 10.85316 402049 402827 Neurological File Review 10.88047 402049 402827 Social Work File Review 10.88044 402050 402605 Psychological File Review 880434 402050 402661 Physician Assessment 878203 402050 402993 Physician Assessment 1000 402036 402575 Psychological File Review 50 Thanks hi, I have a website which is available on internet and uses lot of javascript code. Someone recently reported a bug and I fixed it in a javascript file. Now I want to move this updated js file on my server. but I am confused, how will this fix now be downloaded on every user's browser when they access website the next time? Is the download to client machine dependent on browser settings? could it be possible that some customer machine has latest file and some do not. How do I force file to download on client machine independent of client browser settings? thank u Hi, I am creating a HTML page and mailing it to the user(client side). This html page contains a Table and a button. On button click, I would like to create another HTML page based on the detail in the table,dynamically on run time and Open the newly created HTML. I need to use javascript to achieve this functionality. I have no Server-Client Configuration. And I need to run the Javscript only on client side to process the First HTML's table data and Create a new HTML page. The output of the javascript should also be put in a table format in the newly created HTML page. Here is some background information: The details from one server would be put into this first HTML along with a button. This HTML page is then mailed to Client side. The javascript in the HTML page then processes the Table data of first HTML. This can only be run at Client Side,once the user clicks the button and moreover I dont have Server-Client Configuration. I am creating a report and mailing it, For formatting purposes and for creating hyperlink to mailid's I chose HTML, Now I am struck here. Could some one please help me out with this. Thanks for your time. I want to know how can i make javascript that i can use by run into in address bar.. I just need such javascript that run through address bar. My purpose is How can i check all check box in webpage that do not include all check or uncheck button? Best common example for check all or uncheck all is Quote: <html> <head> <title>Check All</title> <SCRIPT LANGUAGE="JavaScript"> function checkall(formid) { len=formid.ckb.length for(i=0;i<len;i++) { formid.elements.ckb[i].checked=true } } function uncheckall(formid) { len=formid.ckb.length for(i=0;i<len;i++) { formid.elements.ckb[i].checked=false } } </SCRIPT> </head> <body> <CENTER> <FORM NAME="myform"> <INPUT TYPE="checkbox" NAME="ckb"> Checkbox One <BR> <INPUT TYPE="checkbox" NAME="ckb"> Checkbox Two <BR> <INPUT TYPE="checkbox" NAME="ckb"> Checkbox Three <BR> <INPUT TYPE="button" NAME="chka" VALUE="Check All" onClick="checkall(this.form)"> <INPUT TYPE="button" NAME="unchka" VALUE="Uncheck All" onClick="uncheckall(this.form)"> </FORM> </CENTER> </body> </html> Now for above code If there would not have any javascript for select all then how can i use the select all javascript that i can run through address bar. i.e how can i just check all check box by using javascript? Hi everyone, I have been trawling for useful info for a few hours and still have no definitive answer. There is plenty of info about creating server side javascript which can use php/asp to pull in xml etc and process but there is nothing I could find identifying how to do the same thing but with the javascript being client side only, e.g chrome plugin code. From what I currently understand, javascript client side only cannot reach or ask for any services externally. Am I missing something obvious or just trying to do something impossible? Cheers , Aro Hello. Is the any chance to increment IP address in Javascript ? For example 11.12.13.14 plus 1 will be 11.12.13.15 I've started to modify my old script: Code: var ipa = 10.11.12.13; var partsa = []; var tempa = ipa; for ( var p = 0; p < 3; ++p ) { var dot1t = tempa.indexOf("."); partsa[p] = tempa.substring(0,dot1t); tempa = tempa.substring(dot1t+1); } partsa[3] = tempa; But do not know how to display ip like: ( parts1[0].parts1[1].parts1[2].parts1[3]+1 ) Please help. Leos Hey everyone. I need a little help and I'm not an expert by any stretch of the imagination with javascript. I have a simple little code script and I'd like either the onClick function (or the entire code itself, whichever is easiest) to only load once every 24 hours for each IP address. So "123.1.22.333" should only get the effect of this code once every 24 hours regardless if they revisit my site 5 times a day let's say. So here's my little script: Code: <script language="JavaScript"> function goNewWin() { TheNewWin=window.open("http://google.com",'Google','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1'); TheNewWin.blur(); } </script> <body onClick="goNewWin()"> Any help would be very appreciated. Thanks! Hi Friends, I am facing one problem that screw me left and right. Please share me if anyone of you faced this problem and solved already. I am using the below code to assign the javascript function on select on radio button. This may vary based on radio button selection. For some radio button selection the button will be disabled. if(yes) { document.getElementById("Name").href = "javaScript:functionA()"; document.getElementById("Name").onclick = "javaScript:functionA()"; }else { document.getElementById("Name").href = "#"; } This is the code i am using to activate the button or disable the button. For some causes i am getting "javaScript:functionA()" in the address bar instead of calling that java script method. So my new window is not showing me the correct result. Please some one advise me how to solve this problem. Thanks in advance. Regards, Jeva My source : Code: <html> <head> <title></title> <script type="text/javascript"> function runcode(cwin) { cwin.location.replace("javascript:alert("Loaded complete")"); } function newtab() { win=window.open("http://www.google.com"); setTimeout("runcode(win)",5000); setTiemout("win.close()",7000); } </script> </head> <body> <input type="button" value="Click to open newtab" onclick="newtab()" /> </body> </html> I want after newtab is opened 5s, alert window will be opened with message:"Loaded complete". Then 2s it is closed. But it isn't what I expect. Please fix it for me. Thanks in advance! 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> Let me give an example: javascript: var myvar=10; function myfunc(){}; void(0); After excuting the above js source code in the address bar of my browser, I can use window.myvar and window.myfunc() to access myvar and myfunc. This indicates that the above "address-bar javascript code" must have been stored somewhere in the current page. My question is: where is the "address-bar javascript code" stored in the current page? or equivalently, is it possible to retrieve the "address-bar javascript code" by using some other javascript codes? I checked document.childNodes and document.documentElement, but cannot find the javascript source code. Maybe the source code is stored in the window object? How to retrieve it? Thank you very much for the help! I've literally tried everything. Read 26 tutorials, interchanged code, etc. My validation functions all work. My AJAX functions work (tested manually using servlet URL's). The second servlet validates the reCaptcha form that's generated on my webpage. After the form is validated, even if everything's correct, nothing happens upon clicking submit. I even have an alert pop up if with the captcha result, just for middle-layer debugging purposes. I want to do all of my validation clientside; none serverside. However, going to be tough if I can't get my god damn form to submit. I've been puzzled by this for close to 36 hours straight. I can't see, and I'm going to get some rest and hope that there is some useful insight on my problem when I return. html form: Code: <form id="f1" name="form1" onsubmit="validate_form(this); return false;" action="register" method="post"> <table cellspacing="5" style="border: 2px solid black;"> <tr> <td valign="top"> <table cellspacing="5"> <tr> <td>*First name</td> <td align="right"><span id="valid_one"></span></td> <td><input type="text" style="width: 320px;" id="fn" name="fn" onBlur="validate_one();"></td> </tr> <tr> <td align="left">*Last name</td> <td align="right"><span id="valid_two"></span></td> <td><input type="text" style="width: 320px;" id="ln" name="ln" onBlur="validate_two();"></td> </tr> <tr> <td align="left">*Email address</td> <td align="right"><span id="result"></span></td> <td><input type="text" style="width: 320px;" id="mailfield" name="email" onBlur="startRequest();"></td> </tr> <tr> <td align="left">*Phone number</td> <td align="right"><span id="valid_three"></span></td> <td><input type="text" style="width: 320px;" id="pn" name="pn" onBlur="validate_three();"></td> </tr> <tr> <td align="left">*City/Town</td> <td align="right"><span id="valid_four"></span></td> <td><input type="text" style="width: 320px;" id="c" name="c" onBlur="validate_four();"></td> </tr> <tr> <td></td> <td></td> <td> <select name="s"> <option value="AL">Alabama <option value="AK">Alaska <option value="AZ">Arizona <option value="AR">Arkansas <option value="CA">California <option value="CO">Colorado <option value="CT">Connecticut <option value="DE">Delaware <option value="FL">Florida <option value="GA">Georgia <option value="HI">Hawaii <option value="ID">Idaho <option value="IL">Illinois <option value="IN">Indiana <option value="IA">Iowa <option value="KS">Kansas <option value="KY">Kentucky <option value="LA">Louisiana <option value="ME">Maine <option value="MD">Maryland <option value="MA">Massachusetts <option value="MI">Michigan <option value="MN">Minnesota <option value="MS">Mississippi <option value="MO">Missouri <option value="MT">Montana <option value="NE">Nebraska <option value="NV">Nevada <option value="NH">New Hampshire <option value="NJ">New Jersey <option value="NM">New Mexico <option value="NY">New York <option value="MC">North Carolina <option value="ND">North Dakota <option value="OH">Ohio <option value="OK">Oklahoma <option value="OR">Oregon <option value="PA">Pennsylvania <option value="RI">Rhode Island <option value="SC">South Carolina <option value="SD">South Dakota <option value="TN">Tennessee <option value="TX">Texas <option value="UT">Utah <option value="VT">Vermont <option value="VA">Virginia <option value="WA">Washington <option value="WV">West Virginia <option value="WI">Wisconsin <option value="WY">Wyoming </select> </td> </tr> <tr> <td> <br> </td> </tr> <tr> <td></td> <td></td> <td><span id="error"></span></td> </tr> <tr> <td valign="top">*Anti-Spam Verification</td> <td></td> <td id="reCaptcha"></td> </tr> </table> </td> <td valign="top"> <table cellspacing="5"> <tr> <td align="left">*Affiliation</td> <td align="right"><span id="valid_five"></span></td> <td><input type="text" style="width: 320px;" id="affl" name="affl" onBlur="validate_five();"></td> </tr> <tr> <td align="left">*Research Area:</td> <td align="right"><span id="valid_six"></span></td> <td><input type="text" style="width: 320px;" id="ra" name="ra" onBlur="validate_six();"></td> </tr> <tr> <td valign="top" align="left">*Research Overview</td> <td align="right"><span id="valid_seven"></span></td> <td><textarea cols="38" rows="6" id="ro" name="ro" onKeyDown="limitText(this.form.ro,this.form.countdown,500)" onKeyUp="limitText(this.form.ro,this.form.countdown,500)" onBlur="validate_seven();"></textarea></td> </tr> <tr> <td></td> <td></td> <td><font size="1">You have <input readonly type="text" name="countdown" size="1" value="500"> characters remaining.</font></td> </tr> <tr> <td align="left">*Talk Availability</td> <td></td> <td> <input type="radio" name="ta" value="In person">In person <input type="radio" name="ta" value="Online">Online <input type="radio" name="ta" value="Both" checked>Both </td> </tr> <tr> <td align="left" valign="top">Links</td> <td></td> <td> <table id="linkTable" border="0"> <td><input type="text" style="width: 320px;" name="link"></td> <td><div id="result"></div></td> </table> </td> <td align="left" valign="top"><input type="button" value="Add Link" onclick="addLink('linkTable')"></td> </tr> <tr> <td></td> <td><span style="color: red;"></span></td> </tr> </table> </td> </tr> </table> <br /> <input type="submit" id="submit" name="submit" value="Submit Form"> </form> Javascript file: Code: /* * script.js - ajax and table functions */ var xmlHttp; // global instance of XMLHttpRequest var xmlHttp2; // second for captcha functions var validAjax = new Boolean(); var validCaptcha = new Boolean(); var valid_one = new Boolean(); var valid_two = new Boolean(); var valid_three = new Boolean(); var valid_four = new Boolean(); var valid_five = new Boolean(); var valid_six = new Boolean(); var valid_seven = new Boolean(); function init() { showRecaptcha('reCaptcha'); // Separate booleans for AJAX funcs validAjax = false; validCaptcha = false; // Booleanse for fields that don't require servlet validation valid_one = false; valid_two = false; valid_three = false; valid_four = false; valid_five = false; valid_six = false; valid_seven = false; } function showRecaptcha(element) { Recaptcha.create("6Le1a8ESAAAAAGtxX0miZ2bMg0Wymltnth7IG-Mj", element, {theme: "red", callback: Recaptcha.focus_response_field}); } function validate_form() { if (valid_one && valid_two && valid_three && valid_four && validEmail) { startCaptchaRequest(); if (validCaptcha) { return true; } } else { alert("Submission contains errors. Please fill out all required fields before submitting."); return false; } } function validate_one() { if (document.getElementById("fn").value == 0) { valid_one = false; document.getElementById("valid_one").innerHTML = "No"; } else { valid_one = true; document.getElementById("valid_one").innerHTML = ""; } } function validate_two() { if (document.getElementById("ln").value == 0) { valid_two = false; document.getElementById("valid_two").innerHTML = "No"; } else { valid_two = true; document.getElementById("valid_two").innerHTML = ""; } } function validate_three() { if (document.getElementById("pn").value == 0) { valid_three = false; document.getElementById("valid_three").innerHTML = "No"; } else { valid_three = true; document.getElementById("valid_three").innerHTML = ""; } } function validate_four() { if (document.getElementById("c").value == 0) { valid_four = false; document.getElementById("valid_four").innerHTML = "No"; } else { valid_four = true; document.getElementById("valid_four").innerHTML = ""; } } function validate_five() { if (document.getElementById("affl").value == 0) { valid_five = false; document.getElementById("valid_five").innerHTML = "No"; } else { valid_five = true; document.getElementById("valid_five").innerHTML = ""; } } // //function validate_six() { // if (document.getElementById("ra").value == 0) { // valid_six = false; // document.getElementById("valid_six").innerHTML = "No"; // } // else { // valid_six = true; // document.getElementById("valid_six").innerHTML = ""; // } //} // //function validate_seven() { // if (document.getElementById("ro").value == 0) { // valid_seven = false; // document.getElementById("valid_seven").innerHTML = "No"; // } // else { // valid_seven = true; // document.getElementById("valid_seven").innerHTML = ""; // } //} function addLink(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "text"; element1.name = "link" + rowCount; element1.style.width = "320px"; cell.appendChild(element1); } function limitText(limitField, limitCount, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } else { limitCount.value = limitNum - limitField.value.length; } } function createXmlHttpRequest() { if(window.ActiveXObject) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp=new XMLHttpRequest(); } } function startRequest() { createXmlHttpRequest(); var param1 = document.getElementById('mailfield').value; if (param1 == "") { validEmail = false; document.getElementById("result").innerHTML = "Blank"; } else { xmlHttp.open("GET", "http://localhost:1979/PolarSpeakers/servlet/mailCheck.do?e=" + param1, true) xmlHttp.onreadystatechange = handleStateChange; xmlHttp.send(null); } } function handleStateChange() { if(xmlHttp.readyState==4) { if(xmlHttp.status==200) { var message = xmlHttp.responseXML .getElementsByTagName("valid")[0] .childNodes[0].nodeValue; if (message == "Unregistered") { validEmail = true; document.getElementById("result").style.color = "green"; } else { validEmail = false; document.getElementById("result").style.color = "red"; } document.getElementById("result").innerHTML = message; } else { alert("Error checking e-mail address - " + xmlHttp.status + " : " + xmlHttp.statusText); } } } function createCaptchaRequest() { if(window.ActiveXObject) { xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp2=new XMLHttpRequest(); } } function startCaptchaRequest() { alert('made it to captcha requeswt'); createCaptchaRequest(); var param1 = Recaptcha.get_challenge(); var param2 = Recaptcha.get_response(); xmlHttp2.open("POST", "http://localhost:1979/PolarSpeakers/servlet/captchaCheck.do?c=" + param1 + "&r=" + param2, true) xmlHttp2.onreadystatechange = handleStateChangeCaptcha; xmlHttp2.send(null); } function handleStateChangeCaptcha() { if(xmlHttp2.readyState==4) { if(xmlHttp2.status==200) { var message = xmlHttp2.responseXML .getElementsByTagName("result")[0] .childNodes[0].nodeValue; if (message == "Valid") { alert("captcha valid"); validCaptcha = true; } else { document.getElementById("error").innerHTML = message; validCaptcha = false; } } else { alert("Error checking captcha validity - " + xmlHttp2.status + " : " + xmlHttp2.statusText); } } } Hi people, I need help as follows: On the server side I have a php generated session parameter. I need to pass it to javascript on the client side page. I saw on the web the following solution: <script language="JavaScript"> var mySessionVar="<%= Session["MySessionVar"] %>"; </script> I tried it but it did not work. I could not find any explanation of this syntax - will appreciate one. Any suggestions, maybe in another way? Thanks Hey guys. Didnt know what forum to put this in, but i figured i would put it here. Basically im making an ajax chat client. I dont know if anyone here as ever looked at googles chat client code, but if anyone knows how to make one function the same way as it, I would love if you would help me figure it out. I tried making a chat client, but it ended up being slow, buggy, and you couldnt select text because the innerhtml was refresshing so much. So how can I make a good chat client like googles? Thanks! Hello, I have two problems. Firstly I am trying to make a form with client side validation but I have come across a problem. I need to validate the whole form under just one button but for validating email and phone number I have two different buttons and I am not sure how to make all the code run under just one button when it is submitted. The second problem is with validating the phone number. I am sure the code and javascript is fine, but for some reason it will not work. Here is my code: HTML 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"/> <script type="text/javascript" src="client_validation.js" /> </script> <link rel="stylesheet" type="text/css" href="Client validation.css" /> <title> Client Validation </title> </head> <body> <form name="contact_form" method="post" action="submit" onsubmit="return validate_form ( );"> <h3><strong>Client Validation</strong></h3> <p>Your Name: <input type="text" name="text1"></p> <p>Your Last Name: <input type="text" name="text2"></p> <p>Email: <input type="text" id="email" name="text3"></p> <p>Phone: <input type="text" name="text4"></p> <p>Address: <textarea cols="20" rows="5" name="text5"></textarea></p> <p>Do you agree to the Terms and Conditions? <input type="checkbox" name="text6" value="Yes"> Yes <p><input type="submit" name="send" value="Send Details"></p> </form> Your Email: <form id="form_id" method="post" action="action.php" onsubmit="javascript:return validate('form_id','email');"> <input type="text" id="email" name="email" /> <input type="submit" value="Submit" /> <form method="post" action="data.php" name="form1"> <p>Enter Number <input type="text" name="phoneNo"></p> <input type="button" name="btn1" value="submit" onClick="CheckNumber()"> </body> </html> JAVASCRIPT Code: function validate_form ( ) { valid = true; if ( document.contact_form.text1.value == "" ) { alert ( "Please fill in the 'Your First Name' box." ); valid = false; } if ( document.contact_form.text2.value == "" ) { alert ( "Please fill in the 'Your Last Name' box." ); valid = false; } if ( document.contact_form.text5.value == "" ) { alert ( "Please fill in your address." ); valid = false; } if ( document.contact_form.text6.checked == false ) { alert ( "Please check the Terms & Conditions box." ); valid = false; } return valid; } function validate(form_id,email) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var address = document.forms[form_id].elements[email].value; if(reg.test(address) == false) { alert('Invalid Email Address'); return false; } } function CheckNumber() { var PhoneNumber=document.form1.phoneNo.value; for (var i=0; i<PhoneNumber.length; i++) { var c=PhoneNumber.charAt(i); if (!(c>0 || c<9)){ alert("This is not a valid Phone Number"); break; } } } I hope you guys can help. Thank you |