JavaScript - Passing Mouse Coordinates Thru Layers
Similar TutorialsI'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 Hey guys/gals, do ya know an efficient way to get the coordinates of a pictures so that I can use them to create a map? It is a rectangle. Here is the code I set up for a page: Code: <HTML> <HEAD> <TITLE>Cyrus</TITLE> </HEAD> <BODY BGCOLOR=black> <div align="center"> <table border="0"; cellspacing="0"; cellpadding="0"> <tr> <td><img src="http://i732.photobucket.com/albums/ww329/Chrishick/pageheadername.png"; width=900px; hieght=160px;></td> </tr> <tr> <td><img src="http://i732.photobucket.com/albums/ww329/Chrishick/navbar.png" width=900px; border="none" usemap="#navbar"></td> </tr> <tr> <td> <br> <br> <table border="0"; width=900px> <tr> <td> <div align="left"><img src="http://i732.photobucket.com/albums/ww329/Chrishick/appearance-2.png"; width=466px; hieght=320px></div> </td> <td> <div align="right"><img src="http://i732.photobucket.com/albums/ww329/Chrishick/equipment.png"> <br><br> <img src="http://i732.photobucket.com/albums/ww329/Chrishick/personality.png"> </div> </td> </tr> </table> </td> </tr> <tr> <td></td> </tr> <tr> <td> <div align="center"><img src="http://i732.photobucket.com/albums/ww329/Chrishick/brought.png"></div></td> </tr> </table> </div> <map name="navbar"> <area shape="rect" coords="247,185,445,220" href="http://www.roleplayandwritinghaven.com/forum.htm" alt="Forum" /> </map> </BODY> </HTML> Can anyone help me set coordinates for an image I want to add to my page? I have the center coords where I want it to be places x is 400 and y is 90. I've searched all over the internet trying to find a solution.
Hi, I would like to get the Lat/Lng coordinates into teh values in my form but instead I get N/E values, Can anyone please help? Here is my page: http://www.nakedsloth.com/where/default.php here is my code: Code: <?php include_once("common.php"); $markers = mysql_query("SELECT * FROM wheremarkers1"); while($row1 = mysql_fetch_array($markers)) { // echo 'Lat: '.$row1['rslat']; // echo 'Long: '.$row1['rslon']; // echo 'Email: '.$row1['rsemail']; // echo 'Name: '.$row1['rsname']; // echo 'Desc: '.$row1['rsdesc']; } // $lat = $_REQUEST['lat']; // $lng = $_REQUEST['lng']; // if($lat != 51.464960 && $lng != -1.40625){ // $lat = $_POST['lat']; // $lng = $_POST['lng']; // } ?> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <!-- Bootstrap core CSS --> <link href="css/bootstrap.min.css" rel="stylesheet"> <!-- Custom styles for this template --> <link href="css/navbar-fixed-top.css" rel="stylesheet"> <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> <script src="js/ie-emulation-modes-warning.js"></script> </head> <style> body{ font-family: arial; font-size: 13px; width:100%; } #container{ width:100%; } #mapCanvas { width: 70%; height: 80%; float: left; } #infoPanel { width: 400px; float: left; margin-left: 10px; } #infoPanel div { margin-bottom: 5px; } #markerStatus { display:none; } #info { display:none; } #geot { display:none; } body { font: normal 10pt Helvetica, Arial; } ul#topmenu { height:30px; width:100%; margin-top:0px;} ul#topmenu li { display:block; float:left; margin-right:10px; margin-top:14px; } .telephone { display:none; } .website { display:none; } </style> <body style="margin:0px; border:0px; padding:0px;"> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text/javascript"> var geocoder = new google.maps.Geocoder(); $( document ).ready(function() { }); $( document ).ready(function() { $("#rscategory").change(function(){ var id = $(this).find("option:selected").attr("id"); switch (id){ case "poi": $(".telephone").css( "display","block" ); $(".website").css( "display","block" ); $('input[name="rswebsite"]').val('n/a'); $('input[name="rstelephone"]').val('0'); break; case "hiddenmsg": $(".telephone").css( "display","none" ); $(".website").css( "display","none" ); $('input[name="rswebsite"]').val('n/a'); $('input[name="rstelephone"]').val('0'); break; case "landmark": $(".telephone").css( "display","none" ); $(".website").css( "display","none" ); $('input[name="rswebsite"]').val('n/a'); $('input[name="rstelephone"]').val('0'); break; case "pub": $(".telephone").css( "display","none" ); $(".website").css( "display","none" ); break; case "cafe": $(".telephone").css( "display","none" ); $(".website").css( "display","none" ); break; case "GreatView": $(".telephone").css( "display","none" ); $(".website").css( "display","none" ); $('input[name="rswebsite"]').val('n/a'); $('input[name="rstelephone"]').val('0'); break; } }); }); function geocodePosition(pos) { geocoder.geocode({ latLng: pos }, function(responses) { if (responses && responses.length > 0) { updateMarkerAddress(responses[0].formatted_address); updateMarkerCity(responses[6].formatted_address); updateMarkerCountry(responses[7].formatted_address); } else { updateMarkerAddress('Cannot determine address at this location.'); } var country; for (i=0;i<results[0].address_components.length;i++){ for (j=0;j<results[0].address_components[i].types.length;j++){ if(results[0].address_components[i].types[j]=="Region") country = results[0].address_components[i].long_name } } var city; city = results[1].address_component['rsCity'] }); } function updateMarkerStatus(str) { document.getElementById('markerStatus').innerHTML = str; } function updateMarkerPosition(latLng) { document.getElementById('info').innerHTML = [ latLng.lat(), latLng.lng() ].join(', '); latDir = "N"; lngDir = "E"; if(latLng.lat() < 0){ latDir = "S"; } if(latLng.lng() < 0){ lngDir = "W"; } qlat = Math.abs(latLng.lat()); ilat = Math.floor(qlat); xlat = ((qlat - ilat)*60); qlng = Math.abs(latLng.lng()); ilng = Math.floor(qlng); xlng = ((qlng - ilng)*60); xlat = Math.round(xlat*1000)/1000; xlng = Math.round(xlng*1000)/1000; d2 = xlat.toFixed(3); e2 = xlng.toFixed(3); d1 = ilat.toString(); d2 = d2.toString(); e1 = ilng.toString(); e2 = e2.toString(); n = Math.abs(latLng.lat()); // Change to positive var decimal = n - Math.floor(n) var decimal = n - Math.floor(n); document.getElementById('geot').innerHTML = [ latDir + ' ' + d1 + ' ' + d2, lngDir + ' ' + e1 + ' ' + e2 ].join(', '); document.form1.rsLat.value = [ latLng.lat()]; document.form1.rsLong.value = [ latLng.lng()]; document.form1.rsLat.value = [ latDir + ' ' + d1 + ' ' + d2]; document.form1.rsLong.value = [ lngDir + ' ' + e1 + ' ' + e2]; } function updateMarkerAddress(str) { document.getElementById('address').innerHTML = str; } function updateMarkerCity(city) { document.getElementById('city').innerHTML = city; } function updateMarkerCountry(country) { document.getElementById('country').innerHTML = country; } function centerPosition(newgeo,newzoom) { // document.getElementById('mcenter').innerHTML = [newgeo]; // document.getElementById('mzoom').innerHTML = [newzoom]; // document.form2.mcenter2.value = [newgeo]; // document.form2.mzoom2.value = [newzoom]; document.form1.mcenter1.value = [newgeo]; document.form1.mzoom1.value = [newzoom]; } function initialize() { var latLng = new google.maps.LatLng(51.507222, -0.1275); var map = new google.maps.Map(document.getElementById('mapCanvas'), { zoom: 4, center: latLng, mapTypeId: google.maps.MapTypeId.ROADMAP }); var marker = new google.maps.Marker({ position: latLng, title: 'Point A', map: map, draggable: true }); // Update current position info. updateMarkerPosition(latLng); geocodePosition(latLng); // Add dragging event listeners. google.maps.event.addListener(marker, 'dragstart', function() { updateMarkerAddress('Dragging...'); updateMarkerCity(''); updateMarkerCountry(''); }); google.maps.event.addListener(marker, 'drag', function() { updateMarkerStatus('Dragging...'); updateMarkerPosition(marker.getPosition()); }); google.maps.event.addListener(marker, 'dragend', function() { updateMarkerStatus('Drag ended'); geocodePosition(marker.getPosition()); }); google.maps.event.addListener(map, 'bounds_changed', function(){ var newgeo = map.get('center'); var newzoom = map.get('zoom'); centerPosition(newgeo,newzoom); }); } // Onload handler to fire off the app. google.maps.event.addDomListener(window, 'load', initialize); </script> <!-- Fixed navbar --> <div class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Project name</a> </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li class="active"><a href="#">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#contact">Contact</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="#">Action</a></li> <li><a href="#">Another action</a></li> <li><a href="#">Something else here</a></li> <li class="divider"></li> <li class="dropdown-header">Nav header</li> <li><a href="#">Separated link</a></li> <li><a href="#">One more separated link</a></li> </ul> </li> </ul> <ul class="nav navbar-nav navbar-right"> <li><a href="../navbar/">Default</a></li> <li><a href="../navbar-static-top/">Static top</a></li> <li class="active"><a href="./">Fixed top</a></li> </ul> </div><!--/.nav-collapse --> </div> </div> <div class="container"> <!-- Main component for a primary marketing message or call to action --> <div class="jumbotron"> <h1>Navbar example</h1> <p>This example is a quick exercise to illustrate how the default, static and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p> <p>To see the difference between static and fixed top navbars, just scroll.</p> <p> <a class="btn btn-lg btn-primary" href="../../components/#navbar" role="button">View navbar docs »</a> </p> <p> <ul id="topmenu"> <li><a href="default.php">Add marker</a></li> <li><a href="default2.php">View markers</a></li> </ul> <div id="container"> <div id="mapCanvas"></div> <div id="infoPanel"> <br /> <div id="markerStatus"></div> <div id="info"></div> <div id="geot"></div> <form id="form1" name="form1" action="add.php" method="post"> <input type="hidden" name="newcenter" id="mcenter1" value="mcenter1"> <input type="hidden" name="newzoom" id="mzoom1" value="mzoom1"> <input type="hidden" id="rsLat" name="rsLat" size="18"> <br /> <input type="hidden" id="rsLong" name="rsLong" size="18"> <br /> Name: <input type="text" id="rsname" name="rsPubName"><br /> <b>Category:</b> <select id="rscategory" name="rscategory"> <option id="GreatView" value="Great View">Great view</option> <option id="cafe" value="Cafe">Cafe</option> <option id="pub" value="Pub">Pub</option> <option id="restaurant" value="Restaurant">Restaurant</option> <option id="theatre" value="Theatre">Theatre</option> <option id="venue" value="Venue">Venue</option> <option id="landmark" value="Landmark">Landmark</option> <option id="poi" value="Place of Interest">Place of Interest</option> <option id="hiddenmsg" value="Hidden Message">Hidden Message</option> <option id="secretspot" value="Secret Spot">Secret Spot</option> <option id="hiking" value="Hiking">Hiking</option> <option id="hiking" value="Camping">Camping</option> <option id="dogfriendly" value="Dog Friendly">Dog Friendly</option> <option id="valueformoney" value="Value for money">Value for money</option> <option id="streetview" value="Street View">Interesting street view</option> </select> <br /> Description: <textarea id="desc" name="rsdesc" ></textarea> Address: <textarea id="address" name="rsAddress" ></textarea> <input type="hidden" id="wlat" name="rslat" size="10"><br /> <input type="hidden" id="wlon" name="rslng" size="10"><br /> City: <textarea id="city" name="rsTown" ></textarea><br /> <textarea id="country" name="rsCounty" ></textarea><br /> <div class="telephone"> Telephone: <input type="text" name="rsTel"> </div> <div class="website"> Website: <input type="text" name="rsWebsite"> </div> <input type="submit" name="submit" value="Pin Your Location"> </form> <br /><br /> <!-- <b>Current map center:</b> <div id="mcenter"></div> <div style="float:left;"><b>Current map zoom level: </b></div><div id="mzoom" style="float:left;"></div> <div style="clear:both;"></div> --> <!-- <form id="form2" name="form2" method="post" action="center.php"> <input type="hidden" name="newcenter" id="mcenter2" value="mcenter2"> <input type="hidden" name="newzoom" id="mzoom2" value="mzoom2"> <input type="submit" name="submit" value="Center Marker On Map"> </form> <div style="width:300px; font-size:10pt; color:#999; text-align:justify;">'Center Marker On Map' ... This uses cookies to remember location and zoom level.</div> --> </div> </div> </p> </div> </div> <!-- /container --> <script src="../../dist/js/bootstrap.min.js"></script> <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> <script src="js/ie10-viewport-bug-workaround.js"></script> </body> </html> Hi Guys. Trying to pass variables from the javascript into my php script and into my SQL query so i can track the location of the iphone. So far i have... Code: <script type="text/javascript"> function getGPS() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showGPS, gpsError); } else { gpsText.innerText = "No GPS Functionality."; } } long = position.coords.longitude; lat = position.coords.latitude; function gpsError(error) { alert("GPS Error: "+error.code+", "+error.message); } function showGPS(position) { gpsText.innerHTML = "<?php $long = "".$_GET['long'].""; $lat = "".$_GET['lat'].""; $sqldel = "INSERT INTO `location` (`id` ,`user_id` ,`long` ,`lat`) VALUES (NULL , '$user', '$long','$lat' );"; mysql_query($sqldel) or die(mysql_error()); echo "$long"; echo "$lat"; ?>"; } </script> This gets the coordinates in javascript and the php runs and i get a new record in the database but it doesnt pass the variables from java to php. Anyone know a workaround to get the variables from the iphone to sql on a single page? I want this to run in the background and refresh every now and then so i can track users location. thanks. Adam. Hi everyone In this snippet the addresses stored in address[] is geocoded using google maps API. The problem comes when i try to pass these values on to the array flightPlanCoordinates to create a polyline. Nothing happens. Can anyone tell me why? PS. Im quite new to JS Code: var flightPlanCoordinates = []; for ( var i=0, len=address.length; i<len; ++i ){ geocoder.geocode( { 'address': address[i]}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { flightPlanCoordinates.push( new google.maps.LatLng( parseFloat(results[0].geometry.location.lat()), parseFloat(results[0].geometry.location.lng()) ) ); } }); } var flightPath = new google.maps.Polyline({ path: flightPlanCoordinates, strokeColor: "#000000", strokeOpacity: 1.0, strokeWeight: 3 }); flightPath.setMap(map); Hello, I'm more looking for advice but any helpful examples would be great. So basically what I need to accomplish is a grid, that I can drop objects into, then save the coordinates. So let's say I have a 3x3 set of tiles which will represent "floor tiles", and I load from my MySql database a users "furniture", what's the best method of being able to take these dynamic items drop them on a tile which can be then saved in an xml file or something. What are the best j/s libraries for this? I know jQuery and mootools have drag and drop functions but can they accomplish what I'm looking for? Any feedback will help, I'm comfortable coding in js but I want to do it effeciently and there's got to be people who have done similar things. This is what my code is supposed to do: 1. create a select list that changes the photo showing, (which I have) 2. create script so that when the user hovers over the image it shows a div 3. when the users mouse is off the image/div shows the coordinates where it last left 4. on mouseout hides the div again (this is the part I'm stuck on) This is my html: Code: <style> #selectdiv { position:absolute; left:10px; top:10px; width:400px; height:400px; } #mylist { position: absolute; left: 200px; top: 100px; width:inherit; height:inherit; } #myyellow { position: absolute; left: 600px; top: 100px; width:300px; height:200px; background-color:#FF3; } </style> <body> <div id="selectdiv"> <h1 style="font-size:28px">Select a Beatle</h1> <select name="beatles" size="1" id="myselect" onchange="showDiv();"> <option value="-">-</option> <option value="J">John</option> <option value="P">Paul</option> <option value="G">George</option> <option value="R">Ringo</option> </select> </div> <div id="mylist" style="display:none" onmouseover="showYellow(event);" onmouseout="showpixels(event)"></div> <div id="John" style="display:none"> <img src="beatles_john.jpg" /> </div> <div id="Paul" style="display:none"> <img src="beatles_paul.jpg" /> </div> <div id="George" style="display:none"> <img src="beatles_george.jpg" /> </div> <div id="Ringo" style="display:none"> <img src="beatles_ringo.jpg" /> </div> <div id="myyellow" style="display:none"></div> <div id="msg"></div> </body> This is my script: Code: function showDiv() { var mySelect = document.getElementById("myselect"); var myList = document.getElementById("mylist"); switch (mySelect.value) { case 'J': myDiv = document.getElementById("John"); myList.innerHTML = myDiv.innerHTML; myList.style.display = "block"; //Makes div viewable break; case 'P': myDiv = document.getElementById("Paul"); myList.innerHTML = myDiv.innerHTML; myList.style.display = "block"; //Makes div viewable break; case 'G': myDiv = document.getElementById("George"); myList.innerHTML = myDiv.innerHTML; myList.style.display = "block"; //Makes div viewable break; case 'R': myDiv = document.getElementById("Ringo"); myList.innerHTML = myDiv.innerHTML; myList.style.display = "block"; //Makes div viewable break; } } function showYellow(event) { var myyellow = document.getElementById("myyellow"); myyellow.style.display = "block"; } function showpixels(event) { x=event.clientX y=event.clientY var myMsg = document.getElementById("msg"); myMsg.innerHTML = "X coords: " + x + ", Y coords: " + y; } Any feed back is greatly appreciated. I search through the forums and google but didn't find anything on this, but I was wondering if anyone was having or has had issues with google maps changing their lat/long coordinates, even when a frozen version is declared? Code: <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script> In the geocoding portion: Code: geocoder.geocode({'address': query}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var coordinates = results[0].geometry.location; point.latitude = coordinates['oa']; point.longitude = coordinates['pa']; return callback(); } else { var error = new Object(); error.message = 'We were unable to locate your latitude and longitude. Please check your address and try again.<br />'; error.callback = function(){}; return point.errorHandler(error); } }); The coordinates variable keeps changing the key. Originally it was: Code: point.latitude = coordinates['xa']; point.longitude = coordinates['ya']; Then: (and several others) Code: point.latitude = coordinates['sa']; point.longitude = coordinates['ta']; Now: Code: point.latitude = coordinates['oa']; point.longitude = coordinates['pa']; Why if a frozen version is declared, is this still changing? Hi all, I have a div element (i.e. <div id="main">) that contains a number of links, each with white background colors and its top and left style properties set to different values. I need to do several things with the anchors when they are clicked: When a white anchor is clicked, its background color is turned yellow and its coordinates (top and left style property values) are added to an array. The coordinates for a single anchor is to be separated by a hyphen; coordinates for multiple anchors are to be separated by a comma (eg. "0-9,0-18") When a yellow anchor is clicked, its background color is turned white and its coordinates are removed from the array. The values in the array are to be the value for a hidden input element, all separated by commas. I'm a Javascript novice and don't know where to begin. Can someone help me with this? Thanks in advance, Dude-Dastic Hello, i'm working on a 3 page survey. When hitting next, previous, or submit it passes the values of all the questions to the next page. I've got the whole thing working correcting except for one thing: When the box is "not" checked it passes no value. I'm needing it to have a value of "1" when checked and a value of "0" when not checked, and currently when its not checked and i pass the info it leaves it blank. I'd post the whole code to one of the pages but it's long , so i'll post the snipits of the code. Code: <script type="text/javascript"> /* <![CDATA[ */ function processQueryString() { var formData = location.search; formData = formData.substring(1, formData.length); while (formData.indexOf("+") != -1) { formData = formData.replace("+", " "); } formData = unescape(formData); var formArray = formData.split("&"); for (var i=0; i < formArray.length; ++i) { //document.writeln(formArray[i] + "<br />"); var sDataName = formArray[i].split("=") switch (sDataName[0]) { case ".lib_use": for (var j=0; j < document.getElementsByName(".lib_use").length; ++j) { if (document.getElementsByName(".lib_use").item(j).value == sDataName[1]) { document.getElementsByName(".lib_use").item(j).checked = true; //alert("lib_use set"); } } break; case ".lib_comp": if (sDataName[1] == 1) { document.getElementsByName(".lib_comp").checked = true; document.getElementsByName(".lib_comp").value= 1; } else { document.getElementsByName(".lib_comp").checked = false; document.getElementsByName(".lib_comp").value= 0; } break; default: alert("not caught = " + sDataName[0]); continue; } } } /* ]]> */ </script> <input type="checkbox" name=".lib_comp" id="lib_comp" value="1" /> The first case that i showed in my code is a radio button, and it passes correctly, i just wanted to show the "format" i was using in a working sense. The 2nd case is an example of the check boxes. Thanks for looking at this, and giving any suggestions you might have! Hi guys, Hopefully a really quick question. I'm a JS novice, and am looking for a way to output the coordinates of a Google maps marker into the value of two text fields, one for latitude and one for longitude. The code below is a simple location search which returns a result with a draggable marker. Currently, the coordinates in both text fields update when the location search is performed, but not when the marker is dragged to a new location afterwards. Does anyone know the code to simply update the coordinates each time the marker is dropped on a new location? Code: <html> <head> <style type="text/css"> #map_canvas { width:444px; height:444px; overflow:hidden; } </style> <script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAA-Kl-tQOj5PlnOlXQmp2N9hTg6Fn61x9hOlvMvn6kV4ENK8yRfBShRuj-nulocuk2Alx9JmFKKV4zwA" type="text/javascript"></script> <script type="text/javascript"> var map; var geocoder; function initialize() { map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(52.8068752, -1.6430344),6); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.enableScrollWheelZoom(); geocoder = new GClientGeocoder(); // Update current position info } // addAddressToMap() is called when the geocoder returns an // answer. It adds a marker to the map with an open info window // showing the nicely formatted version of the address and the country code. function addAddressToMap(response) { map.clearOverlays(); if (!response || response.Status.code != 200) { alert("Whoops, we couldn't find that address!"); } else { place = response.Placemark[0]; point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); marker = new GMarker(point,{draggable:true}); map.addOverlay(marker); marker.openInfoWindowHtml(place.address + '<br /><span class="smallgrey">Zoom in and drag the marker to exactly where the point is</span>'); document.getElementById("latitude").value = point.lat(); document.getElementById("longitude").value = point.lng(); } } // showLocation() is called when you click on the Search button // in the form. It geocodes the address entered into the form // and adds a marker to the map at that location. function showLocation() { var address = document.forms[0].q.value; geocoder.getLocations(address, addAddressToMap); } // findLocation() is used to enter the sample addresses into the form. function findLocation(address) { document.forms[0].q.value = address; showLocation(); } </script> </head> <body onload="initialize()"> <form action="#" onsubmit="showLocation(); return false;"><input type="text" name="q" size="35" /> <input type="submit" name="find" value="Search"/></form> <div id="map_canvas">And pin the <strike>tail</strike> marker on the <strike>donkey</strike> map:<br /></div> Latitude: <input class="required" type="text" name="latitude" id="latitude" value="53.34870686020199" /> <br /> Longitude: <input class="required" type="text" name="longitude" id="longitude" value="-6.267356872558594" /> </body> </html> Many thanks in advance, I appreciate anyone who wants to help out! Hi, I have what I assume started as a simple error and then trying to fix it I think I have made things so complicated I've become confused. I have two fields, a drop down list and a text field, when someone clicks on a value in a drop down list (I will show the results eventually but at the moment) I just want the result to echo in my getCategory.php and the same for the text field. Both php pages are currently being called. And at the moment contain $_REQUEST['category'] and $_REQUEST['ProductName'] respectively. Nothing is being echoed. I know the below code is wrong, but the more I try to correct it the worse it gets so I thought I would just leave it as is before I made it worse. Code: <script type="text/javascript"> function loadXMLDoc1(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> </head> <body> <label>Search by Category: </label> <select name="category" id="category" onchange='loadXMLDoc1("getCategory.php","txtHint","category")' class="input"> <option value="please select" selected"selected">Please Select</option> <option value="Clothes" name="Clothes" id="Clothes">Clothes</option> <option value="Bags" name="Bags" id="Bags">Bags</option> <option value="Hats" name="Hats" id="Hats">Hats</option> </select> <br /> <br /> <label>Search by name: </label> <input type="text" class="input" name="ProductName" id="ProductName" value="Search" size="30"/> <input type="button" value="Search" onclick="loadXMLDoc1('getProductName.php','txtHint', ProductName='(this.value)')" /> <br /> <br /> <div id="txtHint"></div> Dear all, I'm passing the variables myTitle and myLink to form.php using javascript. This is the way I'm doing it: Code: <a href='form.php?title=" + myTitle +"&link="+myLink+">Click me</a> It's working great but sometimes myTitle and myLink contain the plus character (+). When this happens it's not passed. In the case of the title, it's just a problem of looks but in the case of the link, well, the link won't work without the character. As an example if the title is: Laptop + Accessories What is passed is: Laptop Accessories What can I do to pass also the plus character?? Thanks a lot!! Hi. I'm writing a script that graphs data in different colors and shapes and I'm encountering two problems: (1) I can't specify different colors for the graph I'm rendering. If I use fillStyle="red"; then the entire chart becomes red. It seems to use the last color specified as the color for everything on the chart. (2) The shapes are overlapping in strange ways. The fills are not covering the lines of shapes behind them so it's unclear which shape is in front and which is behind. It's like they aren't being treated as separate shapes but instead one shape where boundaries are unclear. I don't know how else to explain it. I'm hoping there is some way to put each shape in its own layer. Would I have to use DIV IDs for that or is there a way to keep it all in the script so it's more scalable? Hi, I am trying to develop a quiz system.Here is a simplified version of my code with lots of modifications made mainly for easier comprehension. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <script type="text/javascript"> var count=3; var questions = new Array(3); for (var i = 1; i <=count; i++) { questions[i] = "Question "+String(i); } </script> <script type="text/javascript"> /* Global "swap" holder Use value, null, if no layer initially visible */ var currlayerId = "question1"; function toglayer(id) { if(currlayerId) setDisplay(currlayerId, "none"); if(id)setDisplay(id, "block"); currlayerId = id; } function setDisplay(id,value) { var elm = document.getElementById(id); elm.style.display = value; } </script> <style type="text/css" media="screen, print, projection"> .text { display:none; } </style> </head> <body> <li><a href="#" onclick="toglayer('question1');return false;">Q.1</a></li> <li><a href="#" onclick="toglayer('question2');return false;">Q.2</a></li> <li><a href="#" onclick="toglayer('question3');return false;">Q.3</a></li> <div id="question1" class="text"> <script>document.write(questions[1]);</script> <br> </div> <div id="question2" class="text"> <script>document.write(questions[2]);</script> </div> <div id="question3" class="text"> <script>document.write(questions[3]);</script> </div> <script>toglayer('question1');</script> </body> </html> When you will run the code,you will find three links Q.1 Q.2 Q.3 These links are basically due to the following code Code: <li><a href="#" onclick="toglayer('question1');return false;">Q.1</a></li> <li><a href="#" onclick="toglayer('question2');return false;">Q.2</a></li> <li><a href="#" onclick="toglayer('question3');return false;">Q.3</a></li> When you click on any of the links,you will see the question associated with it.This is because of the following code Code: <div id="question1" class="text"> <script>document.write(questions[1]);</script> <br> </div> <div id="question2" class="text"> <script>document.write(questions[2]);</script> </div> <div id="question3" class="text"> <script>document.write(questions[3]);</script> </div> -------------------------------------------------------------------------------------- Now,here's the question,how do I put the div layers and their links in a loop.That is,I want it to be something like this Code: (for var i=1;i<=count;i++) { <li><a href="#" onclick="toglayer('question[i]');return false;">Q.[i]</a></li> } Code: (for var i=1;i<=count;i++) { <div id="question[i]" class="text"> <script>document.write(questions[i]);</script> <br> </div> } The reason why I ask this is,is because the number of questions in the quiz depends on the value of the javascript variable "count".Therefore,if the value of count is 5,the number of questions would be 5,if it is 6 the number of questions will be 6,etc. Thanks Hemant I searched long and hard for an example of how to do this but couldn't find anything similar, even after searching a good number of other forums. Below is a script I have that displays a list of summary info for multiple people. When you mouse over some ones summary info, a bio appears below that summary info (pushing everything below it down). What I'd like to do is take it further and allow more layers. For example, when you hover over their bio, more info about them pops up below that, and so on. I know you're probably tired of seeing mousevent/text questions but I'm desperate at this point. If some one could just add a mouseover event to the bio section that displayed more text below it would suffice and I could take it from there. Heres the code: Code: <p> <script type="text/javascript"> var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS"; }, searchString: function (data) { for (var i = 0; i < data.length; i++) { var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity; } else if (dataProp) return data[i].identity; } }, searchVersion: function (dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) return; return parseFloat(dataString.substring(index + this.versionSearchString.length + 1)); }, dataBrowser: [ { string: navigator.userAgent, subString: "Chrome", identity: "Chrome" }, { string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" }, { string: navigator.vendor, subString: "Apple", identity: "Safari", versionSearch: "Version" }, { prop: window.opera, identity: "Opera" }, { string: navigator.vendor, subString: "iCab", identity: "iCab" }, { string: navigator.vendor, subString: "KDE", identity: "Konqueror" }, { string: navigator.userAgent, subString: "Firefox", identity: "Firefox" }, { string: navigator.vendor, subString: "Camino", identity: "Camino" }, { // for newer Netscapes (6+) string: navigator.userAgent, subString: "Netscape", identity: "Netscape" }, { string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE" }, { string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" }, { // for older Netscapes (4-) string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla" } ], dataOS: [ { string: navigator.platform, subString: "Win", identity: "Windows" }, { string: navigator.platform, subString: "Mac", identity: "Mac" }, { string: navigator.userAgent, subString: "iPhone", identity: "iPhone/iPod" }, { string: navigator.platform, subString: "Linux", identity: "Linux" } ] }; BrowserDetect.init(); //Declaring Variables to be used later var staff_members = -1; var max_staff_members = 9; var staff_name_array = new Array(); //Array of strings var staff_title_array = new Array(); //Array of strings var staff_length_array = new Array(); //Array of strings var staff_info_array = new Array(); //Array of strings var staff_array = new Array(); //Array of strings var staff_id_array = new Array(); //Array of answer IDs var image_source_array = new Array(); //Array of full html code, for images var staff_start = new Array(); //Array of starting pos for staff bios var staff_end = new Array(); //Array of ending pos for staff bios var start_span = '<span style="font-size: 12px;">'; var end_span = '</span>'; var img_start_str = "<img alt="; var img_end_str = '">'; //"border-style: solid;";//Followed by " /> var img_end_str_len = 3; //24; function init() { remove_staff_tag(); for (i = 0; i < staff_members; i++) { staff_name_array[i] = "" } for (i = 0; i < staff_members; i++) { staff_title_array[i] = "" } for (i = 0; i < staff_members; i++) { staff_length_array[i] = "" } for (i = 0; i < staff_members; i++) { staff_info_array[i] = pull_bio(i) } for (i = 0; i < staff_members; i++) { staff_array[i] = start_span + staff_name_array[i] + //"<br/> " + staff_title_array[i] + //"<br/> " + staff_length_array[i] + //"<br/> " + staff_info_array[i] + end_span; //"<br/> " + } for (i = 0; i < staff_array.length; i++) { staff_id_array[i] = "emp_bio_long_" + (i); } remove_unused_staff(); } function remove_staff_tag() { var ret = document.getElementById("div_tag").innerHTML; var ind = ret.indexOf("(max 9):["); var text_after_num = ret.substring(ind + 8); staff_members = liferay_workaround("," + ret.substring(ind + 9, ind + 10)); document.getElementById("div_tag").innerHTML = text_after_num.substring(8); } function remove_unused_staff() { var div_html = document.getElementById("div_tag").innerHTML; for (i = 0; i < max_staff_members; i++) { staff_start[i] = div_html.indexOf("emp_bio_short_" + i) - 29; staff_end[i] = div_html.indexOf("Bio " + (i + 1) + " End") - 26; } end_pos = staff_end[staff_members - 1]; document.getElementById("div_tag").innerHTML = div_html.substring(0, end_pos); } function pull_bio(emp_num) { var ret = document.getElementById("emp_bio_long_" + emp_num).innerHTML; var len = ret.length; var img_start_pos = ret.indexOf(img_start_str); var img_end_pos = ret.indexOf(img_end_str); return ret; } function set_all_bios() { for (i = 0; i < staff_memebrs; i++) { staff_info_array[i] = "changed"; } } function pull_pic_test(emp_num) { var ret = document.getElementById("emp_bio_long_" + emp_num).innerHTML; var img_start_pos = ret.indexOf(img_start_str); var img_end_pos = ret.indexOf(img_end_str); var ret2 = ret.substring(img_start_pos, img_end_pos + img_end_str_len); return ret2; } function get_bio(emp_num) { return staff_array[emp_num]; } function clear_all_bios() { for (i = 0; i < staff_id_array.length; i++) { document.getElementById(staff_id_array[i]).innerHTML = ''; } } function change_text(id_to_change, value_to_change_to) { clear_all_bios(); document.getElementById(id_to_change).innerHTML = value_to_change_to; } function liferay_workaround(almost_number) { var adj = false; if (almost_number == ",0") { almost_number = 0; adj = true; } if (almost_number == ",1") { almost_number = 1; adj = true; } if (almost_number == ",2") { almost_number = 2; adj = true; } if (almost_number == ",3") { almost_number = 3; adj = true; } if (almost_number == ",4") { almost_number = 4; adj = true; } if (almost_number == ",5") { almost_number = 5; adj = true; } if (almost_number == ",6") { almost_number = 6; adj = true; } if (almost_number == ",7") { almost_number = 7; adj = true; } if (almost_number == ",8") { almost_number = 8; adj = true; } if (almost_number == ",9") { almost_number = 9; adj = true; } if (!adj) { almost_number = 1; } return almost_number; } </script></p> <div class="faq-content" id="div_tag"> <p id="staff_num"> Enter number of staff members within the brackets (max 9):[4]</p> <p class="emp_bio_short" id="emp_bio_short_0" onmouseout="" onmouseover="change_text('emp_bio_long_0', get_bio(0))" style="text-align: left;"> <span style="font-size: 12px;"><strong>Employee Name:</strong> Name<br /> <strong>Title: </strong>President & General Manager<br /> <strong>Length of Time with Company: </strong>18 years</span></p> <p class="answer" id="emp_bio_long_0" style="text-align: left;"> [<span style="font-size: 12px;">[You may edit this text to match the intended biography but leave the brackets]</span>]</p> <!---------------------- Bio 1 End --------------------------><!---------------------- Bio 2 --------------------------> <p class="emp_bio_short" id="emp_bio_short_1" onmouseout="" onmouseover="change_text('emp_bio_long_1', get_bio(1))" style="text-align: left;"> <span style="font-size: 12px;"><strong>Employee Name: </strong>Name<br /> <strong>Title: </strong>President & General Manager<br /> <strong>Length of Time with Company: </strong>5 years</span></p> <p class="answer" id="emp_bio_long_1" style="text-align: left;"> [<span style="font-size: 12px;">[You may edit this text to match the intended biography but leave the brackets]</span>]</p> <!---------------------- Bio 2 End --------------------------><!----------------------- Bio 3 --------------------------> <p class="emp_bio_short" id="emp_bio_short_2" onmouseout="" onmouseover="change_text('emp_bio_long_2', get_bio(2))" style="text-align: left;"> <span style="font-size: 12px;"><strong>Employee Name: </strong>Name<br /> <strong>Title: </strong>President & General Manager<br /> <strong>Length of Time with Company: </strong>6 years</span></p> <p class="answer" id="emp_bio_long_2" style="text-align: left;"> [<span style="font-size: 12px;">[You may edit this text to match the intended biography but leave the brackets] </span>]</p> <!---------------------- Bio 3 End --------------------------><!----------------------- Bio 4 --------------------------> <p class="emp_bio_short" id="emp_bio_short_3" onmouseout="" onmouseover="change_text('emp_bio_long_3', get_bio(3))" style="text-align: left;"> <span style="font-size: 12px;"><strong>Employee Name: </strong>Name<br /> <strong>Title: </strong>President & General Manager<br /> <strong>Length of Time with Company:</strong> 5 years</span></p> <p class="answer" id="emp_bio_long_3" style="text-align: left;"> [<span style="font-size: 12px;">[You may edit this text to match the intended biography but leave the brackets] </span>]</p> <!----------------------- Bio 4 End --------------------------><!----------------------- Bio 5 --------------------------> <p class="emp_bio_short" id="emp_bio_short_4" onmouseout="" onmouseover="change_text('emp_bio_long_4', get_bio(4))" style="text-align: left;"> <span style="font-size: 12px;"><strong>Employee Name:</strong> Name<br /> <strong>Title: </strong>John Smith's Title<br /> <strong>Length of Time with Company: </strong>0 years</span></p> <p class="answer" id="emp_bio_long_4" style="text-align: left;"> [You may edit this text to match the intended biography but leave the brackets]</p> <!----------------------- Bio 5 End --------------------------><!----------------------- Bio 6 --------------------------> <p class="emp_bio_short" id="emp_bio_short_5" onmouseout="" onmouseover="change_text('emp_bio_long_5', get_bio(5))" style="text-align: left;"> <span style="font-size: 12px;"><strong>Employee Name:</strong> Name<br /> <strong>Title: </strong>John Smith's Title<br /> <strong>Length of Time with Company: </strong>0 years</span></p> <p class="answer" id="emp_bio_long_5" style="text-align: left;"> [You may edit this text to match the intended biography but leave the brackets]</p> <!----------------------- Bio 6 End --------------------------><!----------------------- Bio 7 --------------------------> <p class="emp_bio_short" id="emp_bio_short_6" onmouseout="" onmouseover="change_text('emp_bio_long_6', get_bio(6))" style="text-align: left;"> <span style="font-size: 12px;"><strong>Employee Name:</strong> Name<br /> <strong>Title: </strong>John Smith's Title<br /> <strong>Length of Time with Company: </strong>0 years</span></p> <p class="answer" id="emp_bio_long_6" style="text-align: left;"> [You may edit this text to match the intended biography but leave the brackets]</p> <!---------------------- Bio 7 End --------------------------><!----------------------- Bio 8 --------------------------> <p class="emp_bio_short" id="emp_bio_short_7" onmouseout="" onmouseover="change_text('emp_bio_long_7', get_bio(7))" style="text-align: left;"> <span style="font-size: 12px;"><strong>Employee Name:</strong> Name<br /> <strong>Title: </strong>John Smith's Title<br /> <strong>Length of Time with Company: </strong>0 years</span></p> <p class="answer" id="emp_bio_long_7" style="text-align: left;"> [You may edit this text to match the intended biography but leave the brackets]</p> <!----------------------- Bio 8 End --------------------------><!----------------------- Bio 9 --------------------------> <p class="emp_bio_short" id="emp_bio_short_8" onmouseout="" onmouseover="change_text('emp_bio_long_8', get_bio(8))" style="text-align: left;"> <span style="font-size: 12px;"><strong>Employee Name:</strong> Name<br /> <strong>Title: </strong>John Smith's Title<br /> <strong>Length of Time with Company: </strong>0 years</span></p> <p class="answer" id="emp_bio_long_8" style="text-align: left;"> [You may edit this text to match the intended biography but leave the brackets]</p> <!----------------------- Bio 9 End --------------------------><!---------------------- Bio 10 --------------------------> <p class="emp_bio_short" id="emp_bio_short_9" onmouseout="" onmouseover="change_text('emp_bio_long_9', get_bio(9))" style="text-align: left;"> <span style="font-size: 12px;"><strong>Employee Name:</strong> Name<br /> <strong>Title: </strong>John Smith's Title<br /> <strong>Length of Time with Company: </strong>0 years</span></p> <p class="answer" id="emp_bio_long_9" style="text-align: left;"> [You may edit this text to match the intended biography but leave the brackets]</p> <!----------------------- Bio 10 End --------------------------></div> <p> <script type="text/javascript"> init(); change_text('emp_bio_long_0', get_bio(0)) </script></p> Hello to all. I am a new to the forum and new to Javascript, so please be gentle. I have a web page in which I am using a script to toggle between div tags. I learned how to set it up for only a few divs, but want to use more than 10+ div tags with the corresponding buttons on the side. When I set it up with 11 buttons, the 10th button does not work, but all of the single digit buttons do. (The 11th button is going to be a hyperlink eventually.) Here is the code for anyone who can help: <code> <script language="javascript" type="text/javascript"> function Button(obj) { var cls = obj.className; if(cls!='Btn_Selected') { if(cls=='Btn') { cls = 'Btn_Highlight'; } else { cls = 'Btn'; } } obj.className = cls; } function select(obj) { for (var x = 1; x <= 10; x++) { document.getElementById("Button"+x).className = 'Btn'; document.getElementById("Content"+x).style.display = 'none'; } obj.className='Btn_Selected'; var tmp = obj.id; var num = tmp.substr(tmp.length-1); document.getElementById("Content"+num).style.display = 'block'; } 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> </code> Hopefully I was clear with what I am looking to achieve. If I need to attach additional code or a link to the web page, let me know. Any help would be greatly appreciated. Thanks All in advance, ScottoNM Hello, I'm new to the forum. I tried coding this myself, but i'm just not that well versed in javascript and need a little help. I am trying to show certain div tags when you click on a hyperlink in an html document. I have four links (bio, news, portfolio, and resume) and four div tags (bio, news, portfolio, and resume). I am just going to show the code for one of the links. This is what I have for the bio link in the head of the html: Code: function setVisible( setting ) { var myElement = document.getElementById("bio"); if(setting) myElement.style.visibility="visible"; else myElement.style.visibility="hidden"; } </script> This is what I have in the style sheet: Code: #bio { position: absolute; font: 9pt arial; line-height: 10.5pt; color: #fff; width: 575px; height: 300px; margin-top: 390px; margin-right: auto; margin-left: 40px; margin-bottom: 5px; z-index: 1; border: 0px solid #fff; } This is what I have on the link in the html doc (I'm assuming this is wrong, I don't know what the proper code should be): Code: <a href="javascript:onClick="setVisible(true)";">BIO</a> Does what I'm trying to do make sense? I'm assuming that it would be the same set up for all four links? Please let me know if I need to be more specific. Any help would GREATLY be appreciated! Thank you, Gerry Usually I can find what I need by doing a Googlesearch. This time, I can't seem to find anything. I need a crossbrowser method for moving layers around the screen. So simple an idea! If it helps answer my query, here is the js for what I have already (a sort of horrible mess that works in IE): PS - I can live with a jquery solution! Code: <!-- function MM_findObj(n, d) { //v3.0 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); return x; } function MM_dragLayer(objName,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v3.0 //Copyright 1998 Macromedia, Inc. All rights reserved. var i,j,aLayer,retVal,curDrag=null,NS=(navigator.appName=='Netscape'), curLeft, curTop; if (!document.all && !document.layers) return false; retVal = true; if(!NS && event) event.returnValue = true; if (MM_dragLayer.arguments.length > 1) { curDrag = MM_findObj(objName); if (!curDrag) return false; if (!document.allLayers) { document.allLayers = new Array(); with (document) if (NS) { for (i=0; i<layers.length; i++) allLayers[i]=layers[i]; for (i=0; i<allLayers.length; i++) if (allLayers[i].document && allLayers[i].document.layers) with (allLayers[i].document) for (j=0; j<layers.length; j++) allLayers[allLayers.length]=layers[j]; } else for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i];} curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT; curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT; curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront; curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS; curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS; curDrag.MM_oldZ = (NS)?curDrag.zIndex:curDrag.style.zIndex; curLeft= (NS)?curDrag.left:curDrag.style.pixelLeft; curDrag.MM_startL = curLeft; curTop = (NS)?curDrag.top:curDrag.style.pixelTop; curDrag.MM_startT = curTop; curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop -cU; curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop +cD; curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS! document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer; if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP); } else { var theEvent = ((NS)?objName.type:event.type); if (theEvent == 'mousedown') { var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft; var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop; var maxDragZ=null; document.MM_maxZ = 0; for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i]; var aLayerZ = (NS)?aLayer.zIndex:aLayer.style.zIndex; if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ; var isVisible = (((NS)?aLayer.visibility:aLayer.style.visibility).indexOf('hid') == -1); if (aLayer.MM_dragOk != null && isVisible) with (aLayer) { var parentL=0; var parentT=0; if (!NS) { parentLayer = aLayer.parentElement; while (parentLayer != null && parentLayer.style.position) { parentL += parentLayer.offsetLeft; parentT += parentLayer.offsetTop; parentLayer = parentLayer.parentElement; } } var tmpX=mouseX-(((NS)?pageX:style.pixelLeft+parentL)+MM_hLeft); var tmpY=mouseY-(((NS)?pageY:style.pixelTop +parentT)+MM_hTop); var tmpW = MM_hWidth; if (tmpW <= 0) tmpW += ((NS)?clip.width :offsetWidth); var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += ((NS)?clip.height:offsetHeight); if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null || maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } } if (curDrag) { document.onmousemove = MM_dragLayer; if (NS) document.captureEvents(Event.MOUSEMOVE); curLeft = (NS)?curDrag.left:curDrag.style.pixelLeft; curTop = (NS)?curDrag.top:curDrag.style.pixelTop; MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop; document.MM_curDrag = curDrag; curDrag.MM_SNAPPED=false; if(curDrag.MM_toFront) { eval('curDrag.'+((NS)?'':'style.')+'zIndex=document.MM_maxZ+1'); if (!curDrag.MM_dropBack) document.MM_maxZ++; } retVal = false; if(!NS) event.returnValue = false; } } else if (theEvent == 'mousemove') { if (document.MM_curDrag) with (document.MM_curDrag) { var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft; var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop; newLeft = mouseX-MM_oldX; newTop = mouseY-MM_oldY; if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL); if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR); if (MM_bT!=null) newTop = Math.max(newTop ,MM_bT); if (MM_bB!=null) newTop = Math.min(newTop ,MM_bB); MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT; if (NS) {left = newLeft; top = newTop;} else {style.pixelLeft = newLeft; style.pixelTop = newTop;} if (MM_dragJS) eval(MM_dragJS); retVal = false; if(!NS) event.returnValue = false; } } else if (theEvent == 'mouseup') { document.onmousemove = null; if (NS) document.releaseEvents(Event.MOUSEMOVE); if (NS) document.captureEvents(Event.MOUSEDOWN); //for mac NS if (document.MM_curDrag) with (document.MM_curDrag) { if (typeof MM_targL =='number' && typeof MM_targT == 'number' && (Math.pow(MM_targL-((NS)?left:style.pixelLeft),2)+ Math.pow(MM_targT-((NS)?top:style.pixelTop),2))<=MM_tol) { if (NS) {left = MM_targL; top = MM_targT;} else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;} MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; } if (MM_everyTime || MM_SNAPPED) eval(MM_dropJS); if(MM_dropBack) {if (NS) zIndex = MM_oldZ; else style.zIndex = MM_oldZ;} retVal = false; if(!NS) event.returnValue = false; } document.MM_curDrag = null; } if (NS) document.routeEvent(objName); } return retVal; } //--> |