JavaScript - Quick Help With Simple Code
Hi... i have this code:
<script type='text/javascript'> cookie_name = GetCookie("href_location"); if(cookie_name){ alert("Cookie found, redirecting to stored cookie."); document.location.href=cookie_name; } </script> I will like to create a iframe using the info from the "cookie_name" value <iframe name="FRAME1" src="cookie_name" width="350" height="320" frameborder="0" scrolling="auto"></iframe> I have a script that set a cookie with the value of a chosed website, what i need now is to create an iframe with that value. Any help will be apriciated. Sorry for my poor enlish Similar TutorialsI have a twitter widget at this side http://1905.gs/blog on the right sidebar. At the bottom of the widget there is the follow me link. I would like to embed a follow me "button" which I have created the script for: The button script: <a href="https://twitter.com/1905GS" class="twitter-follow-button" data-show-count="false" data-lang="tr">Takip et: @1905GS</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> And here is the current javascript link: http://www.1905.gs/blog/wp-content/p...tter-widget.js How I am trying to make it look like: http://a1202.hizliresim.com/u/d/2nryy.jpg thank you very much for your help, I need someone to make a small modification to this javascript code: <script type = "text/javascript"> function hyperlink() { var url = (location.href) url = url.replace(/\.(html)/i, "_2.html") window.location.href = url; } </script> Here is the situation: On this webpage: http://tehcake.com/video/30rock/2x14%20-%20Copyx.html where it says "Backup Links 1 2", if you click on the "1" in "Backup Links 1 2" it goes to this webpage, which is what it is supposed to do: http://tehcake.com/video/30rock/2x14%20-%20Copyx_2.html However, on this webpage, where it says "Backup Links 1 2", if you click on the "1" in "Backup Links 1 2" it leads to a non existing page by adding an extra "_2" to the end of the file name. Anyways, I need a way to modify this code (same one as above): <script type = "text/javascript"> function hyperlink() { var url = (location.href) url = url.replace(/\.(html)/i, "_2.html") window.location.href = url; } </script> This script subtracts ".html" and adds "_2.html" to the URL. Anyways, i need to change it so that if the filename has an _2.html in the file name, like in this URL: http://tehcake.com/video/30rock/2x14%20-%20Copyx_2.html the script would not add an extra _2 to the URL, instead it would just link to the same page. I dont know much about javascript so I need help to make this change. The code I commeted out dosen't work I want to check if its null and if so alert them. { // PART 2: YOUR CODE STARTS AFTER THIS LINE correctAnswer = Math.floor((Math.random() * 100) + 1); // For testing purposes. alert("Testing purposes, correct answer is: " + correctAnswer); var number = 0; //// Calculations //if (isNaN(number) = true) { // alert("Thats not a number"); //} //document.write(number); while (number != correctAnswer) { number = prompt("Wrong Number, guess again."); number = Number(number); if (number < correctAnswer) { document.writeln("Small guess: " + number); } if (number > correctAnswer) { document.writeln("Large guess: " + number); } if (number == correctAnswer) { document.writeln("Correct guess: " + number); } } } I would like to compare my work to the work of others, can you please solve this and post your result? Declare an 8 x 8 matrix and an array of length 22. 1.- Populate the matrix. 2.- Copy the elements of the first row of the matrix, the anti-diagonal, and the last row of the matrix into the array, to form a Z shape. 3.- Sort the array. 4.- Assuming that the data in the arrays are grades, compute the average of the grades stored in the even locations of the array. 5.- Copy the array back into the matrix.(back into the Z) 6.- Print out the matrix values. index.html Code: <html> <head> <title>:: wtmp</title> </head> <body> <p>Welcome to my page</p> <script type="text/javascript" src="file.js"></script> </body> </html> file.js Code: function one(p1, p2) { var j_text=p1+" "+p2; return j_text; } function two() { var rslt=one("Hi", "there!"); } document.write(rslt); var mainscrpt=one("Hello", "world!"); window.alert(mainscrpt); Simple random pic script that I found on the some other forum (I forget what it was) [CODE]var aryimages = new Array('images/pic/01.jpg', 'images/pic/37.jpg', 'images/pic/02.jpg', 'images/pic/family/08.jpg','images/pic/08.jpg', 'images/pic/food/03.jpg'); randompic.src = aryimages[Math.floor(Math.random() * aryimages.length)]; [CODE] code anchors to HTML markup [CODE]<img name="randompic" id="bg" />[CODE] it is working perfectly for Safari and Chrome. Nothing is showing for FF. Any suggestions appreciated. I just started learning JavaScript. I'm sure it's something really simple but I cannot figure out what is missing from my code. No matter what year I enter into the text box, I keep getting "The year you entered, 2080393, is a leap year." It's not returning false...ever. Can someone please tell me what I'm doing wrong so I can stop pulling my hair out? Thanks! <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Is It A Leap Year?</title> <script type="text/javascript"> /* <![CDATA[ */ function isLeapYear(year) { year = parseInt(year); var leapYear = true; var remainder = 0; if(isDivisibleBy(year, 4)) { leapYear = true; } if(isDivisibleBy(year, 100)) { leapYear = false; } if(isDivisibleBy(year, 400)) { leapYear = true; } if(leapYear) { window.alert("The year you entered, " + year + ", is a leap year."); } else { window.alert("The year you entered, " + year + ", is not a leap year."); } } function isDivisibleBy(year, divisor) { var remainder = 0; remainder = year%divisor; if(remainder == 0) { return true; } else { return false; } } /* ]]> */ </script> </head> <body> <form action="" id="GetLeapYear"> <p><strong>Is It a Leap Year?</strong></p> <p><strong>Enter a valid 4-digit year below to find out!</strong><br /></p> <p> <input type="text" name="year" size="20" style="color: black; border-style: solid; border-color: inherit; border-width: medium; background-color: Transparent" value="" /> <input type="button" value="Leap Year?" onclick="isLeapYear(document.getElementById('GetLeapYear').year.value);" /> </p> </form> </body> Here's the basic concept, its somewhat of a counter, and I think javascripts the way to go... Basically I'm looking to generate a running number... x + 11 = print the number The tricky part is, I need it to never stop, somewhat like a timer (example http://www.hashemian.com/tools/javascript-countdown.htm) but not a timer... Think the tally mark on McDonald's 99 billion served.. Any suggestions or ideas? can some please tell me what this line does... Code: <div onClick="getElementById('tInfo').onclick();"> Hi there, I'm not a js coder but needed to cobble something together for a simple IE7 "sniffing" task. It's basically taken from a helpful poster over at http://css-tricks.com/snippets/javas...rnet-explorer/ I'm pretty sure that what I've done is as inelegant as hell!! Although it works, I'd be grateful if someone could show me how to tidy things up. Many thanks Code: $(function(){ if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x; var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number if (ieversion<=7) $(".tooltipthumb").tipTip({attribute: "title", defaultPosition: "top", fadeIn: 200, delay: 0}); else if (ieversion>=8) $(".tooltipthumb").tipTip({attribute: "title", edgeOffset: 130, defaultPosition: "top", fadeIn: 200, delay: 0}); } else { $(".tooltipthumb").tipTip({attribute: "title", edgeOffset: 130, defaultPosition: "top", fadeIn: 200, delay: 0}); } }); $(function(){ $(".tooltip").tipTip({attribute: "title", fadeIn: 200, delay: 0}); }); $(function(){ $(".tooltip_small_thumb").tipTip({attribute: "title", edgeOffset: 90, defaultPosition: "top", fadeIn: 200, delay: 0}); }); $(function(){ if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x; var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number if (ieversion<=7) $(".tooltip_small_thumb").tipTip({attribute: "title", defaultPosition: "top", fadeIn: 200, delay: 0}); else if (ieversion>=8) $(".tooltip_small_thumb").tipTip({attribute: "title", edgeOffset: 90, defaultPosition: "top", fadeIn: 200, delay: 0}); } else { $(".tooltip_small_thumb").tipTip({attribute: "title", edgeOffset: 90, defaultPosition: "top", fadeIn: 200, delay: 0}); } }); Hi everyone, I've been coding Perl for quite some time, but I'm new to Javascript and can't quite figure this out. I want to call a Javascript function that is sent to the browser via a perl script. When I hard code the string "Fargo" into the code it works just fine, when I pass the word Fargo via a variable the script will not call the function what so ever. Is it possible to call a javascript function via a Perl script with Perl providing all the necessary data? Here is my code: #!/usr/local/bin/perl use CGI qw(:all); use CGI::Carp qw(fatalsToBrowser); use Cwd; print header; print "top<br><br>"; $data = "fargo"; print <<html; <html><head></head>my heading is here<br><body></body> <script type="text/javascript"> function testz(inbound) { document.write("im in ", inbound); } //the script will only work if I uncomment the line below and comment out two lines below //var data1="fargo"; var data1 = $data; testz(data1); </script> </html> html Thanks to everyone in advance for your help. So frustrating that lately I've been having trouble with the simplest of code, and this is about as simple as it gets. Matched it up with every similiar example I can find both in books and on the net, and it seems to be perfectly valid code, but when I run it, nothing. :S 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> <script language="javascript" type="text/javascript"> function favouriteColour() { var index = document.getElementById("select1").options[document.getElementById("select1").selectedIndex].value; document.getElementById = "Your favourite colour is " + index; } </script> </head> <body> <select id="select1"> <option></option> <option id="black" onchange="favouriteColour()">Black</option> <option id="white" onchange="favouriteColour()">White</option> <div id="favcolour"></div> <option> </select> </body> </html> Thanks in advance. I'm getting a runtime error on the code in red. Can anyone see anything that is wrong with it? These functions are called by an onBlur by the way. <script type="text/javascript"> //THIS GENERATES QUANTITY OF MATERIALS function generate3() { var tot3 = document.ComplianceForm.materialamount.value; var tbl3 = document.getElementById("quantitymaterials"); if (tot3 > 28) { alert("16 is total amount of materials for now."); } else { for(var i =1; i<=tot3; i++) { tbl3.innerHTML = tbl3.innerHTML + '<tr><td colspan=\"2\"><hr /></td></tr><tr><td>'+i+') Quantity: <input type=\"text\" name=\"qty'+i+'\" size=\"3\"\/></td><td>Description: <input type=\"text\" name=\"material'+i+'\" /></td></tr><tr><td colspan=\'2\' \">Your Truck<input type=\"checkbox\" \/> Other truck<input type=\"checkbox\" \/> Cash<input type=\"checkbox\" \/> Credit Card<input type=\"checkbox\" \/> P.O.<input type=\"checkbox\" \/></td></tr>'; } tbl3.innerHTML = tbl3.innerHTML + '<br>'; } } function remove3() { var tot3 = document.ComplianceForm.materialamount.value; var tbl3 = document.getElementById("quantitymaterials"); for(var i =1;i<=tot3; i++) { tbl3.innerHTML = ""; document.ComplianceForm.materialamount.value = ""; tbl3.innerHTML = ""; } } </script> I'm pretty new to Javascript so don't lay into me too hard. haha thanks. -Ty Hello, What I need is a simple service area, zip code validation form that redirects to a certain URL when a valid zip code is submitted and a different URL when an invalid zip code is submitted. I found a form script example that works well with only a single zip code. My problem is I can't figure out how to modify it so that multiple zip codes are valid. Here is the head part. 60016 is one of about 50 valid zip codes I need the form to accept as valid - [code] <script> var correctCode = "60016"; function validateCode() { var code = document.getElementById("codeTextBox").value; if (code == correctCode) { window.location.href = "/ggc/test1"; } else { window.location.href = "/ggc/test2"; } } </script> [code] Here is the body part - [code] Please enter your zip code: <input type="text" name="codeTextBox" id="codeTextBox" /> <input type="submit" name="Submit" value="Submit" onclick="validateCode()" /> [code] Basically, I have a Simon Says game with very simple functions but I added an image map with buttons that I now want to use, rather than a table with images as buttons. The problem is, now I can't get the game to work with the image map. Can anyone help me?
Hi all. I'm learning JS from pretty much scratch and the first thing I'm trying to do is simply make an image fade function. I just can't seem to make it work though, the image starts off at the right opacity (im this case 0.5) but after that the page goes white and the script never stops. It does seem to be counting up normally "opacity: 0.6 opacity: 0.7" etc. though. Code: <img src="1.jpg" id="pic1"> <script type="text/javascript"> var amount = 0.5; var target = document.getElementById('pic1'); function fade() { if (target.style.opacity < 1.0) { target.style.opacity = amount; amount = amount + 0.1; document.write("<br>opacity: " + target.style.opacity); setTimeout("fade()", 1000) //fade(); } } fade(); </script> edit I rewrote it to make it simpler but still having basically the same problem D:! |