JavaScript - I Need A Second Instance Of This Script Running On Same Page
Is there a way that I can run a second set of this script on the same page at the same time?
If I want a 2nd instance of this script to run on the same page...what values would I need to rename in the 2nd instance? When I try to place this script a second time it only shows the 2nd scripts values or banner ads... I'm trying to make a Banner rotation placement on my sites inner pages (It's a Wordpress powered site) One Set of Banners that ROTATE directly Above Another Set... I like this script since it allows for a Random order on each page load and will ALSO cycle through Each Banner once before repeating the order, That way Each Advertiser will get seen before another is seen a second or third time... I know there are plug-ins for wordpress for advertising, but I have not found any that will rotate out the banners every x niumber of seconds, like this does... Is there a way that I can run a second set of this script on the same page at the same time? <script type="text/javascript"> // Flexible Image Slideshow- By JavaScriptKit.com (http://www.javascriptkit.com) // For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/ // This notice must stay intact for use var ultimateshow=new Array() //ultimateshow[x]=["path to image", "OPTIONAL link for image", "OPTIONAL link target"] ultimateshow[0]=['http://www.rockinghamcountymerchants.com/CraigTravis/CraigTravis250x250.jpg', 'http://tcraigtravis.com/', '_new'] ultimateshow[1]=['http://www.rceno.com/RCENO/bannerads/elizabethspizza/elizabethspizza250x250.jpg', 'http://www.rceno.com/RCENO/advertisers/elizabethspizza/index.html', '_new'] ultimateshow[2]=['http://www.rceno.com/RCENO/bannerads/gavinsmightychamps/gavin250x250.jpg', 'http://www.gavinsmightychamps.com/index.html', '_new'] ultimateshow[3]=['http://www.rceno.com/RCENO/bannerads/redrivergrill/RedRiver2420-250x250.jpg', 'http://www.rockinghamcountymerchants.com/redrivergrill', '_new'] ultimateshow[4]=['http://www.rceno.com/RCENO/bannerads/qualitycleaners/QC250x250-011510.jpg', 'http://www.rockinghamcountymerchants.com/qualitycleaners', '_new'] //configure the below 3 variables to set the dimension/background color of the slideshow var slidewidth="250px" //set to width of LARGEST image in your slideshow var slideheight="250px" //set to height of LARGEST iamge in your slideshow var slidecycles="continous" //number of cycles before slideshow stops (ie: "2" or "continous") var randomorder="yes" //randomize the order in which images are displayed? "yes" or "no" var preloadimages="yes" //preload images? "yes" or "no" var slidebgcolor='white' //configure the below variable to determine the delay between image rotations (in miliseconds) var slidedelay=9000 ////Do not edit pass this line//////////////// var ie=document.all var dom=document.getElementById var curcycle=0 if (preloadimages=="yes"){ for (i=0;i<ultimateshow.length;i++){ var cacheimage=new Image() cacheimage.src=ultimateshow[i][0] } } var currentslide=0 function randomize(targetarray){ ultimateshowCopy=new Array() var the_one var z=0 while (z<targetarray.length){ the_one=Math.floor(Math.random()*targetarray.length) if (targetarray[the_one]!="_selected!"){ ultimateshowCopy[z]=targetarray[the_one] targetarray[the_one]="_selected!" z++ } } } if (randomorder=="yes") randomize(ultimateshow) else ultimateshowCopy=ultimateshow function rotateimages(){ curcycle=(currentslide==0)? curcycle+1 : curcycle ultcontainer='<center>' if (ultimateshowCopy[currentslide][1]!="") ultcontainer+='<a href="'+ultimateshowCopy[currentslide][1]+'" target="'+ultimateshowCopy[currentslide][2]+'">' ultcontainer+='<img src="'+ultimateshowCopy[currentslide][0]+'" border="0">' if (ultimateshowCopy[currentslide][1]!="") ultcontainer+='</a>' ultcontainer+='</center>' if (ie||dom) crossrotateobj.innerHTML=ultcontainer if (currentslide==ultimateshow.length-1) currentslide=0 else currentslide++ if (curcycle==parseInt(slidecycles) && currentslide==0) return setTimeout("rotateimages()",slidedelay) } if (ie||dom) document.write('<div id="slidedom" style="width:'+slidewidth+';height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>') function start_slider(){ crossrotateobj=dom? document.getElementById("slidedom") : document.all.slidedom rotateimages() } if (ie||dom) window.onload=start_slider </script> In Other words I would have one set of 5 ads rotating and directly below it another set of 5 Ads Similar TutorialsI have 2 pages, If in test.php i include test2.php everything is working perfect, but if the page appear the script is not working. Can someone help me find a problem? test.php PHP Code: <head> <script> function Show_test2(){ var ajaxRequest; try{ ajaxRequest = new XMLHttpRequest(); } catch (e){ try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Your browser broke!"); return false; } } } var ot = document.getElementById('over_time').value; var queryString = "?ot=" + ot; ajaxRequest.open("GET", "test2.php" + queryString, true); ajaxRequest.send(null); ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('Show_test2'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } } </script> </head> <body> <?php //include ("test2.php"); $year = 2014; if(!empty($year)) { echo 'Over Time: '; echo ' <select name="over_time" id="over_time" onclick="Show_test2()"> <option value="1">0</option> <option value="2">1</option> <option value="3">2</option> <option value="4">3</option> <option value="5">4</option> <option value="6">5</option> </select> <br/>'; echo '<div id="Show_test2"></div>'; } ?> </body> test2.php PHP Code: <html> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(function() { $('input[name^="player"]').keyup(function(event) { var player = $(this).attr("name").split('_'); player = player[1]; var player_sum = 0; $('.player_'+player).each(function(index, el) { var pt = parseInt($(el).val()); if(!isNaN(pt)) { player_sum += pt; } }); $('#sum_'+player).html(player_sum); }); }); </script> <body> <?php echo 'first half<br>'; for ($i=1;$i<4;$i++){ echo "gracz".$i.": <input type='text' class='player_".$i."' name='player_".$i."' size='1' maxlength='2'> "; } echo '<br><br>'; echo 'second half<br>'; for ($i=1;$i<4;$i++){ echo "gracz".$i.": <input type='text' class='player_".$i."' name='player_".$i."' size='1' maxlength='2'> "; } echo '<br><br>'; for ($i=1;$i<4;$i++){ echo "gracz".$i.": <span id='sum_".$i."'>0</span> "; } echo '<br><br>'; ?> </body> </html> Thanks Hi, I have a site that runs a javascript slideshow automatically when a user visits it. It is designed in such a way that I cannot pre-load individual images for aesthetic reasons. (Also the whole concept makes my brain hurt.) I therefore need 1 of 2 things: 1. A preloader that doesn't show the page or start the slideshow until all the images are loaded. or 2. I could start with the slideshow paused, and when the page is fully loaded, the play command (currently attached to a 'play' button) is 'sent'. (I'm not techy, so this is the best I can do as explanation.) The latter would probably be more elegant, especially if ultimately I could hide the controls for the slideshow with a loading bar until all the html is loaded, and then show them when the slideshow starts. I'm sorry if this is a really basic question. I tried searching the site but couldn't find anything. If you do feel like answering, can you imagine that you are speaking to a 5 year old. Then dumb it down a bit. I need all the explanation and clarity I can get! Thanks! Hey all. I hate posting this problem, because I am quite embarrassed by this script I have put together. This is not the final script, it is a draft, but I am trying to learn as much as possible and I would like to fix this before I move on and completely rewrite it. As you can probably tell - this is my first crack at JS... Right now I have a page with a registration form, seen he http://www.temp1.hangnailproductions...gistration.php It is working as well as it can be in FireFox, but in IE it is not working at all. Now, I just ran the IE8 debugger, and my first problem is the onload function in the body tag, it is saying that an object is missing, but I do not understand what this means. Can anyone help me with this please? Again, sorry for asking for help on such a mess, but like I said - I need to learn and trial and error works best for me... Thanks very much. Okay I am sure my script is loading when the page loads because of the alert box I have added but when I click on the button that is suppose to activate the script nothing happens. The button code is as follows: <button type="button" name="submit" value="submit" class="css3button" onclick="send(nick,passwd,userid,chan,showtime,showjoin,showpart,showquit,fname,fsize,nnick1,nnick2, nnick3,nnick4,nnick5)">Connect</button> I may be using the button wrong but I am new to javascript. Any suggestions would help. I recently coded a page that extracts certain nodes from an external XML file and prints a line of text on the webpage. It is an HTML page that is strictly devoted to this purpose. There is no other information on it. The page is currently stored locally on my computer, and when I open it, the script runs fine and outputs the correct text. However, when I transferred this script over to my web server, and locate it that way, it doesn't run correctly. When I go to the page, it is supposed to display a line of text at the top. It does when I run the file from my local machine, however when I open it from the server, it doesn't display this text. (Same browser, same computer) When I right-click and view the source, all the code is there, and the files are identical. Any idea as to why the script runs correctly only when I open the HTML page locally? I appreciate any help or advice. Thanks! Hey guys, I have a script that I'm running for a select box, and I need to run it twice now for another select box. Unfortunately if I duplicate it, it will not run at all. Im sure there is a way to combine these two so they both run. Any help very much appreciated! I have colored the text that differs between the two instances in red. Runs fine individually but not the two together . Code: <!--[][][][][][][][] Job Contacts Script --> <script type="text/javascript"> function show Customer (str) {var xmlhttp; if (str=="") {document.getElementById(" txtHint ").innerHTML=""; return;} if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest();} else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");} xmlhttp.onreadystatechange=function() {if (xmlhttp.readyState==4 && xmlhttp.status==200) {document.getElementById(" txtHint ").innerHTML=xmlhttp.responseText;}} xmlhttp.open("GET"," getcustomer.asp ?q="+str,true); xmlhttp.send(); }window.onload = function() { document.getElementsByName(' customers ')[0].onchange();}; </script> <!--[][][][][][][][] Job Ship Site Script --> <script type="text/javascript"> function show Shipto (str) {var xmlhttp; if (str=="") {document.getElementById(" txtHint2 ").innerHTML=""; return;} if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest();} else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");} xmlhttp.onreadystatechange=function() {if (xmlhttp.readyState==4 && xmlhttp.status==200) {document.getElementById(" txtHint2 ").innerHTML=xmlhttp.responseText;}} xmlhttp.open("GET"," getshipsite.asp ?q="+str,true); xmlhttp.send(); }window.onload = function() { document.getElementsByName( 'shipsites ')[0].onchange();}; </script> Hi there, I'm fairly new to Javascript, though have a good deal of experience with C# and HTML. I am having trouble getting a form to validate when it is submitted. My goal is that if a checkbox is checked (allowing the user to request more information via email) that the email address textbox should also verified to be filled out. What I have is a script in the page body, that (I believe) validates the two form elements, and the form has an onsubmit tag to run the javascript. However, everytime I run a test on the page, it submits regardless of if there is or isn't anything in the email field, with the box checked. Any guidance would be appreciated! Code: <script type="text/javascript"> function validate(){ if(document.getElementById('00N50000002tarI').value == '1' && document.getElementById('email').value == ''){ alert('Please enter your email address'); return false; } </script> <form class="apply_now_form" action="test.php" id="apply_now_form" method="POST" onsubmit="return validate();"> <div class="text"><label for="email">Email</label> <input id="email" type="text" name="email" maxlength="80" /></div> <div class="check"><font color="#006e92"><input id="00N50000002tarI" name="00N50000002tarI" type="checkbox" value="1" />*I would like to receive the latest updates via email.</font><br></div> <div class="submit"><input class="c pill-button" type="submit" name="submit" value="Apply Now!"/></div> </form> Note: This form was generated by SalesForce Web-to-lead, so I cannot modify form field names, and the form is running on WordPress, in an blank page template (so there shouldn't be any WordPress code muddling with the form). Have spent over 40 hours trying to make something like this work. Any help will be received with profound gratitude. Code: <!-- First, we reference a script whose purpose is to create a space for session variables similar to cookies. Works if it appears early in body of Drupal page, so this is not the issue (Drupal parses pages down for display so there is no user <head> tag). --> <script type="text/javascript" src="sessvars.js"></script> <script language = "javascript"> <!-- We create the variable whichpage because we will be creating a session variable sessvars.whichpage courtesy of the sessvars.js script--> var whichpage; <!-- Next, we create a lookup table: --> var myTable = new Array(); myTable[1] = "001_Front_Cover_jpg.jpg"; myTable[2] = "002_Inside_Front_Cover_jpg.jpg"; myTable[3] = "003_Frontispiece_Design_jpg.jpg"; </script> <!-- Next, we create a table with thumbnails; each thumbnail image is a hyperlink which, onClick, is supposed to run a script assigning a value to sessvars.whichpage, so when Drupal node 23 is reached, it can use the value of sessvars.whichpage to select the array (myTable) element which corresponds to the full-sized picture we want to load. Node 23 also has the lookup array (myTable). The node inserts the snippet contained in the myTable element into a URL of the picture to load. --> <!-- Here we define the table --> <!-- Next, we have a series of hyperlinks which present the table with thumbnails so clicking on the thumbnail assigns a value to sessvars. whichpage and then transfers to the node that uses that value: --> <a href="23" onClick="<script language = 'javascript'> sessvars.whichpage=1; </script>" <img> </img> </a> <a href="23" onClick="<script language = 'javascript'> sessvars.whichpage=2; </script>" <img> </img> </a> <a href="23" onClick="<script language = 'javascript'> sessvars.whichpage=3; </script>" <img> </img> </a> <!-- The problem is that this flat does not work. When we get to node 23 sessvars.whichpage shows as undefined. It used to work when I called a function instead of put the script into each link, but I found there was no simple way to get the value (1,2,3 etc.) to the function --> Is there an answer. Thank you so much in advance. Leon Malinofsky Hello, I'm building a simple custom dropdown menu for a web-site so that I can control look and feel as well as the behavior of an iframe. I've set it up so that when the user clicks on any of the menu's active components, an "if" sequence in the clickHandler() function is activated that gets the element's class. If the event occurred on a dropdown option, the event-target id is checked, and the appropriate function is called. At least this is how it's supposed to work. All of the drop-down options have been assigned the "dmo" class. When I test the menu and click on other elements, it works fine. But when I click the "dmo" drop-down options, nothing happens. Firebug and IE Explorer Developer Tools both show no errors, but on clicking a dropdown option, the correlate code doesn't run at all, and after hours of head-banging, I have no idea why. I need help on this one. Here's the code. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> BODY { background:#000; } .DropMenu { width:228px; height:1.5em; } .DropMenu span { color:#FFF; font-size:0.875em; font-family:Verdana, Geneva, sans-serif; font-weight:bold; } .DropMenuLabel { float:left; width:85px; height:1.5em; padding:0.2em 0 0 0; text-indent:0.3em; } .DropMenuTopList { width:130px; float:left; height:1.5em; padding:0 0 0 0; cursor:pointer; } .DropMenuTopList img { padding:0.4em 0 0 0.3em; cursor:pointer; } .DropMenu span { color:#FFF; font-size:.875em; font-family:Verdana, Geneva, sans-serif; font-weight:bold; vertical-align:center; } #dropMenuButton { cursor:pointer; } #dropMenuOptions { position:relative; width:130px; left:85px; padding:0.2em 0 0 0; visibility:hidden; cursor:pointer; } .MenuList { list-style-type:none; top:0; left:0; width:100%; margin:1.5em 0 0 0; padding:0; } .MenuList li{ height:1.5em; margin:0.2em 0 0 0; padding:0; width:100%; background-color:#666; border-color:#AAA; border:0.5px solid; text-indent:0.3em; } .dmo { z-index:100; } </style> <script type="text/javascript" language="javascript"> window.onload = function() { setBehavior(); } function setBehavior() { /* var downButton = document.getElementById('dropMenuButton') downButton.onclick = new Function ( "showMenu()" ); */ window.onclick = new Function ( "evt" , "clickHandler( evt )" ); } function clickHandler( evt ) { var dropMenu = document.getElementById('dropMenuOptions'); var e = evt; var targ; if (e.target) {targ = e.target} else if (e.srcElement) {targ = e.srcElement} var targClass = targ.getAttribute('class'); /* classnames dmb - dropdown button - this should toggle the dropdown visibility on and off on click, and toggle visibility on over/out dmo - option - once clicked, this should turn the dropdown visibility off */ var exclude = ("dmb" || "dmo") if (targClass != exclude ) { hideMenu() } else if (targClass == "dmb" ) { if (dropMenu.style.visibility == "visible") { hideMenu() } else showMenu(); } else if (targClass == "dmo" ) { if ( targ.id == "option1" ){ window.open(www.bing.com,"Bing") } else if ( targ.id == "option2" ){ window.open(www.bing.com,"Bing") } else if ( targ.id == "option3" ){ window.open(www.cuil.com,"Cuil") } hideMenu(); } } function showMenu() { var dropMenu = document.getElementById('dropMenuOptions'); dropMenu.style.visibility= "visible"; } function hideMenu() { var dropMenu = document.getElementById('dropMenuOptions'); dropMenu.style.visibility= "hidden"; } </script> </head> <body> <div id="customMenu" class="DropMenu"> <span> <div class="DropMenuLabel">Options:</div> <div class="DropMenuTopList dmb" id="dropMenuTopList">Temp Text <img class="dmb" id="dropMenuButton" src="Assets/Buttons/DropMenuDownButton.png"> </img> </div> <div class="dmo DropMenuOptions" id="dropMenuOptions"> <ul id="menuList" class="dmo MenuList"> <li id="option1" class="dmo">Option1</li> <li id="option2" class="dmo">Option2</li> <li id="option3" class="dmo">Option3</li> </ul> </div> </span> </div> </body> </html> Hi there, this is our first post, just stubmled across this awesome site. Need some help if anyone is able (and willing ). We are trying to make the best possible shopping experience for our customers. Objective: to give the customer a running total of what they're about to order, before they add to basket (kind of a quick quote). if you go to our test page: http://www.gatewrights.co.uk/page87.html we have got a form (boxed in red) which does indeed put the totals (of that form) in the totals box (on our form). As you should see if you test it. Now, I need to try and work out (but am really struggling) how to get it to work with the items on our form. Objective: to give the customer a running total of what they're about to order, before they add to basket (kind of a quick quote). I'll post the head js code and the body js code below. I have tried renaning the formID to 'frmOrder' (the same as the one boxed in red, and then moved that boxed one off page but it doesn't work. I suspect there is a little work to do (possibly in the value fields of our form). Hope it is clear, and I thank you for your time so far. -------------------------- js head code: Code: </script><script type="text/javascript" src="orderform04.js"></script> (plus) Code: <script type="text/javascript"> //<![CDATA[ window.onload = setupScripts; function setupScripts() { var anOrder1 = new OrderForm(); } //]]> </script> -------------------- js file uploaded to root directory (orderform04.js): Code: // mredkj.com // OrderForm.js - v0.4 // v0.4 - 2007-02-01 // v0.3 - 2006-04-09 // v0.2 - 2006-04-08 // v0.1 - 2006-04-06 function OrderForm(prefix, precision, firstChoice) { this.prefix = prefix ? prefix : ''; // **************************** // Configure here // **************************** // names - Set these according to how the html ids are set this.FORM_NAME = this.prefix + 'frmOrder'; this.BTN_TOTAL = this.prefix + 'btnTotal'; this.TXT_OUT = this.prefix + 'txtTotal'; // partial names - Set these according to how the html ids are set this.CHK = this.prefix + 'chk'; this.SEL = this.prefix + 'sel'; this.PRICE = this.prefix + 'txtPrice'; // precision for the decimal places // If not set, then no decimal adjustment is made this.precision = precision ? precision : -1; // if the drop down has the first choice after index 1 // this is used when checking or unchecking a checkbox this.firstChoice = firstChoice ? firstChoice : 1; // **************************** // form this.frm = document.getElementById(this.FORM_NAME); // checkboxes this.chkReg = new RegExp(this.CHK + '([0-9]+)'); this.getCheck = function(chkId) { return document.getElementById(this.CHK + chkId); }; // selects this.selReg = new RegExp(this.SEL + '([0-9]+)'); this.getSelect = function(selId) { return document.getElementById(this.SEL + selId); }; // price spans this.priceReg = new RegExp(this.PRICE + '([0-9]+)'); // text output this.txtOut = document.getElementById(this.TXT_OUT); // button this.btnTotal = document.getElementById(this.BTN_TOTAL); // price array this.prices = new Array(); var o = this; this.getCheckEvent = function() { return function() { o.checkRetotal(o, this); }; }; this.getSelectEvent = function() { return function() { o.totalCost(o); }; }; this.getBtnEvent = function() { return function() { o.totalCost(o); }; }; /* * Calculate the cost * * Required: * Span tags around the prices with IDs formatted * so each item's numbers correspond its select elements and input checkboxes. */ this.totalCost = function(orderObj) { var spanObj = orderObj.frm.getElementsByTagName('span'); var total = 0.0; for (var i=0; i<spanObj.length; i++) { var regResult = orderObj.priceReg.exec(spanObj.id); if (regResult) { var itemNum = regResult[1]; var chkObj = orderObj.getCheck(itemNum); var selObj = orderObj.getSelect(itemNum); var price = orderObj.prices[itemNum]; var quantity = 0; if (selObj) { quantity = parseFloat(selObj.options[selObj.selectedIndex].text); quantity = isNaN(quantity) ? 0 : quantity; if (chkObj) chkObj.checked = quantity; } else if (chkObj) { quantity = chkObj.checked ? 1 : 0; } total += quantity * price; } } if (this.precision == -1) { orderObj.txtOut.value = total } else { orderObj.txtOut.value = total.toFixed(this.precision); } }; /* * Handle clicks on the checkboxes * * Required: * The corresponding select elements and input checkboxes need to be numbered the same * */ this.checkRetotal = function(orderObj, obj) { var regResult = orderObj.chkReg.exec(obj.id); if (regResult) { var optObj = orderObj.getSelect(regResult[1]); if (optObj) { if (obj.checked) { optObj.selectedIndex = orderObj.firstChoice; } else { optObj.selectedIndex = 0; } } orderObj.totalCost(orderObj); } }; /* * Set up events */ this.setEvents = function(orderObj) { var spanObj = orderObj.frm.getElementsByTagName('span'); for (var i=0; i<spanObj.length; i++) { var regResult = orderObj.priceReg.exec(spanObj.id); if (regResult) { var itemNum = regResult[1]; var chkObj = orderObj.getCheck(itemNum); var selObj = orderObj.getSelect(itemNum); if (chkObj) { chkObj.onclick = orderObj.getCheckEvent(); } if (selObj) { selObj.onchange = orderObj.getSelectEvent(); } if (orderObj.btnTotal) { orderObj.btnTotal.onclick = orderObj.getBtnEvent(); } } } }; this.setEvents(this); /* * * Grab the prices from the html * Required: * Prices should be wrapped in span tags, numbers only. */ this.grabPrices = function(orderObj) { var spanObj = orderObj.frm.getElementsByTagName('span'); for (var i=0; i<spanObj.length; i++) { if (orderObj.priceReg.test(spanObj.id)) { var regResult = orderObj.priceReg.exec(spanObj.id); if (regResult) { orderObj.prices[regResult[1]] = parseFloat(spanObj.innerHTML); } } } }; this.grabPrices(this); } --- Now I hope this makes sense, and really appreciate any help you can offer. If anything is unclear, please let me know. ps is it something to do with "* Prices should be wrapped in span tags, numbers only."?? Hi all: I've got a script that reads a line of text from a file, and does a bit of parsing to that line into an array. Apparently, this can take some time, so I get the "Stop running this script?" message. From what I understand, I need to use the setTimeout call, but for the life of me can't understand it. When I do add it to some code, it seems to work, but doesn't "pause" the code as I expect it too... Code: function ReadFile(Fname) { var path = "y:\\metrics\\"; var file, x=0, ForReading=1; file = fso.OpenTextFile(path+Fname, ForReading, false); do { var fileLine = file.readline(); var arrSplit = GetItems(fileLine); } while (!file.AtEndOfStream); file.close(); return(x); } function GetItems(recordLine) { var ItemsTemp=[]; var finishString, itemString, itemIndex, charIndex, inQuote, testChar; inQuote = false; charIndex= 0; itemIndex=0; itemString = ""; finishString = false; var count = 0; do { if (++count >= 100) { delay = setTimeout("", 1, []); count = 0; return; } testChar = recordLine.substring(charIndex,charIndex+1); finishString = false; if (inQuote) { if (testChar == "\"") { inQuote = false; finishString = true; ++charIndex; } else { itemString = itemString + testChar; } } else { if (testChar == "\"") { inQuote = true; } else if (testChar == ",") { finishString = true; } else { if (testChar == "=") { testChar = ""; } itemString = itemString + testChar; } } if (finishString) { ItemsTemp.push(itemString); itemString = ""; ++itemIndex; } ++charIndex; } while (charIndex <= recordLine.length); return(ItemsTemp); } Any help would be greatly appreciated! Thanks, Max Hi the Is it possible to probe the name of the variable assigned to an object instance in JavaScript? For example: Code: function house(){ } var bobhouse=new house() if (instancename=="bobhouse") //do something In other words, can I do some sort of string comparison on the variable name "bobname", so I know it's actually called "bobname"? I feel I'm asking how to have a variable recognize itself as a variable. I have created a class providing various functions called BaseBrowser and the class definition by using prototype. Specific browser implementations are then acheived by extending BaseBrowser (eg as 'FF' for Firefox) as shown below. The window alert(); function is overridden for alternate message box popup (using layers in the same window). The function 'browser.customAlert()' can be called from either any code or an actual 'alert()' function. However whenever it is called the value of 'someVar' as defaulted back to the new instance value of false despite the instance 'browser' having already set it to true as it were a new instance. Why is this occuring as it should remember its state between function calls ? Code: var browser; function BrowserBase(){ //instance variables this.someVar=false; function customAlert(){ this.someVar=true; // . . . other custom alert code } } function browserLink(){ BrowserBaseFF2p0.prototype=new BrowserBase();//inherit BrowserBaseFF2p0.prototype.constructor=BrowserBase; browser=new BrowserBaseFF2p0(); } function BrowserBaseFF2p0(){ BrowserBase.call(this);//call parent constructor //override generic functions for enhancement if(document.getElementById){ window.alert=function(txt){ browser.customAlert(txt); } } } Hi All, i have thie following code Code: searchValue=document.getElementById('keyword').value;searchValue=searchValue.replace(" ", "_"); and if searchValue = this is my title the above code returns this_is my title instead of this_is_my_title any ideas? EDIT ==== ok solved it this works Code: searchValue=searchValue.replace(/ /gi, "_"); many thanks Luke Hey, I have made/modifying a script that I can create AJAX objects on the fly. It is working fine in Chrome, FF, Opera, Safari but not IE -.- IE = nightmare Code: function ajax_object() { this.receive = function(serverAJAXpage, whileLoading, onDone, dataIntoDivID) { this.xmlHttp = createAjaxObject(); this.serverAJAXpage = serverAJAXpage; this.xmlHttp.open("GET", this.serverAJAXpage, true); this.xmlHttp.send(); this.xmlHttp.onreadystatechange = function() { if (this.readyState == 1) { eval(whileLoading); //document.getElementById(mydiv).innerHTML=this.responseText; } if (this.readyState == 4) { eval(onDone); if (typeof dataIntoDivID != "undefined") { document.getElementById(dataIntoDivID).innerHTML = this.responseText; } } } } } function createAjaxObject() { var xmlHttp=null; try { xmlHttp=new XMLHttpRequest(); } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } There is the function that handles the object and here is the objects being used: Code: <script> var onlineUsersAJAX = new ajax_object(); onlineUsersAJAX.receive('ajax/onlineUsers.php', '', '', 'onlineUsers'); var recentPostsAJAX = new ajax_object(); recentPostsAJAX.receive('ajax/recentPosts.php', '', '', 'recentThreads'); </script> IE throws the error: 'ajax_object' is undefined Thank you to anyone that can help =) How to I create the following code... Code: #moving { position:absolute; float:right; top:100px; left:50px; } #movingword { position:absolute; float:right; top:0px; left:0px; } ... and this code ... Code: <div id="movingword"> <font color="yellow"><font size="3"><b>This is the place</b></font><br>Welcome!</font> </div> ... programmatically using Javascript? (I will need a X number of "movingwords" and "moving", where X is a number and examples are "movingwords0", "movingwords1", "movingwords2" ... movingwordsX) Here the full code: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="language" content="english"> <meta http-equiv="Content-Style-Type" content="text/css"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <title></title> <style type="text/css"> body { background-color:#000; } #scenery { position:relative; } #moving { position:absolute; float:right; top:100px; left:50px; } #movingword { position:absolute; float:right; top:0px; left:0px; } </style> <script type="text/javascript"> var t=125; var l=20; $(document).ready(function() { document.getElementById("movingword").style.top = t + "px"; document.getElementById("movingword").style.left = l + "px"; }); </script> </head> <body> <font color=white><h1> Hello World </h1></font> <div id="scenery"> <img src="http://www.deshow.net/d/file/travel/2009-10/new-zealand-scenery-738-20.jpg" alt=""> <div id="moving"> <img src="http://cdn1.iconfinder.com/data/icons/gloss-basic-icons-by-momentum/32/bullet-yellow.png" alt=""> </div> <div id="movingword"> <font color="yellow"><font size="3"><b>This is the place</b></font><br>Welcome!</font> </div> </div> </body> </html> Hi there Im trying to create a function where i pass two element id's and my script populates it with events and anything else it may need to run but what i am finding is that i cant use this so that the instance of the object is kept what ends up happening is nothing at all what i would like to have happen is the code to work somthing like this... Code: <div id="iAmTheTargetId"> </div> <div id="iWillHoverOverYouId"> </div> <script type="text/javascript"> var element = new hoverBox('iAmTheTargetId','iWillHoverOverYouId'); </script> and simply running that would then create the equivalent of doing Code: <div id="iAmTheTargetId" onmouseover="element.activate()" onmouseout="element.deactivate()" onmousemove="element.update(event)> </div> <div id="iWillHoverOverYouId"> </div> <script type="text/javascript"> var element = new hoverBox('iAmTheTargetId','iWillHoverOverYouId'); </script> But of course the code above won't actual add onmouseover and etc it just so you can see what i'm trying to achieve Code: /* * triggerId * the element in which the attributes will be applied to * * hoverBoxid * the element in which will hover around the triggerId */ function hoverBox(triggerId,hoverBoxid){ this.triggerElement = document.getElementById(triggerId); this.hoverBoxElement = document.getElementById(hoverBoxid); if(this.triggerElement == null || this.hoverBoxElement){ return null; } self = this; alert(this.triggerElement); this.triggerElement.addEventListener('mouseover',function(){self.activate();},false); this.triggerElement.addEventListener('mouseout',function(){self.deactivate();},false); this.triggerElement.addEventListener('mousemove',function(){self.update(event);},false); } hoverBox.prototype = { triggerElement : null, hoverBoxElement : null, state : false }; hoverBox.prototype.activate = function(){ this.state = true; }; hoverBox.prototype.deactivate = function(){ if(this.state != false){ this.hoverBoxElement.style.display = "none"; this.state = false; } }; hoverBox.prototype.update = function(evt){ if(this.state != false){ this.hoverBoxElement.style.display = "block"; this.hoverBoxElement.style.position = "absolute"; this.hoverBoxElement.style.top = (evt.clientY + 5)+ "px"; this.hoverBoxElement.style.left = (evt.clientX + 10)+ "px"; } }; A quick note theses function will work by them selfs if you just do Code: <div id="target" onmouseover="aHoverBox.activate()" onmouseout="aHoverBox.deactivate()" onmousemove="aHoverBox.update(event)"> </div> <div id="hover"> </div> <script type="text/javascript"> var aHoverBox = new hoverBox('iAmTheTargetId','iWillHoverOverYouId'); </script> But not quite what I'm after i would like not to have to enter in Code: onmouseover="aHoverBox.activate()" onmouseout="aHoverBox.deactivate()" onmousemove="aHoverBox.update(event)" and have that done by the JavaScript Well i hope every thing makes scene sorry if i repeated my self just making sure you understand me I would like to know a script for when you have a page that can expire (or cannot be open again) --- a time limit for like 24 hours. Because I'm going to make a site where people can buy website designs, they buy it off paypal, they get redirected to a site where the code is located and the site will get expired in 24 hours -- then, they wouldn't be able to open the page again. If anyone knows the script, please post it here! Thank you x Why is the callwhy is the slice method only a method of an Array instance? The reason why I ask is because if you want to use it for the arguments property of function object, or a string, or an object, or a number instance, you are forced to use Array.prototype.slice.call(). And by doing that, you can pass in any type of object instance (Array, Number, String, Object) into it. So why not just default it as a method of all object instances built into the language? In other words, instead of doing this: Code: function Core(){ var obj = {a : 'a', b : 'b'}; var num = 1; var string = 'aff'; console.log(typeof arguments);//Object console.log(arguments instanceof Array);//false var args1 = Array.prototype.slice.call(arguments); console.log(args1); var args2 = Array.prototype.slice.call(obj); console.log(args2); var args3 = Array.prototype.slice.call(num); console.log(args3); var args4 = Array.prototype.slice.call(string); console.log(args4); Core('dom','event','ajax'); Why not just be able to do this: Code: function Core(){ var obj = {a : 'a', b : 'b'}; var num = 1; var string = 'aff'; var args = arguments.slice(0); var args2 = obj.slice(0); var args3 = num.slice(0); var args4 = string.slice(0); //right now none of the above would work but it's more convenient than using the call alternative. } Core('dom','event','ajax'); Why did the designers of the javascript scripting language make this decision? Thanks for response. Is this possible? I am writing a script that will display an alert box that reads "your play was saved" after a user clicks the submit button on a form. The only problem is that after clicking save, the page refreshes. Here is the code I tried to use Code: function savedMessage(){ document.getElementById("CmdFinish").addEventListener("click",function(e) { GM_setValue("Saved", 1); }, false); if (GM_getValue("saved", 0) == 1) { alert("Your play has been saved"); GM_setValue("saved", 0); // or GM_deleteValue("saved"); } } The button ID is "CmdFinish" and the value is "saved". Is there ANY way i can make the script run only on a page refresh? **Note** The script is for a specific page and not the whole site, so it wont run on every refresh on the site, only when it's needed on 1 page. |