JavaScript - Need Help With Basic Javascript Programming
Hi so i am using onClick="myPopup(); on a button and when someone clicks on the button, it pops up an advertisement in a new tab.
But is there a way to make the users stay on the page where the button is located instead of forcing the browser to automatically switch to the advertisement tab when a button is clicked? Similar TutorialsIndyNS I am trying to create a dynamic form on my webpage. What I want to do is repeat this process multiple times on the same page. I know I have to have unique id's but I am not for sure how to set them. // JavaScript Document function addRowToTable(){ var tbl = document.getElementById('Division'); var lastRow = tbl.rows.length; // if there's no header row in the table, then iteration = lastRow + 1 var iteration = lastRow; // var iteration = lastRow + 1; var row = tbl.insertRow(lastRow); // cell 0 var cell0 = row.insertCell(0); var el = document.createElement('input'); el.type = 'text'; el.NAME = 'Resource[]'; el.size = 30; cell0.appendChild(el); //cell 1 var cell1 = row.insertCell(1); var el = document.createElement("select"); cell1.innerHTML + '<option value="0">Avaliable</option>' + '<option value="1">Busy</option>' //cell 2 var cell2 = row.insertCell(2); var el = document.createElement('input'); el.type = 'text'; el.NAME = 'Comment[]'; el.size = 25; cell2.appendChild(el); } Hello all, I am having some trouble getting my Javascript code to work properly. I want to create a program that allows two objects to race to a certain point which is 1000px in my program. I have figured out how to get the images to race at random speed, and I have figured out a function to reset the program if the user chooses to restart. Basically I can't figure out how to get the clearTimeout() to stop the Race() function when it reaches 1000px. I am fairly new to the Javascript world and could really use some suggestions or a point in the right direction. Thanks in advance, AJ. Here is my program so far: <body> <script language="JavaScript" type="text/javascript"> <!-- function StartUp() { if ((car1.style.pixelLeft<1000) && (car2.style.pixelLeft<1000)) { Race(); } else { alert(); } } function Race() { car1.style.pixelLeft+=(Math.floor(Math.random()*11)); car2.style.pixelLeft+=(Math.floor(Math.random()*11)); stop=setTimeout("Race()",50); } function Restart() { clearTimeout(stop); car1.style.pixelLeft=10; car2.style.pixelLeft=10; } function swapImage() { var image = document.getElementById("imageToSwap"); var length = document.getElementById("Road"); image.src = Road.value; } //--> </script> <div id="car1" style="position:absolute; top: 10"> <img src="Car1.gif" alt=""/> </div> <div id="car2" style="position:absolute; top: 75"> <img src="Car2.gif" alt=""/> </div> <img id="imageToSwap" src="Road1000.gif" alt=""/> <form name="form1"> <br> <input type="button" value="Race" onClick="StartUp()"> <input type="button" value="Restart" onClick="Restart()"> <br> Track Length: <select id="Road" name="Road" onChange="swapImage()"> <option value="Road1000.gif">1000 feet</option> <option value="Road750.gif">750 feet</option> <option value="Road500.gif">500 feet</option> <option value="Road250.gif">250 feet</option> </select> </form> </body> Friend i concern with some that man told me , JavaScript programming is the best effective for website development. so how it is tell me ?
I need to know two things. How do you position an alert or prompt to anywhere on the screen. How do you change the font for the alert or prompt (i.e Hebrew) Thanks in advance D.A. I have traditionally stayed away from javascript because until relatively recently, the lack of decent documentation has made me want to smash the computer in complete frustration!! Now, I have found this little (seemingly quite new) gem which has, for the first time, explained javascript OO programming to me in five minutes flat, and I understand it perfectly!! It's not hard ... it's really not that hard ... but so many people on the net make such a hash of trying to explain it. Thank you Mozilla: https://developer.mozilla.org/en-US/...ted_JavaScript I have to take more javascript programming classes and I'm really not good at it. I desperately need help. I own Visual Basic, but it's a little difficult to use. What is the best book, online resource, and software for programming in javascript?
Hi All, I m newbie on JavaScript Coding. I have Form where the there are 4 radio buttons. Requirement is OnClick of Each radio buttons, some Div must Greyed out. <input type="radio" name="cf_basic_type" value="Apartment" checked="checked" />Apartment <input type="radio" name="cf_basic_type" value="Villa" />Villa <input type="radio" name="cf_basic_type" value="Independant" />Independant house <input type="radio" name="cf_basic_type" value="Plot" />Plot</div> and Grey Part of Form is: Area Size:<input type="text" name="cf_area_size" id="cf_area_size" /></div> Plot Size:<input type="text" name="cf_area_length" id="cf_area_length" /> <input type="text" name="cf_area_width" id="cf_area_width" /> so for Plot radio selected the 'Area Size' must be greyed out but when others radio button selected is must be active For Apartment radio selected or Villa radio selected, Plot Size must be greyed out. Hope that makes clear.... Its very Urgent kindly help me with this.. Thnks in Advnce Hi, I've just started learning JavaScript - actually started about half an hour ago. I have an extensive knowledge of Lua (if you've heard of it), so the concepts of programming aren't new to me. This code isn't doing anything. The HTML code makes the hyper-linked pictured show, but it doesn't do anything when the mouse rolls over it. The JavaScript code is saved in scripts/titleImage_rollover.js, and I'll show the HTML code as well. JavaScript: Code: <!-- // image rollover for header function image_rollover(){ //show a set of random images switch(math.floor(math.random()*5+1)) { case 1: document.getElementById("logo").src = "images/t2m_logo.png"; break; case 2: document.getElementById("logo").src = "images/pighead10_halloween.png"; break; case 3: document.getElementById("logo").src = "images/pighead10_easter.png"; break; case 4: document.getElementById("logo").src = "images/pighead10_classic.png"; break; case 5: document.getElementById("logo").src = "images/pighead10_combat.png"; break; } } //reset image to normal function image_reset(){ document.getElementById("logo").src = "images/pighead10.png"; } //--> HTML: < 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>pighead10.com | Home</title> <style type="text/css"> .link1 A:link{text-decoration:none;} .link1 A:visited{text-decoration:none;} .link1 A:active{text-decoration:none;} .link1 A:hover{text-decoration:underline;color:blue;} </style> <script type="text/javascript" src="scripts/titleImage_rollover.js"></script> </head> <body style="font-family:arial;color:red"> <a href="http://www.roblox.com/User.aspx?ID=2969907"> <img id="logo" src="images/pighead10.png" width="150" height="200" onmouseover="image_rollover()" onmouseleave="image_reset()"/> </a> </body> </html> Also, is there a way to view some kind of output in JavaScript? Hi, I'm trying to create a video box on a website that plays a youtube video and then automatically plays random recommended videos with no break in playback. An endless playlist created by youtube based on the initial video. Youtube uses Javascript API. I have never used Javascript before but i'm just trying to get the video to play as above. There are few tutorials online and I couldn't find anyone trying to do a similar thing. If you have any idea how i'd go about it or if not where i could find some information to help. Thanks. Hey guys! New user here and I just need a little help with some basic Javascript I must write a function that 'shows' the corresponding part of the form depending on what the user has selected. So... for example, if I select 'Pizza', the div #section2 with the question about Pizza type should be shown. All the sections that are not selected should be hidden. For example, if 'Mexican' is selected, the sections for 'Pizza' and 'Thai' should be hidden. I want this function to also display a message in the JavaScript console indicating which food type is selected. Apparently I'm supposed to use 'console.log("")'??? I'm using an external javascript file called prac8.js If anyone has any idea how to do this I'd be very greatful Code: <!DOCTYPE html> <html> <head> <title>Prac 8 example</title> <script type="text/Javascript" src="prac8.js"></script> <style> #section2, #section3, #section4 { display:none; border:1px solid gray; padding:8px; margin-top:12px; width:400px; } #dessertmsg { color:green; } </style> </head> <body> <h1>Prac 8 example</h1> <h2>A Food Survey</h2> <form id="survey" action="#" method="post"> <div id="section1"> <label for="food">What is your favourite type of food?</label> <select id="food" onchange="selection()"> <option value="pizza">Pizza</option> <option value="mex">Mexican</option> <option value="thai">Thai</option> </select> </div> <div id="section2"> What is your favourite type of pizza?<br> <label for="hawaiian">Hawaiian</label><input type="radio" id="hawaiian"> <label for="supreme">Supreme</label><input type="radio" id="supreme"> <label for="vegetarian">Vegetarian</label><input type="radio" id="vegetarian"> </div> <div id="section3"> What is your favourite Mexican food?<br> <label for="burrito">Burritos</label><input type="radio" id="burrito"> <label for="chilli">Chilli con carne</label><input type="radio" id="chilli"> <label for="taco">Tacos</label><input type="radio" id="taco"> </div> <div id="section4"> What is your favourite Thai food?<br> <label for="stir">Stir-fry</label><input type="radio" id="stir"> <label for="noodle">Noodles</label><input type="radio" id="noodle"> <label for="curry">Curry</label><input type="radio" id="curry"> </div> <label for="dessert">What is your favourite dessert?*</label> <input type="text" id="dessert" onchange="checkForm()"><br> <div id="dessertmsg"> </div> <input type="submit" value="Submit" id="subbutton" disabled> </form> </body> </html> Hi, Please i am confuse to know the work of this sign (!)...which is exclamation sign in programming. i have this code here which which i remove the exclamation sign (!)..it dont work but when i add it ,then it work. Here is the code <script type="text/javascript"> function getvalue() { var mytextfield=document.getElementById("mytext"); if(mytextfield.value!="") { alert("You Entered:"+mytextfield.value) } else{ alert("would you enter some text") } } </script> <input type="text" id="mytext" size="30"> <input type="button" value="check" onclick="getvalue()"> Please help me to understand the use of this sign !. Thank you. Clement Osei. Hi guys, I am new to learning javascript and have a test tomorrow on for loops. I know the answers to the three following loops but i wondered if anyone could take the time to explain to me how to find the answer from the code as I have no idea on how to find the answers (the answer is what is displayed in the alert). Many thanks, Mike The loops are these three: 1. var a=4;b=6; for(var c=0;c<=a;c++){b=b+c;} alert(b); (answer is 16) 2. var v=1; for(i=1;i<5;i++) for(j=2;j<5;j++) v+=1; alert(v); (answer is 13) 3. var s=0; for(i=0;i<=8;i++) if((i%2)==0)s+=1; alert(s); (answer is 5) Hello All Its my first post on this forum. I have a database setup with tables that use my form element names as column names. Now i have successfully retrieved column names and values from the server side to the client side. . I have the column name stored in var columnName How can I get the type of form element type and how can i set the value to it Thanks for your help #Javalove. . .unless otherwise stated. . .! Hi, I'm very much a newbie regaridng javascript and have been looking around and experimenting and have created a javascript although it does not function(Javascript code below), can someone help me fix it? Many Thanks. function gotoURL(){ var newURL = document.GotoForm.theURL.value if (newURL == "info1" || "info2" || "info3" || "info4" || "info 5"){ document.location.href=newURL+".html" }else{ alert("You entered an invalid value"); }} Hey guys. I am pretty new to JS and programming. The company that I am working for put me on this project and I have a question. Here is a snippit for a form that we have. We use a dreamweaver extension "HDW form to database" to process the forms and put them in a mysql database. the wpform() is a validation function that has been written. what I want, is the fallowing, if you look at the code below in the option object, there are different categories... rock, funk, hip hop, synth etc. i want it so when one of them is selected, it goes to a different respected page. for example, if the value Rock is selected, and you press submit, it would take you to www.google.com . On the other hand if the value Funk is submitted, it will take you to www.yahoo.com . Code: <form action="/HDWFormToDatabase/FormToDatabase.php" method="post" name="theForm" onSubmit="return wpform()" accept-charset="iso-8859-1"> <select size="1" name="genre"> <option selected="selected" value="genre">Choose a Genre!</option> <option value="Rock">Rock</option> <option value="Funk">Funk</option> <option value="Hip Hop">Hip Hop</option> <option value="80s">Synthesizer</option> <option value="Techno">Techno</option> </select> <input type="hidden" name="hdwok" id="hdwok" value=" URL GOES HERE" /> </form> Normally, when this option object is not present, the user presses submit and after the form gets processed to the database, the browser forwards to the "URL GOES HERE" value. However, I am not sure exactly what to do now since the URL which it is forwarded to will change. can someone give me a hint on how to make this happen? just some general advice for a newb? I would write it but I am pretty lost. I was thinking of including a if statement in the wpform() function that goes something like: Code: if (document.theForm.genre.selectedIndex == 0) { alert("Please select your genre."); document.theForm.genre.focus(); return (false); } if (document.theForm.genre.selectedIndex==1) { window.location = "http://www.google.com/"; return(true); } if (document.theForm.genre.selectedIndex==2) { window.location = "http://www.yahoo.com/"; return(true); } etc etc Would this work? Is there a more efficient way of doing something like this that I should know of due to my lack of JS skills? Thanks in advance so much for help. I'm stumped. I realise it's something basic... This works - i.e. beeps on mouseover: Code: <html> <head> <script> function EvalSound(soundobj) { var thissound= eval("document."+soundobj); thissound.Play(); } </script> </head> ... <a href="#" onMouseOver="EvalSound('sound1')">Move mouse here</a> ... <embed src="beep.mp3" autostart=false width=1 height=1 name="sound1" enablejavascript="true"> </body> </html> ...but this doesn't work: (I get the error "undefined is null or not an object") Code: <html> <head> <script> function EvalSound(soundobj) { var thissound= eval("document."+soundobj); thissound.Play(); } </script> </head> ... <script language="JavaScript"> <!-- EvalSound('sound1'); change_it1() // activates an external .js //--> </script> ... <embed src="beep.mp3" autostart=false width=1 height=1 name="sound1" enablejavascript="true"> </body> </html> What am I doing wrong? Gotta make the second idea work... Thanks This must be very simple. I want to execute some javascript only if an element is not displayed What is the syntax? if("#element:hidden) { do something like show it } Help much appreciated. hi all, just got to make a basic form for my assignemment but i cant seem to get it to work. please could somebody point me in the right direction? thank you Code: <head> <script type="text/javascript"> function make(myform) { var name = form.nameinput.value ; var age = form.ageinput.value ; var location = form.locationinput.value ; var z = form.team.selectedIndex ; var team = form.team.options[z].value; alert("Thank you " + name + ".Good luck supporting " + team + ); } </script> </head> <body> <form method="get" action="" name="myform"> <h2>Order form</h2> <fieldset> <p>Please enter your details</p> Name: <input type="text" value="" name="nameinput"/><br/> Age: <input type="text" value="" size="2" name="ageinput"/><br/> Location: <input type="text" value="" name="locationinput"/> <p>Choose your favourite football team</p> <select name="team"> <option value="arsenal">Arsenal</option> <option value="aston_villa">Aston Villa</option> <option value="birmingham_city">Birmingham City</option> <option value="blackburn_rovers">Blackburn Rovers</option> <option value="bolton_wanderers">Bolton Wanderers</option> <option value="burnley">Burnley</option> <option value="chelsea">Chelsea</option> <option value="everton">Everton</option> <option value="fulham">Fulham</option> <option value="hull">Hull</option> <option value="liverpool">Liverpool</option> <option value="manchester_city">Manchester City</option> <option value="manchester_united">Manchester United</option> <option value="portsmouth">Portsmouth</option> <option value="stoke_city">Stoke City</option> <option value="sunderland">Sunderland</option> <option value="tottenham_hotspur">Tottenham Hotspur</option> <option value="west_ham">West Ham</option> <option value="wigan_athletic">Wigan Athletic</option> <option value="wolverhampton_wanderers">Wolverhampton Wanderers </option> </select> </fieldset> <input type="button" onclick="make(this.form)" value="Submit Details" name="button"/> </form> Hi, im sorta a newbie but have a few questions i cannot find online anywhere. By the way im trying to create a chrome extension . Its a fairly simple extension, all i want it to do is select a few buttons automatically when the page is loaded. Without me having to click anything. A bot persay. How to automatically select a button/drop down menu How to save a form How to submit a form to a website How it works if you dont get it? Selecting a certain size like S/M/L, color, or anything of that nature AUTOMATICALLY WITHOUT HAVING TO CLICK ANYTHING. Which then adds to my cart. Thats all i want it to really do. Thanks for reading. I have a basic scroller list code, which works when I use it on a HTML page. However if I duplicate it and change the text, only one of the lists functions. I even tried to use a script from a free website online and duplicate that on the page and it still does not work twice. Could somebody help with this? |