JavaScript - How Many Lines Of Code Can Javascript Take?
Here I have a code to redirect a page to one of these three pages. But is there a limit to the amount of websites I can add?
Code: <script type="text/javascript"> var urls = new Array(); urls[0] = "http://www.google.com"; urls[1] = "http://www.youtube.com"; urls[2] = "http://www.codingforums.com"; var random = Math.floor(Math.random()*urls.length); window.location = urls[random]; </script> Would I be allowed to have, say, hundreds of thousands of different sites? Or would the script stop working? Thanks. Similar TutorialsI need to pass two lines of code through an onClick event.... player1.sendEvent('STOP'); player2.sendEvent('STOP'); I tried Code: <a href="javascript:void(0)" onClick="player1.sendEvent('STOP'); player2.SendEvent('STOP');" title="<?php echo $list[$i]->title ?>"> only the event of player1.sendEvent('STOP'); is working... but not the second one. How do I manage this right here on the link rather than calling a fuction. Thanks Hi. I have the following line in my HTML file <table class="bz_buglist" cellspacing="0" cellpadding="4" width="100%"> And I need to use javascript to change this line to <table id="main_table" class="bz_buglist" cellspacing="0" cellpadding="4" width="100%"> . I just need to add the ID part. How can I do this? Is there a method of replacing the line, or a way to "add attribute"? thanks! kev. Hi, Does anyone know how to make a javascript regex ignore new lines? I have this Code: html = html.replace(/<!--(.*?)-->/gi, ''); // HTML comments which matches single line comments like - Code: <!-- this is a comment --> but not this - Code: <!-- This is a comment on multiple lines --> I think the answer lies with [\s\S] but I can't get it to work e.g. - Code: html = html.replace(/<!--(.*[\s\S]?)-->/gi, ''); // HTML comments Any help will be greatly appreciated Cheers Al I am creating a web/shopping cart using Big Commerce. I am not a programer so I need help creating a code for the following: a.- PRICING DISOCOUNTS - The variations features allows for setting prices for diferent size, colors, etc. but will not allow for price discounts. Meaning if you buy 1 ea the price is $10.00 ea 2 $ 8.00 ea or 5 or more $ 7.00 ea. We sell health supplements so Price Discounts are important. Tech support said I needed a simple java cript code written. Need to give a set $$ discount or % discount to all products or individually as required. Can anyone help? I just started a small business but I am willing to pay some for quick delivery. Thank you very much. J.C. Hey guys, Im kind of a newb and i need help with this dice game im trying to build to help me learn javascript. If you open up the code up in your browser and click the roll button, it will clear everything and write var a in the top left corner. What i am trying to do is write the var a into the text box. any suggestions?? [CODE] <html> <head> <script type="text/javascript"> </script> <style type="text/css"> body { background-image: url(http://projectraw.files.wordpress.com/2010/02/background_brick_wall.jpg); } h1 { font-family:"sans-serif",tahoma; background-repeat: no-repeat; color:white; } p { color:white; font-family:"sans-serif",tahoma; font-weight:900; } </style> </head> <body> <center><h1>Ghetto Dice Project</h1></center> <center> <p> Hand coded with care by Tanner Beck </p> </br> </br> </br> </br> </br> </br> </br> </br> </br> </br> <p> <center> <table BGCOLOR="#888888" BORDER="3" CELLPADDING="5"> <tr> <input type="text" name="number" size="4" value=a> </tr> </br> <tr> <button onclick=" a=(Math.floor(Math.random()*13)); document.write(a)">ROLL</button> </tr> </table> </br> </center> </p> </body> </html> [CODE] I'm trying to get a drop down box to change the image i've managed to get it working for one but can't seem to get it working when both scripts are on. any help would be much appreciated! http://humza-productions.co.uk/test/ this is the code i'm using, it's for the baseball jacket one but the one that's working live on the website is currently working for the hoodie Code: <script type="text/javascript"> window.onload=function() { bp='images/', //base url of your images imgnum=3, //Number of your images. This should match on your comboboxes options. thumb=document.getElementById('sho1'), //id of your image that will be changing combobox=document.getElementsByName('os1')[0]; // id of your combobox. combobox.onchange=function() { thumb.src=bp+'shop'+this.value+'.png'; } } </script> I have written the code below myself and im trying to figure out if this is the outcome in a web browser => 0 1 2 3 4 5 6 7 8 9 if not what would be the outcome? <script language=javascript type="text/javascript"> for (i=0 ;i<10 ;i++) { document.write(i) } </script> and how would you modify this code so it prints only even numbers and how would you modify it so that it sums all values of i and prints the final sum? Hi guys my friend has created a game where there are four boxes each numbered from one to four. When you click on these boxes you either get a tick or a cross. In every turn 3 boxes will have ticks and one will have a cross and the aim is to get as many ticks as possible (each tick gets you a point and when you come across a cross your points are all deleted). Anyway i was wondering if theres a way to guess which box will have a cross beforehand. He claims its random but i wanted to make sure. heres the javascript: var spath; var failbox; var score; var pushnumber; var clickedEl; var clickedElT; var waitEvent = 1; function losegameget() { waitEvent = 1; $(".games3of4 > .box > div").each(function (boxli) { jQuery(this).removeClass("check"); jQuery(this).removeClass("check2"); jQuery(this).removeClass("heart"); jQuery(this).removeClass("heart2") }); jQuery(".savegame").css("visibility", "hidden"); $(".asama").find("span").html("0"); jQuery(clickedEl).removeClass("heart"); jQuery(clickedEl).removeClass("heart2"); $(".losebox").css("display", "block"); $(".box").css("display", "none"); jQuery.get("/game1of3"); jQuery.get("/game1of3?score=1", function (json) { var jsonall; eval("jsonall = " + json + ";"); jQuery("#scoreliste").html(""); for (var i = 0; i < jsonall.length; i++) { jQuery("#scoreliste").append(jQuery('<li><div class="order">' + (i + 1) + "</div> " + jsonall[i]["username"] + " <span>(" + jsonall[i]["score"] + ")</span></li>")) } }); } function gameget() { var dd = $(".asama").find("span").text(); if (dd == "0") { $(".asama").find("span").text(0); } score = eval($(".asama").find("span").text()); $(".asama").find("span").empty().html(score + 1); $(".games3of4 > .box > div").each(function (boxli) { jQuery(this).removeClass("check"); jQuery(this).removeClass("check2"); }); waitEvent = 1; } function wgame() { waitEvent = 0; $(".games3of4 > .box > div").each(function (a) { jQuery(this).removeClass("check"); jQuery(this).removeClass("check2"); }); if (parseInt(jQuery(clickedEl).attr("rel")) == 1 || parseInt(jQuery(clickedEl).attr("rel")) == 2) { jQuery(clickedEl).addClass("check") } if (parseInt(jQuery(clickedEl).attr("rel")) == 3 || parseInt(jQuery(clickedEl).attr("rel")) == 4) { jQuery(clickedEl).addClass("check2") } setTimeout("gameget();", 200); } function losegame() { waitEvent = 0; $(".games3of4 > .box > div").each(function (a) { jQuery(this).removeClass("check"); jQuery(this).removeClass("check2"); jQuery(this).removeClass("heart"); jQuery(this).removeClass("heart2"); }); if (parseInt(jQuery(clickedEl).attr("rel")) == 1 || parseInt(jQuery(clickedEl).attr("rel")) == 2) { jQuery(clickedEl).addClass("heart"); } if (parseInt(jQuery(clickedEl).attr("rel")) == 3 || parseInt(jQuery(clickedEl).attr("rel")) == 4) { jQuery(clickedEl).addClass("heart2"); } setTimeout("losegameget();", 400); } function ifagain() { jQuery(".box").hide(); jQuery(".savegame").hide(); jQuery(".asama").hide(); jQuery("#againcall").show(); jQuery(".yes").click(function () { jQuery.get("/game1of3?start=1", function () { jQuery(".box").show(); jQuery("#againcall").hide(); jQuery(".savegame").css("visibility", "visible"); jQuery(".asama").show(); }) }) } function playSound(a) {} jQuery.jQueryRandom = 0; jQuery.extend(jQuery.expr[":"], { random: function (c, d, b, e) { if (d == 0) { jQuery.jQueryRandom = Math.floor(Math.random() * e.length) } return d == jQuery.jQueryRandom; } }); function countGet() { jQuery.get("/game1of3?count=1", function (a) { jQuery("#defa").html(a + " Defa Oynandı<br />"); }) } $(document).ready(function () { setInterval("countGet();", 20000); jQuery(".savegame").click(function () { if (confirm("Puanınızı kaydetmek istediğinizden emin misiniz ?")) { jQuery.get("/game1of3?save=1", function () { jQuery(".box").hide(); jQuery("#saved").show(); jQuery(".boxaga").show(); jQuery(".savegame").css("visibility", "hidden"); $(".highpoint").find("b").html($(".asama").find("span").text()); $(".asama").find("span").html("0"); }) } }); z = 0; $(".games3of4 > .box > div").each(function (boxli) { $(this).click(function () { if (waitEvent) { clickedEl = this; clickedElT = jQuery(this).attr("rel"); jQuery.get("/game1of3?res=" + jQuery(this).attr("rel"), function (data) { if (data == 'umustbelogin') { window.location.href = '/uye/giris?&redirect_to=/oyun'; } else { var r; r = (data.indexOf("true") != -1); } if (r) { wgame(); } else { losegame(); } }) } }); }); $(".try").click(function () { $(".losebox").css("display", "none"); $(".box").css("display", "block"); jQuery(".savegame").css("visibility", "visible"); }); $(".try2").click(function () { $(".boxaga").css("display", "none"); $(".box").css("display", "block"); jQuery("#saved").hide(); jQuery(".savegame").css("visibility", "visible"); }); $.playgame = function (kcode) { score = eval($(".score").find("span").text()); if (kcode == 49) { pushnumber = 1 } if (kcode == 50) { pushnumber = 2 } if (kcode == 51) { pushnumber = 3 } if (kcode == 52) { pushnumber = 4 } clickedEl = $(".gamecontent li")[pushnumber - 1]; clickedElT = pushnumber; jQuery.get("/game1of3?res=" + pushnumber, function (data) { score = eval($(".score").find("span").text()); var r = eval(data); if (r) { wgame(); } else { losegame(); } }) }; jQuery.get("/game1of3"); }); cheers! Hi there, I'm sure someone can help me with this simple fix. I am putting a site together for a friend and I found a Javascript code that I'm using which basically causes an image to enlarge on mouse rollover. The website, which I just started, is: Home 2 What I'm trying to do is get the larger image to appear a little more to the right than it currently does, so it is not right on top of the thumbnails. I hope someone can tell me what code (and where) I need to add to accomplish this. I'm quite new at this so I really need specific instruction. Thanks in advance for your help! Here is the code for the onmouseover routine: Code: <head> <script language="JavaScript"> function showlargeimage(imgshow) {document.getElementById('image').src=imgshow;} function showlargeimage(imgshow) {document.getElementById('image').src=imgshow; document.getElementById('image').style.display='block'; } </script> </head> <body> <TABLE> <TR> <TD> <!--THUMBNAILS--> <img src="thumbnail1.jpg" onmouseover=showlargeimage('image1.jpg')><br> <br> <img src="thumbnail2.jpg" onmouseover=showlargeimage('image2.jpg')><br> <br> <img src="thumbnail3.jpg" onmouseover=showlargeimage('image3.jpg')><br> <br> <img src="thumbnail4.jpg" onmouseover=showlargeimage('image4.jpg')><br> <br> <img src="thumbnail5.jpg" onmouseover=showlargeimage('image5.jpg')><br> <br> </TD> <TD> <!--image SCREEN--> <img src='#' id='image'> <img src='#' id='image' style='display:none'> </TD> </TR> </TABLE> </body> Hi, Which is the difference between to use "<!-- //-->" inside the script or not? Quote: <script language=JavaScript> <!-- function stopError() { return true; } window.onerror = stopError; // --> </script> Quote: <script language=JavaScript> function stopError() { return true; } window.onerror = stopError; </script> Any advice is welcome!! stickers Code below is not working...nothing happens on clicking submit...javascript is enabled in browser..help please. Code: <html> <head> <script type="text/javascript"> function match() { var aa=document.getElementById("username").Value; var bb=document.getElementById("password").Value; if(aa==null || bb==null) { alert("Enter Again"); } else if((aa=="admin") && (bb=="12345")) { Alert("Hello Sir"); } else if((aa=="guest") && (bb=="67890")) { Alert("Hello Guest"); } else { Alert("Enter Valid Info"); } } </script> </head> <body> Username:<input type="text" id="username"/><br/> Password:<input type="text" id="password"/><br/> <input type="submit" onClick="match()"/> </body> </html> Hello to all. I need someone to help me with making code for some page, because I don't know lot about coding. What I want is to this script work only when someone click on text like "Start script", not when someone open page where this script is. Can someone help me with that? Thanks a lot. Quote: <script type="text/javascript"> var win = window.open("http://www.mysite.com/", "mywindow"); var interval; function closePopup() { win.close(); clearInterval(interval); } interval=setInterval(closePopup,10000); </script> Hi guys, as you can see i am newbie.. So ive been working with javascipt and html for about 2 days now. What im trying to do it make a really annoying website kind of like www.mudkipz.ws [go at your own risk], the site is a youtube video of mudkip pokemon that are really annoying they just say Mud-kip for about 9 minutes.. once you try to exit, messages pop up saying "Mud" And "Kip" After Clicking "ok" Its a Loop That goes on for ever! im trying to make something like this on dreamweaver but i have very little experience! Does anyone know how i could be able to make it so it can say [ "hahah i got you!" | |"Only way to exit is by going to this link" | | "Link" | |___________[ok]____________________ | Edit: I got the exit pop up message to work, now i just need the loop code! Any idea of how to put a link in the exit pop up message? Ok this is supposed to be a slot machine that works when I click the "Slot" button. If all the images match, then it is supposed to say "Congratulations...". If all the images do not match, then it is supposed to say "Sorry, you lose....". For one thing, I want the images to load after I hit the slot button and not when I refresh the page. Also, I've screwed up somewhere and I think I need another function option but I don't know where to put it or what to do. And last, my if, else statement isn't working. I'm pretty much new to Javascript and I don't know if the way I assigned the images to variables is even correct. Someone please help me. It would greatly appreciated. PHP Code: <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title> Slot Machine</title> <style type = "text/css"> table { width: 45em } th { text-align: left } th { text-align: center } th { text-align: right } div.red { color: red } </style> <script type = "text/javascript"> <!-- var pictures = [ "star", "blueSeven", "berry" ]; var pic1; var pic2; var pic3; pic1 = document.write ( "<img src = \"" + pictures[ Math.floor( Math.random() * 3 ) ] + ".gif\" />" ); pic2 = document.write ( "<img src = \"" + pictures[ Math.floor( Math.random() * 3 ) ] + ".gif\" />" ); pic3 = document.write ( "<img src = \"" + pictures[ Math.floor( Math.random() * 3 ) ] + ".gif\" />" ); function play() { var statusDiv = document.getElementById( "status" ); if ( pic1 = pic2 ) { if ( pic2 = pic3 ) statusDiv.innerHTML = "Congratulations, you win!"; } else statusDiv.innerHTML = "Sorry, you lose. " + "Please try again."; } </script> </head> <body> <form action = ""> <table> <tr><td /><td><input type = "button" value = "Slot" onclick = "play()" /></td></tr> </table> <div id = "status" class = "red"> Click the Slot button to play</div> </form> </body> </html> Hi everyone hope all well. I need your expertise. I have a problem with the email part of this javascript. Everything is working fine except for It will not validate when i add a period (.) before the @ sign. I am wanting to be able to put in an email like this abc.def@gmail.com or abc+def@gmail.com Here is the code for you to look at Code: <script type="text/javascript"> function validate_form() { if (!ValidatePhoneNumber(document.second.HomePhone.value)) { return false; } if(!ValidateZip(document.second.ZipCode.value)) { return false; } if ( document.second.degreeLevel.selectedIndex == 0 ) { alert ( "Please select degree level" ); return false; } if ( document.second.ProgramInterest.selectedIndex == 0 ) { alert ( "Please select area of study" ); return false; } if ( document.second.LevelofEducationCompleted.selectedIndex == 0 ) { alert ( "Please select level of education" ); return false; } if ( document.second.FirstName.value == '' ) { alert ( "Please Enter a First Name" ); return false; } if ( document.second.LastName.value == '' ) { alert ( "Please Enter a Last Name" ); return false; } if ( document.second.Address.value == '' ) { alert ( "Please Enter a Address" ); return false; } if ( document.second.City.value == '' ) { alert ( "Please Enter a City" ); return false; } if ( document.second.State.selectedIndex == 0 ) { alert ( "Please Select a State" ); return false; } if(!ValidateName(document.second.FirstName.value)) { return false; } if(!ValidateName(document.second.LastName.value)) { return false; } function ValidatePhoneNumber(field) { var valid = "0123456789"; var hyphencount = 0; if (field.length != 10) { alert("Please enter your 10 digits phone."); return false; } for (var i = 0; i < field.length; i++) { temp = "" + field.substring(i, i + 1); if (valid.indexOf(temp) == "-1") { alert("Invalid characters in your phone. Please try again."); return false; } } return true; } if(!EmailValid(document.second.Email.value)) { return false; } function ValidateZip(field) { var valid = "0123456789"; var hyphencount = 0; if (field.length!=5 ) { alert("Please enter your 5 digit zip code."); return false; } for (var i=0; i < field.length; i++) { temp = "" + field.substring(i, i+1); if (valid.indexOf(temp) == "-1") { alert("Invalid characters in your zip code. Please try again."); return false; } } return true; } function ValidateName(field) { var invalid="0123456789()-+=@#$%^&*!~`{}][|:;<>,?/"; for (var i=0; i < field.length; i++) { temp = "" + field.substring(i, i+1); if (invalid.indexOf(temp) != "-1") { alert("Invalid characters in your name field. Please try again."); return false; } } return true; } function EmailValid(email) { if(email=="") { alert("Email is required field!") return false } len = email.length if((email.charAt(1)=='.')||(email.charAt(1)=='@')||(email.charAt(1)=='.')) { alert("Invalid Email Please try again!") return false } if((email.charAt(len-2)=='@')||(email.charAt(len-2)=='.')) { alert("Invalid Email Please try again!") return false } count=0 dotcount=0 for (i=0; i< email.length; i++) { if(email.charAt(i)=='@') count++ if(email.charAt(i)=='.') dotcount++ } if((count !=1)||(dotcount !=1)) { alert("Invalid Email Please try again!") return false } return true } } </script> Im sure it is something small. i have tried changing things around but it will not work for me. Any help would be great. Thanks everyone Nim Hi all, Can some body help me i need a textbox and submit button.when i enter date in text box and click on submit button.Then my chart should display by passing my date(dynamic) through the code. how to design and code. Thanks.. Hello i have problem is i have penny auction script and i try to add auction and it show on indexpage assume 05-05-2011 but when the time hit 00.00 so date become to 6 and back to 5 in the morning maybe 12 hour and i try to change var.match round to var math.floor date become to 4 before midnight 2 minute and back to 5 when the time hit midnight again...so if this day is 5 and before midnight it will not become to 4 but when midnight come it will become to 6...so i dont know when item can end then this is code if someone can sort it out function calc_counter_from_time22(diff) { if (diff > 0) { hours=Math.floor(diff / 3600) minutes=Math.floor((diff / 3600 - hours) * 60) seconds=Math.round((((diff / 3600 - hours) * 60) - minutes) * 60) } else { hours = 0; minutes = 0; seconds = 0; } if(diff < 86400){ return twodigit(hours) + ":" + twodigit(minutes) + ":" + twodigit(seconds); } else{ var Tday = Math.floor(diff / (60 * 60 * 24)); var addDay = Tday; var d = new Date(); d.setDate(d.getDate()+addDay); mkMonth=d.getMonth()+1; mkMonth=new String(mkMonth); if(mkMonth.length==1){ mkMonth="0"+mkMonth; } mkDay=d.getDate(); mkDay=new String(mkDay); if(mkDay.length==1){ mkDay="0"+mkDay; } mkYear=d.getFullYear(); return mkDay+"-"+mkMonth+"-"+mkYear; } Code: <script type="text/javascript"> var aURL = "http://xmegatop100.com/"; if (aURL == http://xmegatop100.com/) { document.write("<p style="text-align: right;"> <a href="{$list_url}/index.php">1-50</a> | <a href="{$list_url}/index.php?start=51">50-100</a> | <a href="{$list_url}/index.php?start=101">100-150</a> | <a href="{$list_url}/index.php?start=151">150-200</a></p> <br><br> "); } else { document.write("<p style="text-align: right;"> <a href="{$list_url}/index.php?cat={$category_url}&start=1">1-50</a> | <a href="{$list_url}/index.php?cat={$category_url}&start=51">50-100</a> | <a href="{$list_url}/index.php?cat={$category_url}&start=101">100-150</a> | <a href="{$list_url}/index.php?cat={$category_url}&start=151">150-200</a></p> <br><br> "); } </script> What im trying to do is if i have url as http://mysite.com then read1 code , if my site has http://mysite.com/index.php?cat=~~~~ Then reads the else part.. am i doing something wrong? this doesnt work.. Hello every body i have a problem with javascript i wrote a script which process the entry of a text area 1 and i made the script process only the first line of the entry i want a method to make the script to process all of the lines which the user enter it OR make a varibals to every line entered from the user i am so sorry about the weak language thank you in advance hello, iam kind of new at javascript, but iam trying my best to be better and better. so i have 3 divs (my_block, my_image, my_description) as you see in my code below Code: <div class = "my_block"> <div class = "my_image"> <img src="images/pic.jpg" width="600" height="600"> </div> <div class = "my_description"> <a> Description goes here.... ! </a> </div> </div> just i want to display the "my description" div only after the 100% image loading completion which exist in "my_image" div. so how can i get this done with Javascript please ?? thanks a lot |