JavaScript - Why Doesn't This Work? (short Script)
I'm trying to resolve a UPS zone from a zip code, here is my code:
Code: <script type="text/javascript"> var zipcode=44657;<!-- Should be zone 5 --> var zip=zipcode.substring(0,3); alert(zip); <!-- Zone chart made from Jacksonville FL zip 32216 on 8-5-2010 --> var azone = new Array (4-5, 5, 6-7, 45, 9, 45, 10-13, 5, 14, 6, 15-18, 5, 19, 6, 20-29, 5, 30-33, 6, 34, 5, 35-51, 6, 52-53, 5, 54, 6, 55, 5, 56-59, 6, 60-89, 5, 100-128, 5, 129, 6, 130-223, 5, 224-225, 4, 226, 5, 227-253, 4, 254, 5, 255-259, 4, 260-261, 5, 262, 4, 263-265, 5, 266, 4, 267, 5, 268-289, 4, 290-296, 3, 297, 4, 298, 3, 299, 2, 300-306, 3, 307, 4, 308-312, 3, 313-316, 2, 317-319, 3, 320-323, 2, 324, 3, 325, 4, 326-329, 2, 330-332, 4, 333-337, 3, 338, 2, 339, 3, 341, 3, 342, 3, 344, 2, 346, 3, 347, 2, 349, 3, 350-359, 4, 360-361, 3, 362, 4, 363-364, 3, 365-367, 4, 368, 3, 369-397, 4, 398, 3, 399, 3, 400-409, 4, 410, 5, 411-418, 4, 420, 5, 421-427, 4, 430-470, 5, 471, 4, 472-475, 5, 476-477, 4, 478-496, 5, 497-505, 6, 506-507, 5, 508-516, 6, 520, 5, 521, 6, 522-539, 5, 540-566, 6, 567, 7, 570-575, 6, 576-577, 7, 580-581, 6, 582, 593, 7, 594-599, 8, 600-668, 5, 669-672, 6, 673, 5, 674-692, 6, 693, 7, 700-704, 4, 705-706, 5, 707-709, 4, 710-722, 5, 723, 4, 724-735, 5, 736, 6, 737, 5, 738-739, 6, 740-768, 5, 769, 6, 770-784, 5, 785, 6, 786-787, 5, 788, 6, 789, 5, 790-797, 6, 798-806, 7, 807, 6, 808-820, 7, 821, 8, 822-831, 7, 832-844, 8, 845-846, 7, 847, 8, 850-853, 7, 854, 8, 855-863, 7, 864, 8, 865-875, 7, 877, 6, 878-880, 7, 881-882, 6, 883, 7, 884, 6, 885, 7, 889-961, 8, 970-986, 8, 988-994, 8); for (y=0;azone[y]=zip;y=y+2){ document.write (azone[y+1]) } </script> Can someone see my error? I'm a bit rusty at my javascript. Similar Tutorialshello... script doesn't work.. it does work in IE but not in another browser like mozilla,opera & safari? what should I do?.. Code: //Current HTML of page var html=""; //View of the page, Normal (Design), HTML, Preview var currentview=0; //Hold window objects for the color, table and properties dialogs var table_dialog, color_dialog, properties_dialog; //Current color action, ForeColor, or BackColor, //used for communication between PageCreate window and Color dialog window var pp; //Is used to disable use of design tools in HTML or Preview mode var enabletoolbar=false; //Variable counter used to index the search in the document var n=0; function InitEditor(){ //Init editor in design mode, maineditor.document.designMode=docmode; //Write a blank page WriteDefaultPage(); //Disable context menu maineditor.document.oncontextmenu=new Function("return false;"); //Set focus to the editor maineditor.focus(); } function EditorView(view){ //Changes editor view to Normal, HTML, and Preview if(currentview==1){ //If the last view was HTML then get the HTML edited by user in HTML mode html=maineditor.document.body.innerText; } //If the last mode was Normal then get the whole HTML content of the page else html=maineditor.document.all.tags("HTML")[0].outerHTML; if(view==0){ //Normal Mode EnableToolbar(true); maineditor.location="about:blank"; maineditor.document.designMode=docmode; maineditor.document.open("text/html"); maineditor.document.write(html); maineditor.document.close(); maineditor.document.oncontextmenu=new Function("return false;"); maineditor.focus(); } if(view==1){ //HTML Mode EnableToolbar(false); maineditor.location="about:blank"; maineditor.document.designMode=docmode; WriteDefaultPage(); HTMLView(); maineditor.document.oncontextmenu=new Function("return false;"); } if(view==2){ //Preview Mode EnableToolbar(false); maineditor.location="about:blank"; //Disable page editing maineditor.document.designMode="Inherit"; //Write the HTML of the page maineditor.document.open("text/html"); maineditor.document.write(html); maineditor.document.close(); //Enable context menu maineditor.document.oncontextmenu=new Function("return true;"); } //Set current view currentview=view; } function EnableToolbar(enable){ //Enable or disable toolbar enabletoolbar=enable; } function OpenFile(){ if(window.confirm("Do you want to save changes in the current document?")){ //Show Save As Dialog maineditor.document.execCommand("SaveAs"); } fileopen_dialog.style.visibility="visible"; } function OpenSelectedFile(){ //Check if the file is an HTML page if(document.fileselect.thefile.value.indexOf(".htm")==-1){ window.alert("The selected file is not an HTML page, please select a valid HTML file"); return; } //Hide the open file dialog fileopen_dialog.style.visibility="hidden"; //Create the FSO object var fso=new ActiveXObject("Scripting.FileSystemObject"); //Open the selected file var f=fso.OpenTextFile(document.fileselect.thefile.value); //Get the content of the file var thehtml=f.ReadAll(); //Close the file f.close(); //Write a blank page maineditor.window.location="about:blank"; //Write the HTML content maineditor.document.open("text/html"); maineditor.document.write(thehtml); maineditor.document.close(); //Set focus to editor maineditor.focus(); } function WriteDefaultPage(){ //Writes a blank HTML page in the editor var pagehtml="<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; " + "charset=windows-1252\">\n<meta name=\"GENERATOR\" content=\"PageCreate\">\n" + "<title>New Page</title>\n</head>\n<body>\n</body>\n</html>"; maineditor.document.open("text/html"); maineditor.document.write(pagehtml); maineditor.document.close(); } function NewPage(){ if(window.confirm("Do you want to save changes in the current document?")){ //Show Save As Dialog maineditor.document.execCommand("SaveAs"); } //Write a blank page maineditor.window.location="about:blank"; WriteDefaultPage(); //Set focus to editor maineditor.focus(); } function HTMLView(){ //Switch to HTML view maineditor.document.body.innerHTML=""; maineditor.document.body.innerText=html; } function TableOn(table, on){ //Highlights the table on which the mouse is over if(on) table.style.backgroundColor="#95AFFF"; else table.style.backgroundColor="#82DF82"; } function ToolbarOn(toolon){ //Highlights on or off the current toolbar //Get the toolbar button on which the mouse is over var tool=event.srcElement; //Change background color if(toolon){ tool.style.backgroundColor="#B4A0FE"; tool.style.borderColor="#000000"; } else{ tool.style.backgroundColor="#D1D1D1"; tool.style.borderColor="#D1D1D1"; } } function FindInPage(showdialog){ //Shows the Find and Replace Dialog var display="visible"; if(showdialog==false) display="hidden"; find_dialog.style.visibility=display; if(showdialog!=false) document.find.findwhat.focus(); } function FindIt(str, replacestr, newstr){ //This functions searchs for a string in the document //and if specified then replaces it with a new string if(str==""){ //If no string to search entered alert("Enter a string to search"); document.find.findwhat.focus(); return; } //Creates a range in the document txt = maineditor.document.body.createTextRange(); //Loop to find the string in the document for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) { txt.moveStart("character", 1); txt.moveEnd("textedit"); } if(found) { //If founded select it and scroll into view txt.moveStart("character", -1); txt.findText(str); //If replace is specified then replace the match with the new string if(replacestr) txt.text=newstr; txt.select(); txt.scrollIntoView(); n++; } else { if (n > 0) { window.alert("There are no more matches"); n=0; } // Not found anywhere, give message. else window.alert("\"" + str + "\" was not founded in document"); } } function InsertHTML(newhtml){ //Inserts HTML in the selection of the document maineditor.focus(); var selpoint=maineditor.document.selection.createRange(); selpoint.pasteHTML(newhtml); } function GetSelectedText(){ //Get the selection of the document maineditor.focus(); var selpoint=maineditor.document.selection.createRange(); var seltext=selpoint.text; return seltext; } function InsertNewImage(){ if(enabletoolbar==false) return; maineditor.focus(); //Open Insert Image Dialog maineditor.document.execCommand("insertimage", true, null); } function InsertForm(){ //Creates a new form var formmethod=window.prompt("Choose form method: GET | POST", "POST"); var formaction=window.prompt("Choose form action:", "http://"); InsertHTML("<div style=\"background-Color:#C0C0C0\"><form method=\"" + formmethod + "\" action=\"" + formaction + "\">\n<p> </p></form></div>"); } function InsertFormControl(control){ maineditor.focus(); //Inserts a form control maineditor.document.execCommand(control, true, null); } function CreateNewLink(){ //Inserts a link in the selected text if(enabletoolbar==false) return; var linktext=GetSelectedText(); if(linktext=="") return; var url=window.prompt("Enter a URL for the new link:", "http://"); if(url!=null){ InsertHTML("<a href=\"" + url + "\">" + linktext + "</a>"); } maineditor.focus(); } function InsertTable(){ //Open Table Dialog table_dialog=window.open("table.htm", "newtable", "top=100,left=100,height=300,width=400,scrollbars=no"); } function CreateTable(tr, tc, ta, tb, tp, ts, tw, tt){ //Creates a new table var tablewidth=""; if(tw!=""){ tablewidth=" width=\"" + tw + tt + "\""; } var thtml="<table border=\"" + tb + "\" cellpadding=\"" + tp + "\" cellspacing=\"" + ts + "\"" + tablewidth + ">"; tr=parseInt(tr); tc=parseInt(tc); for(r=0;r<tr;r++){ thtml+="<tr>"; for(c=0;c<tc;c++){ thtml+="<td></td>"; } thtml+="</tr>"; } thtml+="</table>"; InsertHTML(thtml); table_dialog.close(); } function EditPage(){ properties_dialog=window.open("properties.htm", "editpage", "top=100,left=100,height=275,width=387,scrollbars=no"); } function EditPageProperties(pt, pfc, pbgc, pbgi, usewatermark, pbgs){ maineditor.document.title=pt; maineditor.document.body.text=pfc; maineditor.document.body.bgColor=pbgc; maineditor.document.body.background=pbgi; if(usewatermark) maineditor.document.body.bgProperties="fixed"; else maineditor.document.body.bgProperties=""; if(pbgs!=""){ var pagehtml=maineditor.document.all.tags("HTML")[0].outerHTML; var bodytag= pagehtml.toLowerCase().indexOf("<body"); if(bodytag==-1) return; var beforebodytag= pagehtml.substring(0, bodytag); var afterbodytag= pagehtml.substring(bodytag, pagehtml.length); var pagehtml=beforebodytag + "<bgsound src=\"" + pbgs + "\">" + afterbodytag; maineditor.document.open("text/html"); maineditor.document.write(pagehtml); maineditor.document.close(); } properties_dialog.close(); maineditor.focus(); } function ChangeForeColor(){ //Show the Color dialog to edit Fore Color of text selected if(GetSelectedText()!=""){ pp="EditForeColor"; color_dialog=window.open("color.htm", "colorpicker", "top=100,left=100,height=270,width=500,scrollbars=no"); } } function EditForeColor(thecolor){ maineditor.focus(); //Change fore color of text selected maineditor.document.execCommand("forecolor", false, thecolor); //Close Color Dialog color_dialog.close(); } function ChangeBackColor(){ //Show the Color dialog to edit Back Color of text selected if(GetSelectedText()!=""){ pp="EditBackColor"; color_dialog=window.open("color.htm?p=EditBackColor", "colorpicker", "top=100,left=100,height=270,width=500,scrollbars=no"); } } function EditBackColor(thecolor){ maineditor.focus(); //Change back color of text selected maineditor.document.execCommand("backcolor", false, thecolor); //Close Color Dialog color_dialog.close(); } function ChangeFont(font){ //Changes the font of the selected text maineditor.focus(); maineditor.document.execCommand("fontname", false, font); } function ChangeFontSize(size){ //Changes the font size of the selected text maineditor.focus(); maineditor.document.execCommand("fontsize", false, size); } function DesignTools(tool){ //Activates design tool if(enabletoolbar==false){ window.alert("You must switch into normal view to do this"); return; } maineditor.focus(); maineditor.document.execCommand(tool, true, null); } Hi all, firstly i'm not a coder but i am capable of doing as instructed. I have some script that when used in conjunction with a button highlights all the text between 2 tags to make it easier for copying, it works great in IE but doesn't work in firefox, could someone help please? Here's the script and the button is below. Code: <script type="text/javascript"> function selectCode(a) { // Get ID of code block var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0]; // Not IE if (window.getSelection) { var s = window.getSelection(); // Safari if (s.setBaseAndExtent) { s.setBaseAndExtent(e, 0, e, e.innerText.length - 1); } // Firefox and Opera else { var r = document.createRange(); r.selectNodeContents(e); s.removeAllRanges(); s.addRange(r); } } // Some older browsers else if (document.getSelection) { var s = document.getSelection(); var r = document.createRange(); r.selectNodeContents(e); s.removeAllRanges(); s.addRange(r); } // IE else if (document.selection) { var r = document.body.createTextRange(); r.moveToElementText(e); r.select(); } } </script> Html button Code: <input type="button" value="Highlight Code" onclick="selectCode(this); return false;"> I would like to add a submenu that pops up when the mouse moves over the first-level menu option. I succesfully added the submenu. However, now the image-swap script (the script that makes that the image that you see change as you move your mouse on the image) doesn't work anymore. Does anyone have any idea what I'm doing wrong? The relevant part of the header: Code: <script type="text/JavaScript"> <!-- function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </script> #nav, #nav ul { /* all lists */ padding: 0; margin: 0; list-style: none; float : left; width : 20.35em; } #nav li { /* all list items */ position : relative; float : left; line-height : 0em; margin-bottom : -1px; width: 11em; } #nav li ul { /* second-level lists */ position : absolute; left: -999em; margin-left : 18.35em; margin-top : -1.35em; } #nav li a { width : 10em; display : block; color : none; font-weight : bold; text-decoration : none; background-color : none; padding : 0 0.5em; } #nav li a:hover { color : none; background-color : none; } #nav li:hover ul ul, #nav li:hover ul ul ul, #nav li.sfhover ul ul, #nav li.sfhover ul ul ul { left: -999em; } #nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul, #nav li li li.sfhover ul { /* lists nested under hovered list items */ left: auto; } #content { margin-left : 12em; } --> </style> <script type="text/javascript"><!--//--><![CDATA[//><!-- sfHover = function() { var sfEls = document.getElementById("nav").getElementsByTagName("LI"); for (var i=0; i<sfEls.length; i++) { sfEls[i].onmouseover=function() { this.className+=" sfhover"; } sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } } } if (window.attachEvent) window.attachEvent("onload", sfHover); //--><!]]></script> The relevant part of the body code: Code: <table width="314" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="315"><div align="center"><a href="ob.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image10','','afbeeldingen/menuob2.gif',1)"><img src="afbeeldingen/spacer.gif" alt="spacer" width="5" height="10" hspace="0" vspace="0" border="0" /><br /> <img src="afbeeldingen/menuob1.gif" alt="OB" name="Image10" width="309" height="27" border="0" id="Image10" /></a><br /> <a href="MS.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image11','','afbeeldingen/menums2.gif',1)"><img src="afbeeldingen/menums1.gif" alt="MS" name="Image11" width="309" height="27" vspace="3" border="0" id="Image11" /></a><br /> <a href="kt.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image12','','afbeeldingen/menukt2.gif',1)"><img src="afbeeldingen/menukt1.gif" alt="KT" name="Image12" width="309" height="27" border="0" id="Image12" /></a> <a href="contact.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image15','','afbeeldingen/menucontact2.gif',1)"><img src="afbeeldingen/menucontact1.gif" alt="Contact" name="Image15" width="309" height="27" vspace="3" border="0" id="Image15" /><br /></a> </div></td> </tr> </table> <ul id="nav"> <li> <a href="MS.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image11','','afbeeldingen/menums2.gif',1)"><img src="afbeeldingen/menums1.gif" alt="MS" name="Image11" width="309" height="27" vspace="3" border="0" id="Image11" /></a><br /> <ul> <li> <a href="aa.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image11','','afbeeldingen/menuaa2.gif',1)"><img src="afbeeldingen/menuaa1.gif" alt="AA" name="Image11" width="309" height="27" vspace="3" border="0" id="Image11" /></a><br /> </li> <li> <a href="bb.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image11','','afbeeldingen/menubb2.gif',1)"><img src="afbeeldingen/menubb1.gif" alt="BB" name="Image11" width="309" height="27" vspace="3" border="0" id="Image11" /></a><br /> </li> <li> <a href="cc.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image11','','afbeeldingen/menucc2.gif',1)"><img src="afbeeldingen/menucc1.gif" alt="CC" name="Image11" width="309" height="27" vspace="3" border="0" id="Image11" /></a><br /> </li> </ul></li></ul> Hi, I am a new poster here and new to javascript as well. I made a script in which if a user enters the correct coupon code, he will be directed to a confirmation page. If not an alert box will say the coupon code was wrong. It sounded simple enough and it worked for sometime. Here is what the code looks like: Code: //in the head section function isGood(elem, helperMsg){ var pass = "x1y2"; if(elem.value==pass){ location.href="./couponbuy.html"; return true;} else{ alert(helperMsg); elem.focus(); return false;} } //in the body section <form> Please Enter Coupon Code: <input type='text' id='code'/> <input type='button' onclick="isGood(document.getElementById('code'), 'Please enter a valid coupon code')" value='Enter' /> </form> As I mentioned, it was working originally, but now it only works when I change the variable 'pass' to something different. I want to be able to keep the variable the same. I don't understand what exactly is going on here. I appreciate any and all help. Thanks. I find the following detect Internet connection script unreliable. Can someone tell me what I should change to make it work consistently? To sum up, the code detects an image on a server and checks its size. If it's size is less than zero, then "Off" appears in a form input field. Otherwise, "On" appears in the field. This code is being used in a smartphone to test for Internet connection. Code: <form id="formConnection"> <input id="connectionStatus" class="display2" size="1" type="text" name="status" value=""> </form> <!-- testConnectionInApp.png is a 126-byte 10x10px PNG image. --> <script type="text/javascript"> function showOn(form) { form.elements.status.value = "On"; } function showOff(form) { form.elements.status.value = "Off"; } function testConnection() { var checkExistenceOfImg = new Image(); var form = document.getElementById('formConnection'); checkExistenceOfImg.src = "http://aedownloads.com/misc/testConnectionInApp.png"; if(checkExistenceOfImg.height > 0) { showOn(form); } else { showOff(form); } } </script> </body> </html> This is a script which has a window slide down on the page and a user can choose yes/no to continue. It works in all browsers other than IE...any help please? If you need more info, please let me know. Thanks. <script language="JavaScript" type="text/javascript"> <!-- var allowpop=1; function popWin(){ var ppl="popLayer";var objppl=findObj(ppl); if (objppl==null){return;}// if the layer does not exist, do nothing. var args=arguments,movetoX=parseInt(args[0]),movetoY=parseInt(args[1]),movespeed=parseInt(args[2]); var cycle=10,pxl=""; if(!document.layers){objppl=objppl.style;} if(objppl.tmofn!=null){clearTimeout(objppl.tmofn);} var pplcoordX=parseInt(objppl.left),pplcoordY=parseInt(objppl.top); var xX=movetoX,yY=movetoY;if((pplcoordX!=movetoX)||(pplcoordY!=movetoY)){ var moveX=((movetoX-pplcoordX)/movespeed),moveY=((movetoY-pplcoordY)/movespeed); moveX=(moveX>0)?Math.ceil(moveX):Math.floor(moveX);movetoX=pplcoordX+moveX; moveY=(moveY>0)?Math.ceil(moveY):Math.floor(moveY);movetoY=pplcoordY+moveY; if((parseInt(navigator.appVersion)>4||navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera)) {pxl="px";} if (moveX!=0){eval("objppl.left='" + movetoX + pxl + "'");} if (moveY != 0) {eval("objppl.top = '" + movetoY + pxl + "'");} var sFunction = "popWin(" + xX + "," + yY + "," + movespeed+ ")"; objppl.tmofn = setTimeout(sFunction,cycle); } } function findObj(theObj, theDoc){ var p, i, foundObj; if(!theDoc) theDoc = document; if((p = theObj.indexOf("?")) > 0 && parent.frames.length) {theDoc = parent.frames[theObj.substring(p+1)].document; theObj = theObj.substring(0,p);} if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj]; for (i=0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj]; for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) foundObj = findObj(theObj,theDoc.layers[i].document); if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj); return foundObj; } function hideLayer(layername){ layer=findObj(layername); if(layer.style){layer=layer.style;} layer.visibility='hidden'; } // --> </script> I have a few tabs on my website. They're each set to the corresponding id in the JS file. It's supposed to add #tab-1 to the end of the URL in the users browser when it's clicked. For example, when a user is at mypage.com and they click on the tab, it ads mypage.com/#tab-1 to the end. How come it doesn't do what I want when I click it though? Here's an example of how it's setup. HTML: <a href="#tab-1" id="tab1">Text</a> JavaScript: document.getElementById("tab1").onclick = function(){ this.href += "#tab-1"; } Hi! What am doing wrong? The script works -- identifies blank fields -- but the second function (change_subject) is ignored. This is the script: Code: <HEAD> <script> function is_filled() { if (form_1.realname.value=="") { alert("Please enter your name") form_1.realname.focus() return false } if (form_1.subject.value=="") { alert("Please enter a subject") form_1.message.focus() return false } else return true }; function change_subject { form_1.subject.value="form_1.realname.value + '_' + form_1.subject.value" }; </script> </HEAD> This is the FORM (used for MSA FormMail): Code: <form name="form_1"; onSubmit="return is_filled()"; on Submit="change_subject()"; method="post"; action="http://gb2gf.org/cgi-sys/FormMail.cgi"> <input type="hidden" name="recipient" value="drt@gb2gf.org"> <input type="hidden" name="required" value="greeting,realname,city_state,email_1,email_2,message"> <input type="hidden" name="sort" value="order:greeting,realname,city_state,email_1,email_2,message"> <input type="hidden" name="redirect" value="http://www.gb2gf.org/thanks.htm"> <!-- Input fields here --> </form> Thanks! Dr. T. Code: <html> <head> <script> function color() { var newColor=new Array('#00f','#f00','#ff0'); var i=0; for (i=0;i<=3;i++) { document.getElementByTagName(span).style.display=newColor[i]; } } color(); </script> <div> <span>make this text blue</span> <span>make this text red</span> <span>make this text yellow</span> </div> </body> </html> It should make the first blue, second red, and third yellow yes? Heya, I wrote the following page in a day or two (please don't mind the layout). Everything seems to work excellent, apart from in Firefox (FF) in which it doesn't seem to work at all. None of the other browsers have any trouble with it. I'm pretty new to Javascript (everything you see in the source code is pretty much all I know) and I have absolutely no idea why it doesn't work in Firefox. The page in question could be found [link has been removed]. It's all there is to it. So yeah, how to actually make this work in FF? Thanks a whole bunch in advance! Much appreciated. Below is code using the onmouseover event, but it doesn't work. The only thing that appears in the status bar is the URL. What am I doing wrong? Code: <a href="http://codingforums.com" onmouseover="window.status='This is an OnMouseOver event'; return true" onmouseout="window.status=' '; return true">Put your mouse here to see status info change at bottom.</a> Hi! I'm new to JavaScript and I've done some small adjustments to my clients site, but it won't show properly in IE (the shadowbox js at least.). I thought js was accepted in all newer browsers. Do you have a quick fix or idea on why it doesn't work? You can view source on my site, I use mootools, and shadowbox/corners and rightclick blocker. Is it generally a 'bad thing' to use js in webpages I want everyone to view in the same way? I tried the same effects with CSS but it's not supported in the same way corss-browser, unfortunately. The 'no selection' CSS class I have on the site is also not accepted in IE. It's very annoying! http://santinacrolla.ihaarr.com/p thank you in advance! I've got a form textarea on my site, which after being submitted is stripped by my php file. Then my javascript kicks in and does some analysis of the entered text. However everytime the user entered a hard return within the textarea my javascript gives me an error 'tekenreeks niet afgesloten' which means something like 'string is not closed'. Therefore I decided to replace all occurences of chr(10) and chr(13) with ok2 (just some random characters), I did this with php which worked fine, and I didn't get the javascript error. However I need to reshow the entered text (original) to the user, so I need to restore the old values. I tried Code: result.waarde.replace('ok2', 'chr(13)'); but it doesn't work, as it still displays ok2. I'm no expert in javascript, but how can I replace those characters by the hard returns? Oh yeah I'll show some more coding, perhaps the error can be found the Code: result.waarde.replace('mdw', 'chr(13)');container.innerHTML = result.waarde; and in my html: Code: <div id='waarde' style="width:500px;"></div> Hello, I'm trying to combine two different jQuery scripts on my webpage. The one is showing flashvideos in a lightbox and the other one is displaying thumbnails in a slideshow. The problem is that only one script is working. I have searched the web and forums and found that several people have had this problem before and I have truly tried to fix it with noConflict(). The problem is that I have very little experience in Javascript so I haven't got it working. So, here are the lines in the code: <!-- Video lightbox --> <script type="text/javascript" src="/js/videolightbox/mootools.js"></script> <script type="text/javascript" src="/js/videolightbox/swfobject.js"></script> <script type="text/javascript" src="/js/videolightbox/videobox.js"></script> <!-- Thumbnail slider --> <script type="text/javascript" src="/js/jquery-1.2.6.js"></script> <script type="text/javascript" src="/js/carousel.js"></script> I haven't coded any of these myself (of course), so I am not familiar with the variables in the files. So my target is to find a way to to use these scripts simultaneously. I am very thankful for your help but I am also kindly asking for a simple and easy to understand instruction. The webpage can be found he http://wearethemusicmakers.se/index2.php Best Regards Johannes It can be found right he http://arkdesigns.ca/AttilaKomaromiJavaCalculator.htm I have javascript enabled on my browsers but it still doesn't work. I see the calculator but pushing the buttons does nothing Any help is appreciated My code is: 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>Javascript Calculator</title> <style> <!-- CSS STYLES GO HERE --> .container { width:500px; height:500px; } .equ { width:99%; height:20px; font-size:20px; text-align:right; margin-bottom:15px; } table { border:1px solid black; padding:5px; width:100%; } table td { margin:3px; text-align:center; width:20%; } .buttons { width:100%; height:50px; font-size:15px; } </style> <script type="text/javascript" src="javascript.js"> </script> </head> <body> <div class="container"> <table cellspacing="0"> <tr> <td colspan="5"><input class="equ" type="input" disabled="disabled" id="equation" value="0"/><input type="hidden" id="previousType" value="-1"/></td> </tr> <tr> <td><input class="buttons" type="button" name="sin" value="sin" onclick="solve ('sin')" /></td> <td><input class="buttons" type="button" name="cos" value="cos" onclick="solve ('cos')" /></td> <td><input class="buttons" type="button" name="tan" value="tan" onclick="solve('tan')" /></td> <td><input class="buttons" type="button" name="sqrt" value="√" onclick="solve('sqrt')" /></td> </tr> <tr> <td><input class="buttons" type="button" name="back" value="←" onclick="remove ();"/></td> <td colspan="2"><input class="buttons" type="button" name="erase" value="C" onclick="clear_equation ();" /></td> <td><input class="buttons" type="button" name="divide" value="/" onclick="equation (this.value, 1)"/></td> </tr> <tr> <td><input class="buttons" type="button" name="seven" value="7" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="eight" value="8" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="nine" value="9" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="multiple" value="*" onclick="equation (this.value, 1)"/></td> </tr> <tr> <td><input class="buttons" type="button" name="four" value="4" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="five" value="5" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="six" value="6" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="subtract" value="-" onclick="equation (this.value, 1)"/></td> </tr> <tr> <td><input class="buttons" type="button" name="one" value="1" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="two" value="2" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="three" value="3" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="plus" value="+" onclick="equation (this.value, 1)"/></td> </tr> <tr> <td colspan="2"><input class="buttons" type="button" name="zero" value="0" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="decimal" value="." onclick="equation (this.value, 3)"/></td> <td><input class="buttons" type="button" name="equal" value="=" onclick="solve ('');"/></td> </tr> </table> </div> </body> </html> Please see URL: http://caspca.org/indexticker.htm The ticker below the navbar works fine in FF and Safari, does not work in IE8 (and mostly likely other IE version as well). In IE, the live page will not even load; will load locally but the ticker doesn't work (remains static). Here is the .js: Code: TICKER_CONTENT = document.getElementById("TICKER").innerHTML; TICKER_RIGHTTOLEFT = false; TICKER_SPEED = 1; TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444"; TICKER_PAUSED = false; ticker_start(); function ticker_start() { var tickerSupported = false; TICKER_WIDTH = document.getElementById("TICKER").style.width; var img = "<img src=ticker_space.gif width="+TICKER_WIDTH+" height=0>"; // Firefox if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) { document.getElementById("TICKER").innerHTML = "<TABLE cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'> </SPAN>"+img+"</TD></TR></TABLE>"; tickerSupported = true; } // IE if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) { document.getElementById("TICKER").innerHTML = "<DIV nowrap='nowrap' style='width:100%;'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'></SPAN>"+img+"</DIV>"; tickerSupported = true; } if(!tickerSupported) document.getElementById("TICKER").outerHTML = ""; else { document.getElementById("TICKER").scrollLeft = TICKER_RIGHTTOLEFT ? document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth : 0; document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT; document.getElementById("TICKER").style.display="block"; TICKER_tick(); } } function TICKER_tick() { if(!TICKER_PAUSED) document.getElementById("TICKER").scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1); if(TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft <= 0) document.getElementById("TICKER").scrollLeft = document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth; if(!TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft >= document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth) document.getElementById("TICKER").scrollLeft = 0; window.setTimeout("TICKER_tick()", 30); Any help to fix is greatly appreciated. Thank you. John I have a page with a Geo IP redirect that's supposed to redirect users from London to URL#1 and the rest to URL#2. It's an external geo ip lookup service. First comes the IP lookup: Code: <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"> /* GeoIP Deny Access by City and Redirect Javascript 1.0 http://wiki.category5.tv/MaxMind_GeoIP_API API (c) MaxMind - www.maxmind.com - used with permission "GeoIP Deny Access by City" script by Robbie Ferguson, www.Category5.TV You are free to use and share this script, however this notice must remain intact. */ </script> And then, and here's the problem I think, is the redirects inside an if/else: Code: <script type="text/javascript"> var city=new Array("London, H9") var redirect="http://www.URL1.com" var redirect2="http://www.URL2.com" /* do not edit past this line */ Array.prototype.inArray = function(q) { for(i in this) { if(this[i].toUpperCase() === q) return true; } } var myCity=geoip_city().toUpperCase() var myRegion=geoip_region().toUpperCase() if(city.inArray(myCity+", "+myRegion)) { window.location = redirect; } else { window.location = redirect2; } The redirect works if you are indeed from London. So if the if-statement is true, "window.location = redirect" works, but if the statement is not true, "window.location = redirect2" doesn't seem to be called. Help would be extremely appreciated I am hoping that someone can figure out why this simple javascript works fine in Firefox, but not in IE8. I appreciate any help. PS: I see it DOES work in IE9... but I can't use it if I cannot make it work in IE8 as well. Sincerely, Buffmin 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>test</title> <script type="text/javascript" src="jquery-1.6.2.js"></script> <script type="text/javascript"> $(document).ready(function() { switches = $('#switches > li'); slides = $('#slides > div'); switches.each(function(idx) { $(this).data('slide', slides.eq(idx)); }).hover( function() { switches.removeClass('active'); slides.removeClass('active'); $(this).addClass('active'); $(this).data('slide').addClass('active'); }); }); </script> <style type="text/css"> #switches .active { font-weight: bold; } #slides div { display: none; } #slides div.active { display: block; } </style> </head> <body> <ul id="switches"> <li class="active">First slide</li> <li>Second slide</li> <li>Third slide</li> <li>Fourth slide</li> </ul> <div id="slides"> <div class="active">Well well.</div> <div>Oh no!</div> <div>You again?</div> <div>I'm gone!</div> </div> </body> </html> Ive searched on this board but cant find out why this doesn't work. Code: <script type="text/javascript"> function showSelected(val) if (val == "Nil") { document.getElementById('JustText').innerHTML='hi' } else { document.getElementById('selectedResult').innerHTML="<a href='mailto:" + val + "'>" + val + "</a><p>" } </script> I have the following script in the head; Code: <script type="text/javascript"> <![CDATA[ <!--This function validates the data from the three input boxes on the MAILTO form--> function validate() { Check="Valid"; Name=document.contact.name.value; Mail=document.contact.mail.value; Comment=document.contact.comment.value; if (Name=="your name" || Name.length<1) { alert("Please enter your name"); Check="Invalid"; } else if (Mail.indexOf("@")<1 || Mail.indexOf(".")<1) { alert("Please enter a valid email address"); Check="Invalid"; } else if (Comment=="your comment" || Comment.length<1) { alert("Please enter your comment"); Check="Invalid"; } if (Check=="Invalid") { return false; } else { alert("Thank you for your comment"); } } ]]> </script> and the following form in the body; Code: <div> <form name="contact" onsubmit="return validate()" action="email.asp" method="post"> <div class="input_title">Name:</div><input type="text" name="name" size="25" class="input_box" /> <br /> <div class="input_title">Your Email:</div><input type="text" name="sender" size="25" class="input_box" /> <br /> <div class="input_title">Phone Number:</div><input type="text" name="tel" size="25" class="input_box" />(Optional) <br /> Message: <br /> <textarea name="enquiry" cols="50" rows="6" class="input_box"></textarea> <br /> <input type="submit" value="Submit" name="submit" /><input type="reset" value="Reset" name="reset" /> <br /> </form> <br /><br /> </div> It is a aspx file and validates fine as XHTML Trans. Why won't it work? |