JavaScript - Possible To Have 2 Ajax Requests At The Same Time (long Polling)?
I'm trying to use long-polling for a chat program that I am developing. Currently, I have the following setup:
Code: var lpOnComplete = function(response) { // Do success stuff lpStart(); } var lpStart = function() { $.post('receive.php', {}, lpOnComplete, 'json'); }; $(document).ready(lpStart); receive.php will run until it times out (30 seconds) or gets new information. The problem is, I also need to post some data such as when a user updates their status or sends a message while the receive.php is running. However, I cannot post data until the receive.php request is finished processing. What is the best way to run 2 requests at the same time? Help is greatly appreciated. Similar TutorialsHi, I have long polling functionality working with Google Desktop Notifications. http://blog.perplexedlabs.com/2009/0...-long-polling/ However if I have multiple tabs open then the Notification received from the server is duplicated on every tab. Is there way to prevent this from happening as it should only appear once? Thanks I am making an app which will later on allow developers to make plugins for the user to add to his account, but I am starting to think this kind of thing is a security risk because my app is mostly based on ajax and for instance if my app asks the server to delete a file the server accepts, but how will it know if that request was sent by my app and not by a plugin? The plugins reside in iframes which javascript allows to send ajax requests to the domain of the page. I would really appreciate any help. thanks. Hello im using dhtmlx grid in this cells i have from time and to time (i.e ind==1 and ind==2) i need to validate time where to-time must be greater than from-time else it should alert an message,i have writeen a normal Regular expression for the time validation.as the time is i string format i.e[05:00],please can any one send me code for that. Code: var err_str=""; function validate_grid(value,id,ind) { if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } Hi Code: var err_str=""; function validate_grid(value,id,ind) { $("#result").html(" ").show(); if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } alert(err-str); here ind==1 is from_time and ind==2 is to_time,i need to validate time as to_time must be always greater than from-time,if condition fails an alert msg should populate.time format is[05:00]as it is in string format im unable to do the validation for it.(ex:from-time=08:00 to-time=07:59 condition fails) thank you. hi im using dhtml xgrid where i need to do validation for time ,(from-time and to-time i.e ind==1 and ind==2 ) to-time must be greater than from-time else i need to alert a message to-time must be greater than from-time. can any one send me the code for it time format is[05:00]. Code: var err_str=""; function validate_grid(value,id,ind) { $("#result").html(" ").show(); if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } Hi, I am hoping I just need to be pointed in the right direction with this. I have Page1. When Page1 body onloads it uses Ajax to call PartA Within PartA I have a message board so members can write messages which will be sent to my database in PartA[1] and immediately posted for view on to PartA[2]. As I want to have my request to the server updating regularly I want to have PartA[2] on a timed loop to refresh - I do not need the content of PartA[1] to refresh. So the order of events would look like this: Page1 | onload call | v PartA / \ V V PartA[1] PartA[2] (loads once) (constantly refreshes) What I am not sure about is that I have <body> and <head> attributes in Page1 only. I have already used my body onload to call PartA (and can't use it to call PartA[2] before PartA has loaded anyway). I do not want the user to have to click a button or do anything to call up PartA[2]. So my question is how would I get PartA[2] to automatically load within PartA? I hope I have made this clear, but if I haven't let me know and I will try again. 1 down vote favorite I do have the countdown script (see link below) to display the time between current time and the date given in real-time. However, I want to achieve to display the time difference between a given start and end time. Right now, it calculates from the current server time to the end time. I want to be able to set up my own start time and end time. Here is what I have: http://jsfiddle.net/BgEtE/ thank you for help Hello, I would like to create something like this: Practice mental arithmetic both the entire thing and multiple smaller programs that could be embedded into a web page that deal with specific problems, i.e. separate addition, subtraction etc. I have no knowledge of CSS, javascript etc. How long before I could do this? hi, can some one help me how to get the time and date difference? given two time and date with the following format like in textbox A: 2011-05-03 17:35:47.0 and textbox B: 2011-05-03 16:35:47.0 then the output would be: 0 days, 1 hour, 0 minutes, 0 seconds regards, verve I'm not really a Java writer, so I don't know how to do this myself, though I imagine it would be pretty simple. I am looking to add a script to a webpage that allows users to input a time manually, and have it converted to GMT/Zulu time and display the converted time. I have seen a lot of time zone conversion scripts online, but they all just convert whatever the current system time is to another time zone. I am looking for a script that allows users to convert a time and show the zulu time, for times other than the current time. The time zone the inputed local time would be in is +4:30 (Kabul). I don't really care about style or aestehtics, just a simple script I can insert into a web page to have a time input field. The converted output time can appear in another field, a popup bubble, etc, again style isn't really an issue. It's really just to help people in my job who need to know what the GMT/Zulu time was for certain local times after the fact. One would think it shouldn't be that hard to just subtract 4:30 in your head, but apparently it is. Sorry if just asking for code outright like this is frowned upon. How do you take a long number such as Math.PI and break it out into an array? For example: [3] [.] [1] [4] [1] [5] [9] I suppose that because of the decimal you would have to convert it into a string first? It would be ideal if I could keep the number as a number without converting it to a string, but I'm not sure if that's possible. Every thread I've found online so far seems to indicate that you need a delimiter between the string you want to split up - that you can't just put every character of a string into an array... but there must be a way. I'm new to Javascript and to these forums. All suggestions welcome. Thanks. 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> hello, i want to trim a word that too long.. example "I don't know what i will dooooooooooooooooooooooooooooooo now" how trim it with javascript function so i will get 'I don't know what i will doooo... now" any body help.. Regards, hi, in my code below, I need to change the line Code: map.setCenter(new GLatLng(i[0], i[1]), 13); to have the LAT and LONG from my database therefore, I think maybe I need to open a database connection (which I think i am on the same page) and put some ASP in my JavaScript?! Code: var i = geoCodes.split(","); if (GBrowserIsCompatible()) { if(eval(document.getElementById("mapping"))) { var map = new GMap2(document.getElementById("mapping")); map.setCenter(new GLatLng(i[0], i[1]), 13); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); Hi I have the following code which is created server side to convert postcodes from a database into coordinates. I'm fairly sure there's something in the javascript which is preventing all the postcodes from the code being converted. Does anyone have any ideas... This code has been taken from something else so could probably be tidied up a lot but every time I try it stops working. Thanks Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Geocoding UK Postcodes with Google APIs Demo</title> <script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=ABQIAAAAQJTCOfFBzEZfb0xYTu1h_BR0_9owy9VLLEJCKI_ZedHr-0NdXxQd9Q8sR1hC7s4PNGNVmIaTUQvspA" type="text/javascript"></script> <script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAQJTCOfFBzEZfb0xYTu1h_BR0_9owy9VLLEJCKI_ZedHr-0NdXxQd9Q8sR1hC7s4PNGNVmIaTUQvspA" type="text/javascript"></script> </head> <body> <div id="message"></div> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["PL14 4PW, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["EX10 0QN, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["BH19 3HG, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["CT18 8HB, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["NR9 4DD, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["BT94 5HF, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["FK17 8HY, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["SY7 9LT, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["LL58 8HU, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["SA62 3AL, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["DL8 3HQ, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> <script type="text/javascript"> var delay = 0; if (GBrowserIsCompatible()) { var geo = new GClientGeocoder(); function getAddress(search, next) { geo.getLocations(search, function (result) { if (result.Status.code == G_GEO_SUCCESS) { var p = result.Placemark[0].Point.coordinates; var lat=p[1]; var lng=p[0]; document.getElementById("message").innerHTML += lat+ ',' +lng+'<br />'; //This is the line to change... var point2 = new GLatLng(lat,lng); //Need to create this on the fly from the postcode in the database var marker2 = createMarker(point2,'rtyrty'); map.addOverlay(marker2); } next(); } ); } var addresses = ["YO18 8RE, UK"]; var nextAddress = 0; function theNext() { if (nextAddress < addresses.length) { setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay); nextAddress++; } else { } } theNext(); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> </body> </html> Hi All, In javascript is it possible to convert a long number (as hex string) to a float number ? Ex. 40 A0 00 D2 is 5.0001 and reverse I know I can use math functions, then seperate out Sign/mantissa/exponent and then convert it in float, but their must be some easy alternative. Can I use sprintf, is yes how can I use this? Thansk for your help! Regards Max Hi, I made some changes to the following example: http://docs.jquery.com/Plugins/validation#Example Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script> <style type="text/css"> * { font-family: Verdana; font-size: 96%; } label { width: 10em; float: left; } label.error { float: none; color: red; padding-left: .5em; vertical-align: top; } p { clear: both; } </style> <script> $(document).ready(function(){ $("#commentForm").validate(); }); </script> </head> <body> <form class="cmxform" id="commentForm" method="get" action=""> <fieldset> <legend>A simple comment form with submit validation and default messages</legend> <p> <input id="cname" name="name" size="25" class="required" value="Name" onfocus="if (this.value == 'Name') {this.value=''}" onblur="if(this.value == '') { this.value='Name'}" /> </p> <p> <input id="cemail" name="email" size="25" class="required email" value="Email" onfocus="if (this.value == 'Email') {this.value=''}" onblur="if(this.value == '') { this.value='Email'}" /> </p> <p> <input id="curl" name="url" size="25" class="url" value="URL" onfocus="if (this.value == 'URL') {this.value=''}" onblur="if(this.value == '') { this.value='URL'}" /> </p> <p> <textarea id="ccomment" name="comment" cols="35" rows="5" class="required" onfocus="if (this.value == 'Comment') {this.value=''}" onblur="if(this.value == '') { this.value='Comment'}">Comment</textarea> </p> <p> <input class="submit" type="submit" value="Submit"/> </p> </fieldset> </form> </body> </html> I know how to add custom validation methods for the required fields Name, Email, and Comment. But I just don't know how to validate the optional filed URL. I've searched everywhere to no avail! Any help is greatly appreciated! Desparate This is my first time doing JavaScript I don't what I did wrong here, but the problem its not showing up the current date and time. Code: <script language = "JavaScript" type="text/javascript"> now = new Date(); localtime = now.toString(); utctime = now.GMTString(); document.wite("<b>localtime</b>" + localtime + "</br>"); document.write("<b>utctime</b>" + utctime); </script> This is what supposed to look like I have tried using different browser chrome,IE9,Maxtor, and Opera my OS is Win7 Hi, i'm having a problem with calling a netbeans function through an URL, that saves data to a postgresql table that has 119 columns. This is the original link: Code: http://www.mirodinero.com:8080/mirodinero-war/setMisDatos?callback=respuestaGuardarMisDatos¶m=%26usuario%3DIsa%20Mirodinero%26nivel%3D109%26gano_sal_neto%3D211113.45%26gano_sal_prof%3D2480%26gano_monet%3D0%26gano_renta_fija%3D0%26gano_renta_vble%3D0%26gano_inmuebles%3D2226.75%26gano_otros%3D2223.73%26gano_otros_ing%3D2411.12%26porc_gano_monet%3D0%26porc_gano_rentaf%3D0%26porc_gano_rentav%3D0%26porc_gano_inm%3D2%26porc_gano_otros%3D2%26porc_gano_otros_ing%3D1%26gasto_casa1%3D1306.46%26gasto_casa2%3D2402.38%26gasto_casa3%3D3999.57%26gasto_prestamo1%3D93475.58%26gasto_prestamo2%3D7325.88%26gasto_prestamo3%3D34090.9%26gasto_tarjetas%3D29443.2%26gasto_ibi%3D5670%26gasto_imp_otros%3D6780%26gasto_seg_inm%3D1320%26gasto_seg_pens%3D3451.22%26gasto_seg_vida%3D2330%26gasto_seg_plan%3D34230%26gasto_seg_medico%3D21220%26gasto_seg_coche%3D220%26gasto_luz%3D620%26gasto_agua%3D4550%26gasto_gas%3D320%26gasto_telef_f%3D22320%26gasto_telef_m%3D2350%26gasto_internet%3D20%26gasto_tv%3D3450%26gasto_hogar%3D20%26gasto_comida%3D20%26gasto_cenas_copas%3D20%26gasto_viajes%3D20%26gasto_vacaciones%3D220%26gasto_mobiliario%3D220%26gasto_ropa%3D2320%26gasto_transp%3D230%26gasto_otros%3D3620%26gasto_colegios%3D240%26gasto_univ%3D340%26gasto_master%3D2230%26gasto_otros_gastos%3D7323433%26porc_gasto_tarjetas%3D0%26porc_gasto_ibi%3D0%26porc_gasto_trib%3D0%26porc_gasto_seg_inm%3D0%26porc_gasto_seg_pens%3D0%26porc_gasto_seg_vida%3D2%26porc_gasto_seg_plan%3D2%26porc_gasto_seg_med%3D0%26porc_gasto_seg_coche%3D0%26porc_gasto_sum_luz%3D2%26porc_gasto_sum_agua%3D2%26porc_gasto_sum_gas%3D0%26porc_gasto_sum_teleff%3D0%26porc_gasto_sum_telefm%3D0%26porc_gasto_sum_int%3D0%26porc_gasto_sum_tv%3D0%26porc_gasto_nivel_hogar%3D0%26porc_gasto_nivel_comida%3D0%26porc_gasto_nivel_cenas%3D0%26porc_gasto_nivel_viajes%3D0%26porc_gasto_nivel_vacac%3D0%26porc_gasto_nivel_mob%3D0%26porc_gasto_nivel_ropa%3D20%26porc_gasto_nivel_transp%3D30%26porc_gasto_nivel_otros%3D30%26porc_gasto_colegios%3D2%26porc_gasto_univ%3D0%26porc_gasto_master%3D0%26porc_gasto_otros_gastos%3D23%26tengo_casa1%3D1231.11%26tengo_casa2%3D10000%26tengo_casa3%3D22240%26tengo_otras%3D23560%26tengo_monetario%3D1212.34%26tengo_planpensiones%3D23230%26tengo_otros%3D23330%26porc_tengo_casa1%3D1%26porc_tengo_casa2%3D0%26porc_tengo_casa3%3D2%26porc_tengo_otras%3D0%26porc_tengo_monet%3D0%26porc_tengo_plan%3D0%26porc_tengo_otros%3D0%26debo_casa1%3D4340%26debo_casa2%3D23450%26debo_casa3%3D23430%26debo_prestamo1%3D23330%26debo_prestamo2%3D6871.11%26debo_prestamo3%3D11340%26debo_tarjetas%3D61340%26porc_debo_casa1%3D30%26porc_debo_casa2%3D10%26porc_debo_casa3%3D12%26porc_debo_prestamo1%3D1%26porc_debo_prestamo2%3D12%26porc_debo_prestamo3%3D1%26porc_debo_tarjetas%3D4%26plazo_debo_casa1%3D230%26plazo_debo_casa2%3D450%26plazo_debo_casa3%3D122%26plazo_debo_prestamo1%3D3%26plazo_debo_prestamo2%3D12%26plazo_debo_prestamo3%3D4 It's 2568 characters long, so i guess that's why i get sometimes a GET undefined method in the web console. The original function does something like this: Code: var param ="&usuario="+usuario+"&nivel="+nivel+gano+porc_gano+gasto+porc_gasto+tengo+porc_tengo+debo+porc_debo+plazo_debo; var s = document.createElement("script"); s.type = "text/javascript"; s.async = true; s.src = server_direction +"setMisDatos?callback=respuestaGuardarMisDatos¶m="+encodeURIComponent(param); var h = document.getElementsByTagName("script")[0]; h.parentNode.insertBefore(s, h); //or h.appendChild(s); and every variable in the param is written like this: Code: var plazo_debo_casa1 = (getValor("plazo_debo_casa1")); var plazo_debo_casa2 = (getValor("plazo_debo_casa2")); var plazo_debo_casa3 = (getValor("plazo_debo_casa3")); var plazo_debo_prestamo1 = (getValor("plazo_debo_prestamo1")); var plazo_debo_prestamo2 = (getValor("plazo_debo_prestamo2")); var plazo_debo_prestamo3 = (getValor("plazo_debo_prestamo3")); var plazo_debo ="&plazo_debo_casa1="+plazo_debo_casa1+"&plazo_debo_casa2="+plazo_debo_casa2+"&plazo_debo_casa3="+plazo_debo_casa3+"&plazo_debo_prestamo1="+plazo_debo_prestamo1+"&plazo_debo_prestamo2="+plazo_debo_prestamo2+"&plazo_debo_prestamo3="+plazo_debo_prestamo3; since my webpage has different parts where to put the data, i thought that a good idea would be to create smaller function for parts of variable, for example putting 30 variables and the do the callback. I did like this: Code: function guardaLoQueGano(){ var nivel = parseInt(document.getElementById('progreso_nivel_total').style.marginLeft); /*idUsusario*/ var usuario = miGetElementsByClassName('title', document.getElementById('block-user-1'))[0].innerHTML; /*gano*/ var gano_sal_neto = getValor("gano_sal_neto"); var gano_sal_prof = getValor("gano_sal_prof"); var gano_monet = getValor("gano_monet"); var gano_renta_fija = (getValor("gano_renta_fija")); var gano_renta_vble = (getValor("gano_renta_vble")); var gano_inmuebles = (getValor("gano_inmuebles")); var gano_otros = (getValor("gano_otros")); var gano_otros_ing = (getValor("gano_otros_ing")); /*gano porcentajes*/ var porc_gano_monet = getValor("porc_gano_monet"); var porc_gano_rentaf = getValor("porc_gano_rentaf"); var porc_gano_rentav = getValor("porc_gano_rentav"); var porc_gano_inm = getValor("porc_gano_inm"); var porc_gano_otros = getValor("porc_gano_otros"); var porc_gano_otros_ing = getValor("porc_gano_otros_ing"); var param = "&usuario=" + usuario + "&nivel=" + nivel + "&gano_sal_neto=" + gano_sal_neto + "&gano_sal_prof=" + gano_sal_prof + "&gano_monet=" + gano_monet + "&gano_renta_fija=" + gano_renta_fija + "&gano_renta_vble=" + gano_renta_vble + "&gano_inmuebles=" + gano_inmuebles + "&gano_otros=" + gano_otros + "&gano_otros_ing=" + gano_otros_ing + "&porc_gano_monet=" + porc_gano_monet + "&porc_gano_rentaf=" + porc_gano_rentaf + "&porc_gano_rentav=" + porc_gano_rentav + "&porc_gano_inm=" + porc_gano_inm + "&porc_gano_otros=" + porc_gano_otros + "&porc_gano_otros_ing=" + porc_gano_otros_ing; var s = document.createElement("script"); s.type = "text/javascript"; s.async = true; s.src = direccion_servidor + "setMisDatos?callback=respuestaGuardarMisDatos¶m=" + encodeURIComponent(param); var h = document.getElementsByTagName("script")[0]; // adesso h.appendChild(s); h.parentNode.insertBefore(s, h); alert("Datos de lo que gano actualizados correctamente"); } This kind of function works perfectly, but has a big problem: it changes the values of the columns of this function, but deletes the remaining ones. How can I create different smaller function, in a way to save only on some columns without changing the others? Shall I write the netbeans function setMisDatos to make it more clear? Hi there! Well, I recently found the Image clock code, and I am loving it! But, I would like it to only display pacific time, not retrieve the time from a users browser. Here's my code: Code: <script type="text/javascript"> /*********************************************** * JavaScript Image Clock- by JavaScript Kit (www.javascriptkit.com) * This notice must stay intact for usage * Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and 100s more ***********************************************/ var imageclock=new Object() //Enter path to clock digit images here, in order of 0-9, then "am/pm", then colon image: imageclock.digits=["/users/1712/49/18/66/album/c012.png", "/users/1712/49/18/66/album/c112.png", "/users/1712/49/18/66/album/c211.png", "/users/1712/49/18/66/album/c311.png", "/users/1712/49/18/66/album/c411.png", "/users/1712/49/18/66/album/c511.png", "/users/1712/49/18/66/album/c611.png", "/users/1712/49/18/66/album/c711.png", "/users/1712/49/18/66/album/c811.png", "/users/1712/49/18/66/album/c911.png", "/users/1712/49/18/66/album/cam11.png", "/users/1712/49/18/66/album/cpm13.png", "/users/1712/49/18/66/album/ccolon11.png"] imageclock.instances=0 var preloadimages=[] for (var i=0; i<imageclock.digits.length; i++){ //preload images preloadimages[i]=new Image() preloadimages[i].src=imageclock.digits[i] } imageclock.imageHTML=function(timestring){ //return timestring (ie: 1:56:38) into string of images instead var sections=timestring.split(":") if (sections[0]=="0") //If hour field is 0 (aka 12 AM) sections[0]="12" else if (sections[0]>=13) sections[0]=sections[0]-12+"" for (var i=0; i<sections.length; i++){ if (sections[i].length==1) sections[i]='<img src="'+imageclock.digits[0]+'" />'+'<img src="'+imageclock.digits[parseInt(sections[i])]+'" />' else sections[i]='<img src="'+imageclock.digits[parseInt(sections[i].charAt(0))]+'" />'+'<img src="'+imageclock.digits[parseInt(sections[i].charAt(1))]+'" />' } return sections[0]+'<img src="'+imageclock.digits[12]+'" />'+sections[1]+'<img src="'+imageclock.digits[12]+'" />'+sections[2] } imageclock.display=function(){ var clockinstance=this this.spanid="clockspan"+(imageclock.instances++) document.write('<span id="'+this.spanid+'"></span>') this.update() setInterval(function(){clockinstance.update()}, 1000) } imageclock.display.prototype.update=function(){ var dateobj=new Date() var currenttime=dateobj.getHours()+":"+dateobj.getMinutes()+":"+dateobj.getSeconds() //create time string var currenttimeHTML=imageclock.imageHTML(currenttime)+'<img src="'+((dateobj.getHours()>=12)? imageclock.digits[11] : imageclock.digits[10])+'" />' document.getElementById(this.spanid).innerHTML=currenttimeHTML } </script> <DIV STYLE="position:absolute; top:260px; left:215px; width:109px; height:28px"> <FONT SIZE="+2" COLOR="black"> <TABLE BORDER="0" cellpadding="10" CELLSPACING="0" TOP MARGIN="0"> <TR> <TD WIDTH="109" HEIGHT="28" BACKGROUND="/users/1712/49/18/66/album/clock210.png" VALIGN="top"> <script type="text/javascript"> new imageclock.display() </script> </TD> </TR> </TABLE> </DIV> Much appreciated! |