JavaScript - Something Really Simple I Hope!
Hello!
I have a script that prints a DIV and I am looking to set the font for the generated page, and the font color and size. But for the life of me, I cannot figure out if it can be done in this script, or if I have to setup a separate print.css. Here is my script: Code: <script type="text/javascript"> function PrintDiv_print_all() { var divToPrint = document.getElementById('print_all'); var popupWin = window.open('', '_blank', 'width=600,height=800,scrollbars=yes'); popupWin.document.open(); popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>'); popupWin.document.close(); } </script> I am still learning this stuff and any help is appreciated! Similar TutorialsWhat i have is a bit of Ajax code which would use the value of one select to populate the second select. So the code looked a little like this. Code: <select name="category" onchange="category(this.value)"><option>...</option></select> The Javascript code I wrote worked fine. Then when I wrapped the selects in a form, my onchange events wouldnt work. Im a bit of a Javascript novice so could someone point out what I have missed here. I have tested and it is the form that is blocking the onchange from working. Im testing this in Chrome. Thanks for your time. Hey all, i'm new here and first off, i'd just like to offer my sincerest appologies if i've posted this in the wrong section! I've made some basic HTML web sites in the past and now the company i work for has asked me to make one. Its a rubber roller manufacture company and i would like to make a page that will have input fields and a submit button that will send the inputted details to our sales manager's email address...something like this Contact Name: (input box) Company Name: (input box) Roller Diameter: (input box) Required Compound: (input box) Email Address: (input box) (SEND BUTTON) Also it would be a massive help if someone could tell me if it is possible for me to set it so that once the send button is clicked, it will send an email of the data but also redirect to another page (just saying thanks for input etc etc) HUGE thanks in advance!!! Hi Guys, For my Duke of Edinburgh award ( a scheme in the UK), I've started maintaining the local church website. I had a plan to use Javascript to create a variable array, containing references to a weekly bible reading, which would then be loaded up in the browser. The browser would then use the local date to decide which reading it takes (from the array), and would then take that reading from a separate website. Could anybody give me any suggestions or pointers regarding this script, or link me to some tutorials which would be suitable for a novice scripter - I'm 15, and only really know basic html and a few very basic bits of javascript/c++. Many thanks, Conor 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 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 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! 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; } 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> 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'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 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> 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 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 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 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? 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> |