JavaScript - Help With Simple Matter.
I am trying to use document.get to change the style of a class.
The CSS is: PHP Code: .jewelToggler{background:no-repeat url(/rsrc.php/z7VU4/hash/66ad7upf.png);display:inline-block;height:31px;position:absolute;text-decoration:none;width:24px} and the HTML is such: PHP Code: <a class="jewelToggler" id="jewelRequest" title="Friend requests" href="http://www.facebook.com/reqs.php" onclick="var toggle = function() {this.onclick = function(e) {e = e || window.event;e && Event.prevent(e);Jewel.toggle(this, "[fb]requests");}.bind(this);this.onclick();}.bind(this);this.onclick = function() {CSS.toggleClass(this.parentNode, 'openToggler');return false;}.bind(this);this.onclick();onloadRegister(toggle);return false;" accesskey="3"><span class="jewelCount"><span id="jewelRequestCount">0</span></span></a> mainly focusing on [a class="jewelToggler"] So naturally I assumed that his javascript would work: PHP Code: document.getElementById('jewelToggler').getElementsByTagName("a")[0].style.backgroundImage="url('myimgurl')"; But it doesn't change anything. Comments? Ideas? Thanks. Similar TutorialsI am not sure why this is happening, but the script is working and throwing an alert but still submits. Code: <script type="text/javascript"> function check(a,b) { var obja = document.getElementById('email') var objb = document.getElementById('confemail') if (obja.value==objb.value) {} else {alert("The e-mail fields aren't the same!!") } return false; } </script> Code: <table> <tr><td colspan="2">Email:</td></tr> <tr><td colspan="2"> <input type="text" name="email" class="wide" id="email"></td></tr> <tr><td colspan="2">Confirm Email:</td></tr> <tr><td colspan="2"> <input type="text" name="confemail" id="confemail" class="wide"></td></tr> <tr><td colspan="2"><br /> <input name="Submit" type="submit" value="Submit Help Request" onclick="check('email','confemail') "></td></tr> </table> does anyone see the issue? Thanks for any help. I imagine this would be very simple for someone who knows javascript. I want to have three fields. First field is "posted speed limit", second field is "actual speed" and third field will be the output field. All the script needs to do it subtract the posted speed from the actual speed and add a ZERO to the end; which is the amount of the speeding ticket. The minimum fine is $100, however. So, 5 miles over the speed limit would be $100 (minimum value) 15 miles over the speed limit would be $150 (add a zero) 35 miles over the speed limit would be $350. etc. I know very little Javascript, if anyone could help me out with this, I'd appreciate it. Thanks, Sean Hello, Below is my Javascript, CSS and HTML code for the navigation menu on http://033691f.netsolhost.com/stnew/ -- a test site for my company. Note: I did not write the Javascript code nor do I know how to write javascript. I take no credit. When the page first opens, the navigation shows fully expanded for a second, then collapses all. I would like to cut out the expanded view if possible and have the page load with the menu fully collapsed. Is there any way that would work? Thank you in advance for any input! Code: function initMenus() { $('ul.menu ul').hide(); $.each($('ul.menu'), function(){ var cookie = $.cookie(this.id); if(cookie === null || String(cookie).length < 1) { $('#' + this.id + '.expandfirst ul:first').show(); } else { $('#' + this.id + ' .' + cookie).next().show(); } }); $('ul.menu li a').click( function() { var checkElement = $(this).next(); var parent = this.parentNode.parentNode.id; if($('#' + parent).hasClass('noaccordion')) { if((String(parent).length > 0) && (String(this.className).length > 0)) { if($(this).next().is(':visible')) { $.cookie(parent, null); } else { $.cookie(parent, this.className); } $(this).next().slideToggle('normal'); } } if((checkElement.is('ul')) && (checkElement.is(':visible'))) { if($('#' + parent).hasClass('collapsible')) { $('#' + parent + ' ul:visible').slideUp('normal'); } return false; } if((checkElement.is('ul')) && (!checkElement.is(':visible'))) { $('#' + parent + ' ul:visible').slideUp('normal'); if((String(parent).length > 0) && (String(this.className).length > 0)) { $.cookie(parent, this.className); } checkElement.slideDown('normal'); return false; } } ); } $(document).ready(function() {initMenus();}); Code: <ul id="menu1" class="menu" style="margin-top:20px;"> <li><a class="m0" href="index.php" style="background-color:#222; color:#fff;">HOME</a></li> <li><a class="m1" href="">WHO WE ARE ...</a> <ul><li><a href="">Company Overview</a></li> <li><a href="">Clientele</a></li> <li><a href="">Multimedia</a></li> <li><a href="">Careers</a></li> <li><a href="">Contact Us</a></li> </ul> </li> <li><a class="m1" href="">WHAT WE DO ...</a> <ul><li><a href="">Promotional Products</a></li> <li><a href="">Screen Printing</a></li> <li><a href="">Embroidery</a></li> <li><a href="">Signage</a></li> <li><a href="">Web Design</a></li> </ul> </li> <li><a class="m3" href="">FIND PRODUCTS ...</a> <ul><li><a href="">Web Search</a></li> <li><a href="">Online Catalogs</a></li> </ul> </li> <li><a class="m4" href="">SUPPORT TOPICS ...</a> <ul><li><a href="">General Information</a></li> <li><a href="">Available Brands</a></li> <li><a href="">Artwork Submissions</a></li> <li><a href="">Color & Substrate Charts</a></li> <li><a href="">Dartman Game</a></li> </ul> </li> <li><a class="m5" href="http://www.screentek.net/blog">READ OUR BLOG</a></li> </ul> Code: ul.menu { border-bottom:1px solid #ccc; } ul.menu, ul.menu ul { list-style-type:none; margin: 0; padding: 0; width: 240px; } ul.menu a { display: block; text-decoration: none; } ul.menu li { margin-top: 0px; border-top:1px solid #ccc; font-size:10pt; font-family: Segoe-B; } ul.menu li a { background: #fff; color: #333; padding: 3px 20px; } ul.menu li a:hover { background: #2b76b7; color:#fff; } ul.menu li ul li a { background: #fff; color: #2b76b7; padding-left: 35px; font-size:10pt; font-family: Segoe-R; } ul.menu li ul li a:hover { background: #eee; border-left: 5px #000 solid; padding-left: 25px; color:#333; } .code { border: 1px solid #ccc; list-style-type: decimal-leading-zero; padding: 5px; margin: 0; } .code code { display: block; padding: 3px; margin-bottom: 0; } .code li { background: #ddd; border: 1px solid #ccc; margin: 0 0 2px 2.2em; } .indent1 { padding-left: 1em; } .indent2 { padding-left: 2em; } .indent3 { padding-left: 3em; } .indent4 { padding-left: 4em; } .indent5 { padding-left: 5em; } Hi Folks, I've been trying to learn Javascript, I'm fluent with CSS, HTML and not to bad with jQuery and PHP. But I've been trying to learn the core fundamentals of JavaScript. Basically, I have a friend who has a strange take on the English language, so I wanted to make him a translator, so that you could input one of his misspellings and it would bring up the proper word. <html> <head> <script type="text/javascript" src="js/modernizr.js"></script> <script type="text/javascript"> // Mox spellings function checkMox () { var bm = document.forms["transMox"]["mox"].value; if (bm == "wid") { document.write("wid = with"); } else { document.write("Please enter a Moxism"); } }; </script> </head> <body> <header> <div id="title"> <h1>I drink!</h1> <h2>Therefor I am...</h2> </div> <nav> <ul> <li>The history of Moxisms</li> <li>Examples of Moxisms</li> <li>The man himself...</li> </ul> </nav> </header> <h3>Welcome to the Big Mox translator</h3> <form id="transMox" action="#output" method="post" onsubmit="return checkMox()"> <input type="text" id="mox">Enter a Moxism</input> <br /> <input type="submit" id="submit" onSubmit="checkMox();">G0!</input> </form> <div id="output"> </div> </body> </html> Obviously that's just for one word, so I wondered how to structure more words into an array or something? Anyway, cheers in advance for the help guys! Hi, Im trying to make an imacro/javascript script that checks a webpage for names, and if either of the names are found, i want the script to alert me, if not, continue looping/reloading the page. Im not at all good with javascript, imacro is more sort of my thing, however what i do have, doesnt seem to do anything. var links = document.getElementsByTagName('a'); for (var i in links){ if (links[i].value == "Simon" || links[i].value == "James"){ alert("ATTENTION"); } } i dont know if its something simple i'm missing, or whether im nowhere near, but ive spent all day trying to do this, and lost all patience. Any suggestion/fixes? Hi, I have some Javascript, what I want to hapen is, when the variables hour and randomhour are the same, the message hello is displayed. What actually happens is the message will display all the time, and dissapear when randomhour is 0. Here is my script: Code: <script type="text/javascript"> //Gets hour and minute of day var d = new Date(); var hour = d.getHours(); var minute = d.getMinutes(); //Generates a random hour and minute var randomhour=Math.floor(Math.random()*24) var randomminute=Math.floor(Math.random()*60) document.write(hour); document.write(minute); document.write("----"); document.write(randomhour); document.write(randomminute); if (hour = randomhour) { document.write("<b>Hello</b>"); } </script> Basically i have an image of a ball that i am trying to make bounce from top to bottom so far it is just going to the bottom and stopping plz help thanks <head> <title></title> </head> <body> <center> <input type="button" value="Click" onClick="moveDown()"/> </center> <img id="Ball" src="ball.jpg" style="position:absolute; top:100px; left:100px;"/> <script language="JavaScript"> var Image = document.getElementById("Ball"); var Position = 100; var direction = 1; function moveDown() { if(direction > 0) { Image.style.top = parseInt(Image.style.top) + 20+'px'; } if(parseInt(Image.style.top)> 100 || direction > 1 ) direction = 1 if(parseInt(Image.style.top)> 500 || direction < 1 ) { direction = -1 Image.style.top = parseInt(Image.style.top) - 20+'px'; } } setInterval ("moveDown()", 50 ); </script> </body> </html> http://www.outwarstop.com/woz/woz09r3a.php On this page located around where it says Drops under where it says "Sha-Zhul ArchDemon [60]" are the mouseover's but the location of the popup doesnt come up at the mouse, but on the left side of the table, i need help gettin the popup to appear where the mouse is located. I'm a student learning javascript, I'm having a very basic problem. I have to write a script that outputs XHTML text that keeps displaying in the browser window that multiples of the integer 2, namely 2, 4, 8, 16, 32, 64, etc. This is the code i have, Code: <!-- var product=2; while { product =2*product; } document.writeln( +product+ ); // --> And it pretty much does nothing. Help would be much appreciated Dave For the first program I am trying to have the user input the password "stamp" to advance to the next page which is a pizza menu. The first program is supposed to give the user 3 tries and if they do not get it correct an alert is to pop up and tell them how many tries they have left. If they do not get it correct the input field for the riddle is to be locked. However if they have it correct they should be forwarded to the pizza menu. Code: <html> <body> <FORM name= "myForm"> <h3> What goes around the world but stays in a corner?</h3> <br> <INPUT type="password" name="passPhrase" id="pass"> <script language= "javaScript"> alert("Enter the correct password to proceed"); function checkpass(form) { if(form.passPhrase.value == "stamp") { alert("page unlocked!"); form.compute.disabled = false; form.authenticate.disabled = true; } else alert("that is not the correct response!"); </form> } </script> </body> </html> For the second program I am having a few small problems, I need to make a button that updates and clears the order. The updated order is supposed to be displayed in the text box that I have at the bottom. Also I am trying to make a function that computes the total cost for the order. Code: </head> <body> <body bgcolor="Silver"> <p> <center> <form method="post" > <p><font size="+4"><strong><font color="#000000">Lance's Pizza <br></font><font size="+4"><strong><font color="#000000"><img src="pizza.jpg" width="163" height="134"></font></strong></font></strong></font></p> <center> <p><strong> Pizza Size:</strong></p> <p> <input type="radio" name="size" value="mini" id="Size_mini"> Mini 14in [$9.99] <input type="radio" name="size" value"=medium" id="Size_Medium"> Medium 16in [$12.99] <input type="radio" name="size" value="large" id="Size_Large"> Large 18in [$15.99] </p> <p><strong>Toppings:</strong>: <center> <input name="toppings" type="checkbox" id="Pepperoni"> Pepperoni [$0.50] <input name="toppings" type="checkbox" id="Suasage"> Sausage [$1.00] <input name="toppings" type="checkbox" id="Greenpeppers"> Green peppers [$0.25] <input name="toppings" type="checkbox" id="Onions"> Onions [$0.25] </p> <input name="toppings" type="checkbox" id="Mushrooms"> Mushrooms [$0.50] <input name="toppings" type="checkbox" id="Olives"> Olives [$0.25] <p> <TEXTAREA NAME="" ROWS="10" COLS="40" onBlur="blurHandlerRouting"> </TEXTAREA> <br><input name="clear" type="button" value="Clear" onClick="Reset();"> </p> </form> </p> </body> </html> I have very limited understanding of programming, but I want to do something with javascript in the browser and don't know how to go about it. I know it could be done in C or some other language, but I have even less experience with that, so I want to see if I can do it in the browser. I have a questionnaire that the respondents filled out by hand, and I have to tally the results. Rather than go through and tally up the results for each question by hand on paper, I'd rather just be able to punch the values for the answers (the questions are "worst to best; 1-5" type responses) on the 10-key, have it add 1 to the appropriate box for each question, move to the next question, wait for my next entry of 1-5, and start back at the beginning again when I'm finished inputting answers for all the questions. I have an idea that there'd be 5 boxes per question for the tallied results and a box alongside each of those for entry of the answer. If you input "1" in that box, it'd add 1 to the first box; if you hit "2," it'd add 1 to the second box; if you hit "3," it'd add 1 to the third box, etc. I know this probably requires onKeyDown or onKeyUp to get the value of the answer, but I'm not sure how to get values captured from onKeyDown/Up through the javascript and back into the appropriate boxes. I'm not sure if I need an if...then conditional in the javascript or if it can be done some other way. Anyway, can anyone post some simple, sample code so I can get this going for at least one question and then I can scale it up from there? Thank you! i have this simple js example to click Delete Post and then give the user two options. If they click yes then they go that page...but how do i set it to where when they click cancel it goes back to "Delete Post" ??? i suck at javascript Code: <html> <body> <p><b>Delete Post</b></p> <script type="text/javascript"> window.onclick=function(){ document.getElementsByTagName("p")[0].innerHTML="<b><a href='#'>Delete</a> || Cancel</b>" } </script> </body> </html> Hi, I need a very simple script that will do the following : I have a HTML form. I have an input call "title". Say I wrote "fleur-de-lys" I have a text area call "text" When I hit the submit button I want to do : 1. Create a HTML webpage with the name in input : fleur-de-lys.html 2. Add the text in "text" somewhere in the body of that new file fleur-de-lys.html 3. Add a preview of that text somewhere in my index page Basically it's like you post a new article on wordpress or whatever, but I just want something simple no database and just need help on how I do this. Thank you very much I have a simple javascript function in a page using the DataTables JQuery plugin, but am having an issue. I have a While loop that cycles through a 2D array of table data. The intent of the loop is to grab the first column on every row of a table, and if there is a value in the column, add it to a running total. I've confirmed that the If statement only executes when there is something in the cell, so that is working fine. Code: function fnCalculateGPA ( ) { var tableData = $('#myDataTable').dataTable().fnGetData(); var totalCredits = 0; var i = 0; while (i <= 21){ if (tableData[i][0]){ totalCredits += Number(tableData[i][0]); } i++; } alert(totalCredits); $("div.gpb").html('<b>GPA:</b> <label name="gpa_display">'+totalCredits+'</label>'); } When I run this as is, the function seems to stall and the alert on the bottom does not even execute. If I take the While loop out and manually loop through the array myself, everything works fine. If I comment out Code: totalCredits += Number(tableData[i][0]); everything is fine, minus the total is not calculated obviously. What on that line is causing the While loop to stall? What am I missing here? I know it is going to be something simple, but this has been driving me nuts for hours now!! Any help would be appreciated. but I just can't figure it out. I have trawled the net for a solution and tried many different things that I have seen but still no luck. Maybe the answer is staring me right in the face and I just can't see it. The code it executing the first time but as the setTimeout tries to start the second loop I get an error 'box is not defined'. Any suggestions and explanations of what I am doing wrong much appreciated! Code: function expand(box) { var box = document.getElementById(box); var originalHeight = parseInt(box.style.height); var inc = 5; newHeight = (originalHeight + inc); box.style.height = newHeight + "px"; int = setTimeout('expand(box)',100); } Hey guys, I'm new to jquery and I'm sure this is a VERY simple problem.. Here's my code Quote: <style type="text/css"> #box { background: red; width: 300px; height: 300px; display: none; } </style> <script type="text/javascript"> $(function() { $('a').click(function() { $('#box').slideDown(4000); }); }); </script> </head> <body> <div id="box"></div> <a href="#">Click Me!</a> </body> </html> As you can see it's pretty simple, I've made the box slideIn. My problem is I want to make a separate button to slide it back out, but because I've used the "a" tag it's associating all links with the same function, how do I get around this? I'm sure it's really simple! Thanks I have been having problems adding checkboxes and option selects in the same function.. Here's what I have. Code: <script type="text/javascript"> function bonuscalc() { var aaaa = document.getElementById("aaaa").value; var bbbb = document.getElementById("bbbb").value; var cccc = document.getElementById("cccc").value; if (dddd.checked){ var dddd = document.dddd.value = 2; } else { var dddd = document.dddd.value = 1; } var eeee = document.getElementById("eeee").value; var bonus = aaaa* bbbb * dddd * cccc * eeee; var roundbonus = Math.round(bonus*10)/10; document.getElementById("roundbonus").value = roundbonus; } </script> Javascript first.. The part I'm not sure about is the if/else part for checbox. Now the html: Code: <form action="" id="calc1"> <table width="100%"> <tbody> <tr> <td>A status: <select id="aaaa"> <option value="1.1">A1</option> <option value="1.02">A2</option> <option value="1">A3</option> <option value="0.95">A4</option> </select> </td> <td>B status: <select id="bbbb"> <option value="1">0%</option> <option value="0.99">1%</option> <option value="0.98">2%</option> <option value="0.97">3%</option> <option value="0.96">4%</option> <option value="0.95">5%</option> <option value="0.94">6%</option> <option value="0.93">7%</option> <option value="0.92">8%</option> <option value="0.91">9%</option> <option value="0.90">10%</option> </select> </td> <td>E status:<input id="eeee" type="text" /> </td> <td>D status: <input id="dddd" name="dddd" type="checkbox"> </td> <td>C status: <select id="cccc"> <option value="1">No</option> <option value="1.2">Yes</option> </select> </td> </tr> <tr> <td width="100%"> <input type="button" value="Submit" onclick="bonuscalc()" /> <br /> Result: <input type="text" readonly="readonly" id="roundbonus" /> </td> </tr> </tbody> </table> </form> I hope it's not too confusing. The idea is to assign value 2 if the checkbox is checked and value 1 is it isn't.. Im new to JavaScript so take it steady, i have an array: <script type="text/javascript"> var colOne [0] = new Array("Copyright", "Council - spending plans - consultation", "Data protection"); var colTwo [1] = new Array("Digital Region", "Freedom of information", "Libraries - online information resources"); var colThree [2] = new Array("Our standards", "Test"}; document.write(colOne[0]); </script> anyone can tell why it does not work? How would I add up a array of numbers in a function? My numbers keep getting written as strings, instead of adding onto each other. I am a beginner. function (myNumbers) { var number = [6,9,10,13,14]; var total = 0; for(var total=0; total < number.length; total = total + 1) { total = total + number; document.write(total); } } myNumbers(); This is just an excercise. hi guys i am pretty new to javascript and i'm having trouble with this code: Code: <HTML> <HEAD> <TITLE></TITLE> <SCRIPT LANGUAGE = "JAVASCRIPT"> var recipient; // Declare other variables here recipient = window.prompt('Please enter the name of the recipient', ''); // Prompt for other values here // Output the customised greeting here </SCRIPT> </HEAD> <BODY> </BODY> </HTML> What I need it to do is pop up with 3 input boxes. 1 for the reciever, 1 for the occasion (e.g. birthday ect) and another from the sender. and i need to be able to show it in the browser too. |