JavaScript - Mouse Position Not Working In Firefox
it works great in chrome and strangely enough internet explorer 8 but doesn't work in firefox
Code: // Detect if the browser is IE or not. // If it is not IE, we assume that the browser is NS. var IE = document.all?true:false; // If NS -- that is, !IE -- then set up for mouse capture if (!IE) document.captureEvents(Event.MOUSEMOVE) // Set-up to use getMouseXY function onMouseMove document.onmousemove = DRAG; // Temporary variables to hold mouse x-y pos.s // Main function to retrieve mouse x-y pos.s var tempX = 0; var tempY = 0; function DRAG(e) { if (!IE) { // grab the x-y pos.s if browser is NS tempX = e.pageX; tempY = e.pageY; } else { // grab the x-y pos.s if browser is IE tempX = event.clientX + document.body.scrollLeft tempY = event.clientY + document.body.scrollTop } // catch possible negative values in NS4 if (tempX < 0){ tempX = 0; } if (tempY < 0){ tempY = 0; } // show the position values in the form named Show // in the text fields named MouseX and MouseY var w = getW(); var h = getH(); if(tempX > (w-32)){tempX = w-32;} if(tempY > (h - 32)){tempY = h-32; } var newX = tempX-id.offsetWidth; var newY = tempY-header.offsetHeight-id.offsetHeight; if(newX < 0){newX = 0; } if(newY < 0){newY = 0; } document.getElementById('myx').innerHTML = newX; document.getElementById('myy').innerHTML = newY; id.style.left = newX+"px"; id.style.top = newY+"px"; Similar TutorialsHi I have a control on the left side of the page which sits inside a div. The control reacts to where the mouse is positioned within the div. This works fine in IE but I cant get it working in Firefox. Heres what I have: Code: <div id="divcon" class="boxContentLeft" OnMouseMove="SetValues(event);"> function SetValues(event) { var ev=(!event)?window.event:event; //Moz:IE if (ev.pageX) { //Mozilla or compatible /* The absolute position of the control */ var MarqPos = GetAbsPosition(divcon); alert('MarqPos x = '+MarqPos.x+'\nMarqPos y = '+MarqPos.y); /* Relative to this div */ MousePointerDivX = ev.pageX-MarqPos.x; MousePointerDivY = ev.pageY-MarqPos.y; alert('MousePointerDivX = '+MousePointerDivX+'\nMousePointerDivY = '+MousePointerDivY); /* Relative to the top left of the viewable area */ MousePointerClientX = ev.pageX; MousePointerClientY = ev.pageY; alert('MousePointerClientX = '+MousePointerClientX+'\nMousePointerClientY = '+MousePointerClientY); } else if(ev.clientX) { //IE or compatible /* Relative to this div */ MousePointerDivX = window.event.x; MousePointerDivY = window.event.y; alert('MousePointerDivX = '+MousePointerDivX+'\nMousePointerDivY = '+MousePointerDivY); /* Relative to the top left of the viewable area */ //MousePointerClientX = window.event.clientX; //MousePointerClientY = window.event.clientY; //alert('MousePointerClientX = '+MousePointerClientX+'\nMousePointerClientY = '+MousePointerClientY); /* The absolute position of the control */ var MarqPos = GetAbsPosition(divcon); alert('MarqPos x = '+MarqPos.x+'\nMarqPos y = '+MarqPos.y); /* The mouse position relative to top left of page */ //MousePointerX = mouseX(window.event); //MousePointerY = mouseY(window.event); //alert('MousePointerX = '+MousePointerX+'\nMousePointerY = '+MousePointerY); /* The control relative to the top left of the parent control */ //var OffsetLeft = marquees.offsetLeft; //var OffsetTop = marquees.offsetTop; //alert('OffsetLeft = '+OffsetLeft+'\nOffsetTop = '+OffsetTop); } else { //old browsers return false; } setInterval("",20); } // Calculates the object's absolute position, and width and height function GetAbsPosition(object) { var position = new Object; position.x = 0; position.y = 0; if( object ) { position.x = object.offsetLeft; position.y = object.offsetTop; if( object.offsetParent ) { var parentpos = GetAbsPosition(object.offsetParent); position.x += parentpos.x; position.y += parentpos.y; } } position.cx = object.offsetWidth; position.cy = object.offsetHeight; return position; } Using IE only I didnt need to find out the position of the DIV within the page as I could just use 'window.event.x' which would return the x coordinate within the DIV. I dont think you can do that with Firefox so you have to get the coordinate of the mouse and then subtract the coordinates of the DIV. But when Im calling GetAbsPosition(divcon) I get Error: divcon is not defined. Can somebody please tell me why I can call GetAbsPosition from IE and it works but I get an error calling the same thing in Firefox. Thanks is it possible to make the mouse be at a given position on the screen using javascript for example i am writing a element resize script and i would like to have it so when u click on the resize button the cursor moves to the bottom right corner of the element for the starting position
Error: Code: Error ``TypeError: window.event is undefined'' [x-] in file ``file:///C:/Users/Martyn%20Ball/Desktop/test.php#'', line 6, character 0. Code: Code: <html> <head> <title>Testing Javascript</title> <script type="text/javascript"> function test() { alert(window.event.clientX); } function doSomething(e) { var posx = 0; var posy = 0; if (!e) var e = window.event; if (e.pageX || e.pageY) { posx = e.pageX; posy = e.pageY; } else if (e.clientX || e.clientY) { posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } // posx and posy contain the mouse position relative to the document // Do something with this information } </script> </head> <body> X Position: <div id="x"></div> Y Position: <div id="y"></div> <br /> <a href="#" onMouseOver="test()">Test Link</a><br /> <a href="#" onClick="doSomething('y')">Type of Event</a> </body> </html> (Taken from external website so I can understand how it works). Hi all, I tried to create a mouse over effect using jquery. When user hovers #box1_trigger link, the #service_box1 div should change it's background position. The code i created is the following it's not working for some reason. html: Code: <div class="service_box box1" id="service_box1"> <a href="#" id="box1_trigger"> <h3>bla bla</h3> <p>bla bla bla bla bla</p> </a> </div> javascript: Code: <script type="text/javascript"> $(document).ready(function() { $("#box1_trigger").hover( function() { $("#service_box1").stop().animate({backgroundPosition:"(0 -250px)"}, "slow"); }, function() { $("#service_box1").stop().animate({backgroundPosition: "0 0"}, "slow"); } ); }); </script> css: Code: #service_box1{ width:318px; height:282px; float:left; background:url(images/services_panel.png) 0 0 no-repeat; } a#box1_trigger{ width:100%; height:100%; float:left; display:block; } Could you help me fix this please?? so basically I have a div that contains the image of a circle and I need to check if the mouse is touching the circle. what approach should I take to this? I need to call another function when the mouse leaves the circle (which will be a square speaking physically) I would assume it has to do with radius, but I am not really sure how to do this with a circle shape. thanks a ton! Hi; I'd like to ask you a question; why my mouse cursor does not sit in the position of the leftmost and topmost of a bbcode form. Thanks. my form as following; bbcode form PHP Code: <form action="story_verify1.php" method="post" name="editform" onsubmit="return checkForm(this)"> <table id="editform"> <tr> <td id="story">My story</td> </tr> <tr> <td> <input type="button" class="button" value="bold" name="bold" onclick="javascript:tag('b', '[b]', 'bold*', '[/b]', 'bold', 'bold');" onmouseover="helpline('bold')" /> <input type="button" class="button" value="italic" name="italic" onclick="javascript:tag('i', '[i]', 'italic*', '[/i]', 'italic', 'italic');" onmouseover="helpline('italic')" /> <input type="button" class="button" value="underline" name="underline" onclick="javascript:tag('u', '[u]', 'underline*', '[/u]', 'underline', 'underline');" onmouseover="helpline('underline')" /> <input type="button" class="button" value="quote" name="quote" onclick="javascript:tag('q', '[quote]', 'quote*', '[/quote]', 'quote', 'quote');" onmouseover="helpline('quote')" /> <input type="button" class="button" value="code" name="code" onclick="javascript:tag('c', '[code]', 'code*', '[/code]', 'code', 'code');" onmouseover="helpline('code')" /> <input type="button" class="button" value="url" name="url" onclick="javascript:tag('url', '[url]', 'url*', '[/url]', 'url', 'url');" onmouseover="helpline('url')" /> <input type="button" class="button" value="img" name="img" onclick="javascript:tag('img', '[img]', 'img*', '[/img]', 'img', 'img');" onmouseover="helpline('img')" /> <br /> Font size: <select name="fontsize" onchange="font('[size=' + this.form.fontsize.options[this.form.fontsize.selectedIndex].value + ']', '[/size]'); this.selectedIndex=2;" onmouseover="helpline('fontsize')" class="form_elements_dropdown"> <option value="50%" >Tiny</option> <option value="75%" >Small</option> <option value="100%" selected="selected" >Normal</option> <option value="150%" >Large</option> <option value="200%" >Huge</option> </select> Font color: <select name="fontcolor" onchange="font('[color=' + this.form.fontcolor.options[this.form.fontcolor.selectedIndex].value + ']', '[/color]'); this.selectedIndex=0;" onmouseover="helpline('fontcolor')" class="form_elements_dropdown" > <option value="black" style="color:black">Black</option> <option value="silver" style="color:silver">Silver</option> <option value="gray" style="color:gray">Gray</option> <option value="maroon" style="color:maroon">Maroon</option> <option value="red" style="color:red">Red</option> <option value="purple" style="color:purple">Purple</option> <option value="fuchsia" style="color:fuchsia">Fuchsia</option> <option value="navy" style="color:navy">Navy</option> <option value="blue" style="color:blue">Blue</option> <option value="aqua" style="color:aqua">Aqua</option> <option value="teal" style="color:teal">Teal</option> <option value="lime" style="color:lime">Lime</option> <option value="green" style="color:green">Green</option> <option value="olive" style="color:olive">Olive</option> <option value="yellow" style="color:yellow">Yellow</option> <option value="white" style="color:white">White</option> </select> <br /> <input type="text" name="helpbox" size="75" class="helpbox" readonly="readonly"/> </td> </tr> <tr> <td> Post:***<br /> <textarea rows="10" cols="50" name="Content" class="form_elements_text" id="thread"> <?php echo trim(stripslashes($_SESSION['story_content'])); ?> </textarea> </td> </tr> <tr> <td colspan="2" class="security_check"> <?php $_SESSION['fvalue']=rand(0,9); echo $_SESSION['fvalue']; ?> + <?php $_SESSION['svalue']=rand(0,9); echo $_SESSION['svalue']; ?> = <input type="text" name="result" /> ** </td> </tr> <tr> <td colspan="2" id="post"> <input type="submit" name="Post" value="Post" class="button" /> <input type="submit" name="preview" value="Preview" class="button"/> <input type="reset" value="Reset" class="button" onclick="javascript:confirm_reset();"/> </td> </tr> </table> </form> bbcode.js PHP Code: //Variables for controlling opening and closing tags (function tag) var b = 2; var i = 2; var u = 2; var q = 2; var mail = 2; var url = 2; var img = 2; //Function for creating non-font tags function tag(v, tagadd, newbut, tagclose, oldbut, name) { var r = document.selection.createRange().text; rr = tagadd + r + tagclose; if(r) { document.selection.createRange().text = rr; } else { if (eval(v)%2 == 0) { eval("window.document.editform."+name+".value = newbut;"); var content = window.document.editform.content.value; window.document.editform.content.value = content + tagadd; window.document.editform.content.focus(); } else { eval("window.document.editform."+name+".value = oldbut;"); var content = window.document.editform.content.value; window.document.editform.content.value = content + tagclose; window.document.editform.content.focus(); } eval(v+"++;"); } } //Function for adding font color and size tags function font(bbopen, bbclose) { var r = document.selection.createRange().text; rr = bbopen + r + bbclose; if(r) { document.selection.createRange().text = rr; }else{ var post = document.editform.post; post.value += bbopen +r+ bbclose; post.focus(); } return; } function smilie (tag) { var myField; tag = ' ' + tag + ' '; if (document.getElementById('thread') && document.getElementById('thread').type == 'textarea') { myField = document.getElementById('thread'); } else { return false; } if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = tag; myField.focus(); } else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; var cursorPos = endPos; myField.value = myField.value.substring(0, startPos) + tag + myField.value.substring(endPos, myField.value.length); cursorPos += tag.length; myField.focus(); myField.selectionStart = cursorPos; myField.selectionEnd = cursorPos; } else { myField.value += tag; myField.focus(); } } //Helpbox messages bold_help = "Bold text: [b]text[/b]"; italic_help = "Italic text: [i]text[/i]"; underline_help = "Underline text: [u]text[/u]"; quote_help = "Quote text: [quote]text[/quote] or [quote=name]text[/quote]"; code_help = "Code display: [code]code[/code]"; img_help = "Insert image: [img]http://image_url[/img]"; url_help = "Insert URL: [url]http://url[/url] or [url=http://url]URL text[/url]"; fontcolor_help = "Font color: [color=red]text[/color] Tip: you can also use color=#FF0000"; fontsize_help = "Font size: [size=50%]small text[/size]"; //Function for displaying help information // Shows the help messages in the helpline window function helpline(help) { var helpbox = document.editform.helpbox; helpbox.value = eval(help + "_help"); } //Function to confirm reset function confirm_reset () { if(confirm("If you continue you will loose everything you have entered so far. \n \n" + "Click OK to proceed and start again. \n \n Alternatively click cancel to continue " + "working on your post.")) { return true; } else { return false; } } //Check the form submission for errors function checkForm() { var subject = document.editform.subject; var post = document.editform.post; //Check to make sure post lengths are sensible if (subject.value.length < 2 && post.value.length < 2) { alert("This is a short post!" + " \n \n " + "We require that each post (and subject) \n" + "be at least 2 characters long. \n \n" + "Go back and try again."); return false; } else { if (subject.value.length < 2) { alert("We require that the subject \n" + "be at least 2 characters long. \n \n" + "Go back and try again."); return false; } else { if (post.value.length < 2) { alert("We require that each post \n" + "be at least 2 characters long. \n \n" + "Go back and try again."); return false; } else { return true; } } } } I put in a code, so that when you hover over a link, text appears at the bottom of the page. My code works fine in IE 8, but the text doesn't appear in Firefox. I ran Firebug, and it gave me a "detailsbox is not defined" error. I'm still trying to figure javascript out, and could really use your help! Thanks Code: <script type="text/javascript"> function menu (whichMenu,whatState){ if (document.getElementById) {document.getElementById(whichMenu).style.visibility = whatState;} else {document[whichMenu].visibility = whatState;} } function details(what){ myInfo={"Threat":"text.", "Compliance":"text.", "Virtualization":"text.", "Convergence":"text."} detailsBox.innerHTML=myInfo[what] } </script> <LINK href="main.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- a.black:link {color: #000000;} a.black:active {color: #000000;} a.black:visited {color: #000000;} a.black:hover {color: #000000;} a.red:link {color: #ff0000;} a.red:active {color: #ff0000;} a.red:visited {color: #ff0000;} a.red:hover {color: #ff0000;} --> </style> <script type="text/javascript"> function newPopup(url) {popupWindow = window.open(url,'popUpWindow','dependent=yes,height=570,width=750,left=10,top=10,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no')} </script> <script type="text/javascript"> function newPopup2(url) {popupWindow = window.open(url,'popUpWindow','dependent=yes,height=570,width=750,left=10,top=10,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no')} </script> </head> <body bgcolor="#c1c2c2"> <table width="1065" cellpadding="0" cellspacing="0" border="0"> <tr><td colspan="6"><img src="images/White_Rectangle.jpg" width="1065" height="24"></td></tr> </table> <table width="1065" bgcolor="white" cellpadding="0" cellspacing="0" border="0"> <tr><td><img src="images/White_Rectangle.jpg" width="17" height="55"></td><td colspan="5"><a href="index.html"><img src="images/Trend_Micro_Securing_Your_Web_World_Logo.gif" border="0"></a></td> <td><img src="images/White_Rectangle.jpg" width="100" height="55"></td> <td align="right"><font size="2" face="Interstate-Regular"><a href="JavaScript:newPopup('help.html');" style="text-decoration:none" class="red">Help</a></font> <font size="2" face="Interstate-Regular" color="gray"> | </font> <font size="2" face="Interstate-Regular"><a href="JavaScript:newPopup2('quiz.html');" style="text-decoration:none" class="red">Feedback</a></font> <br> <br> <font size="2" face="Interstate-Regular"><a href="http://www.trendmicro.com" style="text-decoration:none" class="black" rel="nofollow" target="blank">www.trendmicro.com</a></font> </td> <td><img src="images/White_Rectangle.jpg" width="25" height="55"></td> </tr> </table> <table width="1065" cellpadding="0" cellspacing="0" border="0"> <tr><td colspan="6"><img src="images/White_Rectangle.jpg" width="1065" height="18"></td></tr> </table> <table width="1065" cellpadding="0" cellspacing="0" border="0"> <tr><td><A HREF="products.html" onmouseover="document.but.src='images/Upsell_Reference_Gradient.jpg'"onmouseout="document.but.src='images/Upsell_Reference_Tab.jpg'"><IMG SRC="images/Upsell_Reference_Tab.jpg" NAME="but" width="178" height="38" BORDER="0"></A></td><td><A HREF="competitor_products.html" onmouseover="document.but2.src='images/Competitor_Products_Gradient.jpg'"onmouseout="document.but2.src='images/Competitor_Products_Tab.jpg'"><IMG SRC="images/Competitor_Products_Tab.jpg" NAME="but2" width="178" height="38" BORDER="0"></A></td><td><img src="images/Red_Bar.jpg" width="178" height="38"></td><td><img src="images/Red_Bar.jpg" width="177" height="38"></td><td><img src="images/Red_Bar.jpg" width="177" height="38"></td><td><img src="images/Red_Bar.jpg" width="177" height="38"></td></tr> <tr><td colspan="6"><img src="images/White_Rectangle.jpg" width="1065"></td></tr> </table> <table width="1024" cellpadding="0" cellspacing="0" border="0"> <tr> <td valign="top"> <table cellpadding="0" cellspacing="0" border="0" > <tr> <td valign="top" bgcolor="#FFFFFF"> <div style="overflow:auto; width:300px; height:820px; background-color:#ebebe9; text-align:right; padding-right:1px;"> <div style="text-align:left;"> <a href="index.html"><img src="images/home_btn.jpg" border="0" /></a> <div class="glossymenu" > <a class="menuitem submenuheader" href="" ><div style="margin-top:4px;">Client/Server Suite</div></a> <div class="submenu"> <ul> <li><a onmouseover="details('Threat')" href="products_css_detail1.html" rel="nofollow" target="mainBody" class="menulink">Threat Landscape</a></li> <li><a onmouseover="details('Compliance')" href="products_css_detail2.html" rel="nofollow" target="mainBody" class="menulink">Security Compliance</a></li> <li><a onmouseover="details('Convergence')" href="products_css_detail4.html" rel="nofollow" target="mainBody" class="menulink">Convergence and Cost Reduction</a></li> </ul> </div> I'm trying to enable/disable a textarea. I am able to do a mouseout disable, but cannot do a mouseover enable. For instance, when I click on the image, a textarea shows up. When I move my mouse to a different location, the textarea disables fine. Then when I try to move my mouse back over the textarea, it DOES NOT enable for me to write in it. What am I doing wrong? Thanks! Another bonus question, I just happen to try out this code in IE and the textareas are not showing up where I click. I assume that I'm capturing the X/Y coordinates incorrectly for an IE browser. Any pointers? ********* CODE ************* <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Mouse position</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> var posx, posy; // initialize cache var cache= []; var count=0; function getMouse(e){ posx= posy= 0; var ev= (!e) ? window.event : e;//IE:Moz if (ev.pageX){//Moz posx=ev.pageX+window.pageXOffset; posy=ev.pageY+window.pageYOffset; } else if(ev.clientX) {//IE posx=ev.clientX+document.body.scrollLeft; posy=ev.clientY+document.body.scrollTop; } else { // old browsers return false; } } function showP(){ // object to store this coordinate var thisCoord= {}; // x & y values stored as object attributes thisCoord.posx= posx; thisCoord.posy= posy; // check the cache for this coordinate object if ( !cache[thisCoord] ) { // if it hasn't been cached yet, push it onto the stack cache.push(thisCoord); var newDiv= document.createElement("textarea"); newDiv.setAttribute("class","div3"); newDiv.setAttribute("id",count); newDiv.style.width='180px'; newDiv.style.height='45px'; newDiv.style.visibility="visible"; newDiv.style.top= (thisCoord.posy -10) +'px'; newDiv.style.left= (thisCoord.posx -6) +'px'; newDiv.setAttribute("onmouseout","this.disabled=true"); newDiv.setAttribute("onmouseover","this.disabled=false"); // append to the document BODY document.getElementsByTagName("body")[0].appendChild(newDiv); count++; } } </script> <style type="text/css"> .div1 {position:absolute;top:100px;left:100px;visibility:visible;z-index:5} .div2 {position:absolute;top:0px;left:0px;visibility:hidden;z-index:1;color:black;} .div3 {position:absolute;visibility:hidden;z-index:10;font-size:14px;font-weight:450;color:black;} textarea[disabled='disabled'] { background:yellow; color:blue; cursor:default; } </style> </head> <body> <div id="div1" class="div1"> <img id="theImage" src="./YourImage.jpg"> </div> <script type="text/javascript"> // setup event handlers // document BODY onmousemove document.getElementsByTagName("body")[0].onmousemove= function(e){ getMouse(e); }; // the image onclick document.getElementById("theImage").onclick= showP; //onMouseOut </script> </body> </html> Hi, I was wondering if anyone could help me out with a script I'm trying to create/customize. The idea is to scroll an image by dragging of the mouse (like you have with Google maps for example), instead of the scrollbars. Right now I'm using a script that does the job perfectly fine under IE, but not so much under FireFox, and definitely not under Chrome. Some additional code is probably needed but I have no clue how to write proper JavaScript. Everything I try gives errors and leaves me baffled. Here's a hands-on example of what I mean (works only under IE!): http://home.wanadoo.nl/r.a.dekk/kaart/kaart.html This is the script I'm using now: Quote: <!-- <script type="text/javascript"> document.onmousedown = function(){ var e=arguments[0]||event; var x=document.body.scrollLeft+e.clientX; var y=document.body.scrollTop+e.clientY; document.onmousemove=function(){ scroll(x-e.clientX, y-e.clientY); return false; } document.onmouseup=function(){ document.onmousemove=null; } return false; } </script> //--> Any help will be appreciated. Thanks. I've got to have a typo somewhere, but i can't seem to find it. I need a new pair of eyes to point it out for me. background: trying to code a mouseover link for a nav bar. everything is working( hyperlink, normal image shows up) but when i mouse over the image swap doesn't happen. I have 2 parts of code. 1st preloads images and does the swap function. loads in <head> See below: Code: <SCRIPT language="javascript" type="text/javascript"> if (document.images) { /* preload images */ var subcontractorsOn = new Image (); subcontractorsOn.scr = "subcontractorsOn.gif"; var subcontractorsOff = new Image (); subcontractorsOff.scr = "subcontractorsOff.gif"; } function mouseOn (imgName) { if (document.images) document [imgName].scr = eval (imgName + "On.scr"); } function mouseOff (imgName) { if (document.images) document [imgName].scr = eval (imgName + "Off.scr"); } </SCRIPT> 2nd just calls the functions to preform the swap. this is in the <body> see code below Code: <a href="subcontractors.htm" onMouseOut="mouseOn('subcontractors')" onMouseOver="mouseOff('subcontractors')"> <img src="subcontractorsOff.gif" height="40" width="133" name="subcontractors" id="subcontractors" border="0" alt="subcontractors"></a> any insight would be great. regards, Fatmann66 I have found that in IE8 I cannot give an element the alpha filter (opacity) if it has the position style set to something (relative or absolute). An element without the position style (it is the empty string) can have opacity in IE8. I have found that in IE7 I can only give an element the alpha filter if the position style is set to something (relative or absolute). An element without a position style will not take the alpha filter. This is a major conundrum. Does anyone have any insight into this bug? Given the above, I can only achieve opacity in one of the two browsers. I have both IE8 and IE7 running in standards mode. The opacity is being set programmatically with JS like so: obj.style.filter = "alpha(opacity="+opacity+")"; where opacity is an integer between 0 and 100. Obviously I don't have any problem with any other browser doing opacity because it is different styles for them and they don't care about the position style at all. hereis the html file and javascripton click of this button a html ***************************** <table class=matcolor id=topnav cellspacing=0 cellpadding=0 width=550 border=0 bgcolor="#FFCCCC"> <tbody> <tr align=middle> <td id=menu1 onMouseOver="this.className='mPrimaryOn';showmenu(this);" onClick="this.document.location.href=''" onMouseOut="this.className='mPrimaryOff';hidemenu(this);" class="mat" height="20"> <div align="center"><font color="#FF0000">Desk Top Publishing </font></div> </td> <td width=1 bgcolor=#ff9900 class="mat"></td> <td id=menu2 onMouseOver="this.className='mPrimaryOn';showmenu(this);" onClick="this.document.location.href=''" onMouseOut="this.className='mPrimaryOff';hidemenu(this);" class="mat" height="20"> <div align="center"><font color="#FF0000">Transcription</font></div> </td> <td width=1 bgcolor=#ff9900 class="mat"></td> <td id=menu3 onMouseOver="this.className='mPrimaryOn';showmenu(this);" onClick="this.document.location.href=''" onMouseOut="this.className='mPrimaryOff';hidemenu(this);" class="mat" height="20"> <div align="center"><font color="#FF0000">Accounts Processing </font></div> </td> </tr> </tbody> </table> ***************************************** <script language=JavaScript> ix = document.getElementById('tblmenu1').getBoundingClientRect(); new ypSlideOutMenu("menu1", "right",ix.left + ix.right ,ix.bottom + 10); </script> **any thing i have to alter to work in firefox please help Hello all, I have a property of text box which works well in firefox but not in IE ..I am unable to understand why ..andy help is appreciated ? Code: onfocus="this.style.backgroundColor='#F1CC8E';" Hey people! New to using Javascript but have a problem. Working in Firefox but not in IE, and no errors flash up - it just does not work! Here is my code if anyone has the time to take a peak! What it does in Firefox is has a drop down with two options, both of which call the functions passing over the name of the items to be hidden or displayed. Works fine, but not in IE. Javascript Function: Code: <script type="text/javascript"> function showStuff(id) { document.getElementById(id).style.display = 'block'; } function hideStuff(id) { document.getElementById(id).style.display = 'none'; } </script> Form drop down to call javascript: Code: <select name="golf_package"> <option value='Yes' onClick="showStuff('Golf'); hideStuff('Accommodation')">Yes</option> <option value='No' selected='selected' onClick="showStuff('Accommodation'); hideStuff('Golf')">No</option> </select> Hide and Show date: Code: <span id="Golf" style="display: none; return: false;">HIDE BIT</span><span id="Accommodation" style="display: none; return: false;">HIDE BIT TWO </span> Any help will be much appreciated! Thanks Hi, I'm new to JS and been thrown in at the deepend as our developer has just left! You are dealing with a total newbie! I have the following script that is not working in FF but is fine in Chrome and IE can anyone tell me what is wrong with it please?! Code: function showTotalCost(val) { if(val=='yes') { if(document.getElementById('secondaryeventtype').value == 'adventure') { document.getElementById('totalcost').innerText = Number(parseFloat(document.getElementById('cost').value) + 100).toFixed(2) + ' (including insurance)'; } else { document.getElementById('totalcost').innerText = Number(parseFloat(document.getElementById('cost').value) + 27).toFixed(2) + ' (including insurance)'; } } else { document.getElementById('totalcost').innerText = document.getElementById('cost').value; } } Code: function calculateGroupMembers() { var iMultiplier; if(document.getElementById('txtGroup1Firstname').value != '' || document.getElementById('txtGroup1Surname').value != '' || document.getElementById('txtGroup1Email').value != '') { iMultiplier=2; } if(document.getElementById('txtGroup2Firstname').value != '' || document.getElementById('txtGroup2Surname').value != '' || document.getElementById('txtGroup2Email').value != '') { iMultiplier=3; } if(document.getElementById('txtGroup3Firstname').value != '' || document.getElementById('txtGroup3Surname').value != '' || document.getElementById('txtGroup3Email').value != '') { iMultiplier=4; } if(document.getElementById('txtGroup4Firstname').value != '' || document.getElementById('txtGroup4Surname').value != '' || document.getElementById('txtGroup4Email').value != '') { iMultiplier=5; } if(document.getElementById('txtGroup5Firstname').value != '' || document.getElementById('txtGroup5Surname').value != '' || document.getElementById('txtGroup5Email').value != '') { iMultiplier=6; } document.getElementById('totalcost').innerText = Number(parseFloat(document.getElementById('cost').value) * iMultiplier).toFixed(2) + ' (inc group members)'; } It is fired from an onblur event in the div below once the chkbox is ticked, the link to the page is https://www.doitforcharity.com/book-...eid=1990&cid=0 but you may need to progress through https://www.doitforcharity.com/book-....aspx?eid=1990 first: Code: <div id="pnlGroupBooking"> <label class="boldfieldlabel" for="chkGroupBooking">Do you wish to book for others too? </label> <input id="chkGroupBooking" type="checkbox" language="javascript" onclick="__doPostBack('chkGroupBooking','')" checked="checked" name="chkGroupBooking"> (you may book up to 5 additional people) <div id="pnlGroupBookingNames" style="border: 1px solid LightGrey; width: 500px;" styles="padding:10px;"> <strong>Group Member Names</strong> <br> <p> </p> <p> </p> <p style="vertical-align: top;"> <strong>1) </strong> <input id="txtGroup1Firstname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup1Firstname"> <input id="txtGroup1Surname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup1Surname"> <input id="txtGroup1Email" class="formfield" type="text" onblur="calculateGroupMembers();" name="txtGroup1Email"> <br> <strong>2) </strong> <input id="txtGroup2Firstname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup2Firstname"> <input id="txtGroup2Surname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup2Surname"> <input id="txtGroup2Email" class="formfield" type="text" onblur="calculateGroupMembers();" name="txtGroup2Email"> <br> <strong>3) </strong> <input id="txtGroup3Firstname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup3Firstname"> <input id="txtGroup3Surname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup3Surname"> <input id="txtGroup3Email" class="formfield" type="text" onblur="calculateGroupMembers();" name="txtGroup3Email"> <br> <strong>4) </strong> <input id="txtGroup4Firstname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup4Firstname"> <input id="txtGroup4Surname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup4Surname"> <input id="txtGroup4Email" class="formfield" type="text" onblur="calculateGroupMembers();" name="txtGroup4Email"> <br> <strong>5) </strong> <input id="txtGroup5Firstname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup5Firstname"> <input id="txtGroup5Surname" class="formfieldsmall" type="text" onblur="calculateGroupMembers();" name="txtGroup5Surname"> <input id="txtGroup5Email" class="formfield" type="text" onblur="calculateGroupMembers();" name="txtGroup5Email"> </p> </div> </div> Thanks! I'm new to javascript and am not sure why this works in firefox and not chrome. I am trying to create a script that keeps an object fixed horizontally while bing positioned absolute vertically. if I replace the toPP variable in document.getElementById('fire').style.top = toPP; with say '50px' it will move the element down 50 pxs, but how I have it currently it doesn't do anything in chrome Code: <script type="text/javascript" > window.onscroll = function() { if( window.XMLHttpRequest ) { var x = 0 -document.documentElement.scrollTop; var toP = String(x); var toPP = toP + "px"; document.getElementById('fire').style.position = 'fixed'; document.getElementById('fire').style.top = toPP; } } </script> Hi Guys, I'm trying to do up a contact form that after a user submits the information, the drop down contact box will slide back up instead of redirecting to another page. The script works fine in Chrome and Safari, but Firefox and IE keeps redirecting to the php page. Hope someone can shed some light here, thanks! Html form: Code: <div class="left"> <!-- Login Form --> <form class="clearfix" action="contactengine.php" name="cform" method="post"> <h4>Drop us a mail</h4> <label class="grey" for="emailName">Name:</label> <input class="field" type="text" name="emailName" id="emailName" value="" size="23" /> <label class="grey" for="emailFrom">Email Address:</label> <input class="field" type="text" name="emailFrom" id="emailFrom" value="" size="23" /> <label class="grey" for="message">Message:</label> <textarea type="text" name="message" id="message" size="23"></textarea> <div class="clear"></div> <input type="submit" rows="" cols="" name="submit" value="Submit" class="bt_register" /> <span id="messageSent">Message sent successfully!</span> </form> <script language="JavaScript" type="text/javascript"> //You should create the validator only after the definition of the HTML form var frmvalidator = new Validator("cform"); frmvalidator.addValidation("emailName","req","Please enter your Name"); frmvalidator.addValidation("emailName","maxlen=20", "Max length for Name is 20"); frmvalidator.addValidation("emailFrom","maxlen=50", "Max length for email is 50"); frmvalidator.addValidation("emailFrom","req","Please enter your Email"); frmvalidator.addValidation("emailFrom","email","Please enter a valid email"); </script> </div> <div class="left right"> <!-- Register Form --> <h4>Contact Details</h4> <p class="grey"><b>XXX<br /></b>XXX<br />XXX<br />XXX</p> <p class="grey">T: 999<br />F: 999</p> <h5>Stalk Us</h5> <a href="index.html"><img src="misc/fb.png" border="0" alt="Facebook" /></a> <a href="index.html"><img src="misc/twit.png" border="0" alt="Twitter" /></a> </div> </div> </div> <!-- The tab on top --> <div class="tab"> <ul class="login"> <li class="left"> </li> <li>Hello there</li> <li class="sep">|</li> <li id="toggle"> <a id="open" class="open" href="#">Contact Us</a> <a id="close" style="display: none;" class="close" href="#">Close Panel</a> </li> <li class="right"> </li> </ul> </div> <!-- / top --> The Slider JS: Code: $(document).ready(function() { // Expand Panel $("#open").click(function(){ $("div#panel").slideDown("slow"); }); // Collapse Panel $("#close").click(function(){ $("div#panel").slideUp("slow"); }); // Switch buttons from "Hey There | Contact us" to "Close Panel" on click $("#toggle a").click(function () { $("#toggle a").toggle(); }); //submission scripts $('div#panel').submit( function(){ //statements to validate the form var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; var email = document.getElementById('emailFrom'); if (!filter.test(emailFrom.value)) { $('.email-missing').show(); } else {$('.email-missing').hide();} if (document.cform.emailName.value == "") { $('.name-missing').show(); } else {$('.name-missing').hide();} if (document.cform.message.value == "") { $('.message-missing').show(); } else {$('.message-missing').hide();} if ((document.cform.emailName.value == "") || (!filter.test(email.value)) || (document.cform.message.value == "")){ return false; } if ((document.cform.emailName.value != "") && (filter.test(email.value)) && (document.cform.message.value != "")) { //hide the form $('.div#panel').hide(); //show the loading bar $('.loader').append($('.bar')); $('.bar').css({display:'block'}); //send the ajax request $.post('contactengine.php',{emailName:$('#emailName').val(), emailFrom:$('#emailFrom').val(), message:$('#message').val()}, //return the data function(data){ //hide the graphic $('.bar').css({display:'none'}); $('.loader').append(data); }); //waits 2000, then closes the form and fades out $("#messageSent").show("slow"); setTimeout('$("#toggle a").toggle(); $("div#panel").slideUp("slow")', 2000); //stay on the page return false; } }); }); The PHP Code: PHP Code: <?php $EmailFrom = "xxx@xxx.com"; $EmailTo = "xxx@xxx.com"; $Subject = Trim(stripslashes($_POST['Webmail'])); $Name = Trim(stripslashes($_POST['emailName'])); $Email = Trim(stripslashes($_POST['emailFrom'])); $Message = Trim(stripslashes($_POST['message'])); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Email Adress: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, Webmail, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=success.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> Hi, This problem has completely stumped me, was hoping from a bit of advice. I have used the code of my affiliate software to show my company logo. This code works in Firefox, but for some reason doesn't work in IE. The company who own the affiliate software have never seen this problem before and have been unable to assist. Not sure if it's a server problem? To see the problem have a look at logo at the top of my test website in firefox then IE. http://www.nctshop.co.uk/staging/ Here is a snippet of the code below. It is the line where it links to nctshopaffiliate which is where the problem lies. Thanks! Adrian Code: <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td class="topnav1bgcolor"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top"><a href="../default.asp"><script language="JavaScript" type="text/javascript" src="http://www.nctshopaffiliate.co.uk/display.php?token=logo" alt="NCTSHOP" width="650" height="89" border="0"/></script></a></td> <td align="right" valign="top"> <table width="223" border="0" cellpadding="0" cellspacing="0"> <tr><td height="5" colspan="5"><img src="images/clear.gif" alt="" style="width:1;height:1;border:0"></td></tr> <tr><td colspan="5"> </td></tr> <tr><td height="25" colspan="5"><img src="images/clear.gif" alt="" style="width:1;height:1;border:0"></td></tr> <tr> <td class="plaintext"><a title="View Basket" href="basket.asp"><img src="images/newcart_Img.gif" alt="View Basket" style="width:23;height:12;border:0"></a></td> <td><img src="images/clear.gif" alt="" style="width:5;height:1;border:0"></td> <td style="background-image:url(images/bkg_cartinfo.gif);height:21"> <table width="200" border="0" cellpadding="0" cellspacing="0" > <tr> <td class="plaintext" align="center"><a title="View Basket" href="basket.asp"><span class="plaintext"><u>Items</u></span></a> <%=session("SL_BasketCount")%> | Sub Total <%=formatcurrency(session("SL_BasketSubTotal"))%></td> </tr> </table> </td> <td> </td> <td><a class="topnav1" title="Checkout" href="<%=session("secureurl")%>custinfo.asp" ><u>Checkout</u></a></td> </tr> </table> </td> <td style="width:10"><img src="images/clear.gif" alt="" style="width:1;height:1;border:0"></td> </tr> </table> </td> </tr> </table> Hi, After spending hours trying out many different examples that supposedly work with IE and FF, I've decided to post here This is the code I'm using to catch the down arrow: Code: function is_int(event) { var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; if(Key==40) { alert('down arrow'); } } And called using the following on the text input of a form field: Code: onKeyDown="is_int(event);" This works in IE but still not in Firefox (3.5.7). Surprised as it has the .which in there - I thought this is what FF needed? |