JavaScript - Why Does This Work And This Doesnt?
Im new to javascript and trying to make a form validator, ive succeeded but its left me confussed as to setting variables.
my original code was Code: function applyform() { var name = document.getElementById('mainname'); var lvl = document.getElementById('mainlvl'); var class = document.getElementById('mainclass'); var role = document.getElementById('mainrole'); var reason = document.getElementById('reason'); var age = document.getElementById('age'); var mic = document.getElementById('microphone'); var voice = document.getElementById('voice'); if(notempty(name, "Please enter your main characters name")){ if(dropselect(lvl, "Please select your characters level")){ if(dropselect(class, "Please select your characters class")){ if(dropselect(role, "Please select your characters role")){ if(notempty(reason, "Please tell us why you wish to join us")){ if(notempty(age, "Please state your age")){ if(notempty(mic, "Please state if you have a microphone")){ if(notempty(voice, "Please state if you will use voice communication during events")){ return true; } } } } } } } } return false; } using this stoped all my javascript functions working but i cant see any fault with it. I've changed the code now to Code: function applyform() { if(notempty(document.getElementById('mainname'), "Please enter your main characters name")){ if(dropselect(document.getElementById('mainlvl'), "Please select your characters level")){ if(dropselect(document.getElementById('mainclass'), "Please select your characters class")){ if(dropselect(document.getElementById('mainrole'), "Please select your characters role")){ if(notempty(document.getElementById('reason'), "Please tell us why you wish to join us")){ if(notempty(document.getElementById('age'), "Please state your age")){ if(notempty(document.getElementById('microphone'), "Please state if you have a microphone")){ if(notempty(document.getElementById('voice'), "Please state if you will use voice communication during events")){ return true; } } } } } } } } return false; } this works fine but i don't get why my first bit of code didnt work and id really appreciate someone explaining it to me. thanks in advance Similar TutorialsCan anyone please tell me what im doing wrong? Code: <script type = "text/javascript"> function submitallforms() { setTimeout('document.forms[0].submit()',100); setTimeout('document.forms[1].submit()',200); setTimeout('document.forms[2].submit()',300); } </script> <NOSCRIPT>This shopping-cart needs JavaScript. Please enable JavaScript in your browser's preferences.</NOSCRIPT> <script> if(typeof navigator.cookieEnabled=="boolean" && !navigator.cookieEnabled) alert("You need to enable Cookies in your browser, before this shopping-cart will work for you!"); </script> <!-- <script src=noper-language-pdt.utf8.js></script> --> <script src=http://www.mlpdecals.com/cgi/nopercart.js></script> <FORM name="0" action="shoppingcart.htm" method=GET onSubmit="return AddToCart(this)"> <font class=bigtext><b>Special Instructions:</b></font><br> <input type=text size=32 maxlength=200 name=USERTEXT> <input type=hidden _PRICE="0.00" _QUANTITY="1" _NAME="special-instructions" _ID="nSPCI"> </FORM> <br><br> <FORM name="0" action="shoppingcart.htm" method=GET onSubmit="return AddToCart(this)"> <font class=bigtext><b>Special Instructions:</b></font><br> <input type=text size=32 maxlength=200 name=USERTEXT> <input type=hidden _PRICE="0.00" _QUANTITY="1" _NAME="special-instructions" _ID="nSPCI"> </FORM> <br> <br> <input type=submit value="Submit" onclick="submitallforms();"> I use a basic pop-up window code that i have used for many years. I probably need to update it, but i was wondering why it will work for every browser but IE8. Can anyone help? Code: function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=600,height=400,left = 540,top = 325');"); } Code: <a href="javascript:popUp('/email/agent/aid/<?php echo $this->agent->pers_code?>')" > can anyone see something that may cause the problem? Thanks for any help! <html> <script language="javascript"> function checkForm() { String name= document.getElementById("name"); if(name.length==0) return ; // else // return ; } </script> <body> <form action="test2.jsp" onclick =" return checkForm()"> <input type="text" name="name" value="shyam" id="name" /> <input type="submit" name="sub" value="clickme" /> </form> </body> </html> Hey guys I have a stupid problem, my teacher asked us to DONT use javadscript in html (like onchange ="....") If i use following js in html my page works: <select id="car" name="car" onchange="configurator()"> If i delete that last piece and try to code it in a .js file like: document.getElementsById("car").onchange = configurator; it doesnt work, it doest recognize the .onchange method Thanks in advance I have a problem with one simple script, which works in every browser, just not in IE6 and IE7. You can see the script at http://bbtalk.eu/iframe.html - when you click on the iframe, you should see "clicked at the bottom". But it doesnt work in IE6 and IE7. Do anyone know how to fix that? Thank you
Trying to have my navigation have an on click and selected state, but I am not able to do so with this code (website is: http://bit.ly/rgwsite ) Code: $('nav li a').click(function() { $(this).parent().addClass('on').siblings().removeClass('on'); }); nav li is as follows Code: <nav> <li class="highlt"> <a href="index.php" class="home"><span>Home</span></a> </li> The reason we need to use a jquery/javascript action to add the class to the navigation is because it doesn't refresh when a new page loads. For instance, when you're on the home page and click on the tab "Experience RGW", it only loads the content for that page below the header (within the "#ajax" div). Currently, none of these scripts are working. There is no reason they shouldn't... could there be something else causing the page not to recognize the jquery script and run it on-click? The main reason I ask is because I've tried to test the function and add an alert, but even that didn't work function hasTagsInText(text) { if(text.indexOf("<TABLE") >=0 || text.indexOf("<table") >=0) return 'table'; ///this line of code doesnt work in firefox Hi All, Im trying to add some content by JS (which ive done) but i cant click a link i have made; JS: Code: function game() { document.getElementById('title').innerHTML = '<p style="float: left; text-decoration: underline; font-weight: bold;">Deady Teddy</p><img src=css/images/popup/close.png style="float: right; cursor: hand;" href="javascript: hideModal("modalPage");"></img>'; } *Yes i know about the Href but if i put "onClick" it gives errors*; HTML: Code: <a href="javascript:void(0);" onClick="javascript: revealModal('modalPage'); game();">Deady Teddy </a> And place its adding it to: Code: <div id="modalPage"> <div class="modalBackground"></div> <div class="modalContainer"> <div class="modal"> <div class="modalTop" id="title" onselectstart='return false'> </div></div></div></div> Any Idea's? this is my code ______________________________________________________________ <pega:when test="$mode-input"> <script language="JavaScript"> function showNextButton() { handleClientEvent('SERVER','MakeScoreOrder','','-1'); /* fetches the data */ var submitClicked = "<p:r n='pyWorkPage.PFRSData.SubmitClicked' />"; var submitClicked = submitClicked.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); var msg = "<p:r n='pyWorkPage.PFRSData.HasMessages' />"; var msg = msg.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); if (submitClicked == "" || msg =="true") { toggleSubmitBtn(0); } else if (submitClicked == "true" || msg =="false") { toggleSubmitBtn(1); } } function toggleSubmitBtn(status) { var submitButton=document.actionForm.submitButton; if(submitButton) { var parentTable=pega.u.d.findParentTable(submitButton); if(parentTable) if(status) { if(parentTable.style.display=='none' || parentTable.style.display=='') { parentTable.style.display='inline'; document.actionForm.submitButton.disabled=false; } } else { parentTable.style.display='none'; document.actionForm.submitButton.disabled=true; } } } </script> <button onClick="showNextButton();" id="PISSubmit" style="vertical-align:middle;"> <span class='buttonLeft'></span> <span class='buttonMiddle'> <span class='buttonText' onmouseover="this.className='buttonTextHover'" onmouseout="this.className='buttonText'">Submit</span> </span> <span class='buttonRight'></span> </button> </pega:when> ___________________________________________________________ On clicking PISsubmit button it should fetch data and display the next button(submitButton).. but on first click nothing happens on second click it fetches the data and third click it displays Next(submitButton)button. Kindly help !! Note: its in pega application. Hello here is my code that im dealing with and only second sliceshow works for me i need them both that would be working together please help me! thanks for any help here is my script <head> <title>Easy Slider jQuery Plugin Demo</title> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/easySlider1.7.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#slider").easySlider({ auto: true, continuous: true, nextId: "slider1next", prevId: "slider1prev" }); }); </script> <link href="css/screen.css" rel="stylesheet" type="text/css" media="screen" /> <link rel="stylesheet" type="text/css" href="leidyba/css/demo.css" /> <link rel="stylesheet" type="text/css" href="leidyba/css/styleleidyba.css" /> <link rel="stylesheet" type="text/css" href="leidyba/css/jquery.jscrollpane.css" media="all" /> <link href='http://fonts.googleapis.com/css?family=PT+Sans+Narrow&v1' rel='stylesheet' type='text/css' /> <link href='http://fonts.googleapis.com/css?family=Coustard:900' rel='stylesheet' type='text/css' /> <link href='http://fonts.googleapis.com/css?family=Rochester' rel='stylesheet' type='text/css' /> <div id="container"> <div id="header"> <h1>Easy Slider jQuery Plugin - Multiple sliders</h1> </div> <div id="content"> <div id="slider"> <ul> <li><a href="http://templatica.com/preview/30"><img src="slide/images/01.jpg" alt="Css Template Preview" /></a></li> <li><a href="http://templatica.com/preview/7"><img src="slide/images/02.jpg" alt="Css Template Preview" /></a></li> <li><a href="http://templatica.com/preview/25"><img src="slide/images/03.jpg" alt="Css Template Preview" /></a></li> </ul> </div> <div class="container"> <div id="ca-container" class="ca-container"> <div class="ca-wrapper"> <div class="ca-item ca-item-1"> <div class="ca-item-main"> <div class="ca-icon"></div> <h3>Knygų leidyba</h3> <h4> <span class="ca-quote">“</span> <span>The greatness of a nation and its moral progress can be judged by the way in which its animals are treated.</span> </h4> <a href="#" class="ca-more">plačiau...</a> </div> <div class="ca-content-wrapper"> <div class="ca-content"> <h6>Knygų leidyba</h6> <a href="#" class="ca-close">close</a> <div class="ca-content-text"> <p>I am so happy, my </p> <p>When, while the </p> <p>She packed her .</p> </div> <ul> <li><a href="#">Read more</a></li> <li><a href="#">Share this</a></li> <li><a href="#">Become a member</a></li> <li><a href="#">Donate</a></li> </ul> </div> </div> </div> <div class="ca-item ca-item-2"> <div class="ca-item-main"> <div class="ca-icon"></div> <h3>Reklaminiai bukletai</h3> <h4> <span class="ca-quote">“</span> <span>I hold that the more </span> </h4> <a href="#" class="ca-more">plačiau...</a> </div> <div class="ca-content-wrapper"> <div class="ca-content"> <h6>Would you eat your dog?</h6> <a href="#" class="ca-close">close</a> <div class="ca-content-text"> <p>I am so happy, my .</p> <p>When, while the </p> <p>She packed her </p> </div> <ul> <li><a href="#">Read more</a></li> <li><a href="#">Share this</a></li> <li><a href="#">Become a member</a></li> <li><a href="#">Donate</a></li> </ul> </div> </div> </div> </div> </div> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script type="text/javascript" src="leidyba/js/jquery.easing.1.3.js"></script> <!-- the jScrollPane script --> <script type="text/javascript" src="leidyba/js/jquery.mousewheel.js"></script> <script type="text/javascript" src="leidyba/js/jquery.contentcarousel.js"></script> <script type="text/javascript"> $('#ca-container').contentcarousel({ }); </script> </div> </body> </html> when i run applet nothing shows jsut text field [highlight=Java] import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Assign6 extends JApplet implements ActionListener { JLabel answerLabel; JTextField answerField; public void init() { Container c = getContentPane(); c.setLayout (new FlowLayout()); answerLabel = new JLabel(""); answerField = new JTextField(10); answerField.setEditable(true); answerField.addActionListener(this); c.add(answerLabel); c.add(answerField); } public int generateNumbers() { int x=0; x = 1 + (int)(Math.random() * 10); return x; } public void actionPerformed(ActionEvent e) { String correct = new String("Correct "); int x = generateNumbers(); int y = generateNumbers(); showStatus("How much is " + x + " times " + y); int answer; answer = Integer.parseInt(answerField.getText()); int product = x*y; if (product == answer){ showStatus("Very good!"); } else showStatus("No. Please try again."); } @Override public void paint(Graphics g) { super.paint(g); } } { } [/highlight] Hello Guys, im writing a big page with several different elements in it, and im stuck trying to duplicate a script. first one works "tab b" click each 'icon' and a .png file appears above it to show its selected. "tab c" same script and code seems to only work for first icon, and switch off when clicked on the others. been staring at this for sooooome time now, please can someone see what i have done wrong, as i dont really understand the code im using, im just a beginner. url is http://www.zakscustomcues.com/module...builder2.0.php much appreciated. steve Hey Everyone, Thanks for reading my thread, I really hope I'm not asking a dumb question as I am teaching myself java but here goes. I'm a bit stuck and want my code to output a message when a form input does not contain a word (like lets say codingforums.com). I know it outputs my message when the field is left blank but here's what I have, any help will be greatly appreciated Thanks. Code: function checkPostFields(form) { var msg = ''; var value_missing = false; if (form.elements['test'].value == '' ) { msg += '<?php echo $errormessage; ?>\n'; value_missing = true; } } This script is supposed to tally the score of the questions. It shows up fine but it does not tally the score <p>You are on a business journey beyond traditional small business style <input type="checkbox" value="1" name="Q1">yes <input type="checkbox" value="0" name="Q1">no</p> <p>You don t want to be the glue holding everyday operations together <input type="checkbox" value="1" name="Q1">yes <input type="checkbox" value="0" name="Q1">no</p> <p>You are comfortable with using simple business technology tools and the web <input type="checkbox" value="1" name="Q1">yes <input type="checkbox" value="0" name="Q1">no</p> <p>You believe in business operations based upon processes <input type="checkbox" value="1" name="Q1">yes <input type="checkbox" value="0" name="Q1">no</p> <p>You earn operating success by having a good working team <input type="checkbox" value="1" name="Q1">yes <input type="checkbox" value="0" name="Q1">no</p> <p>One of your high priorities is designing and evolving your business progressively <input type="checkbox" value="1" name="Q1">yes <input type="checkbox" value="0" name="Q1">no</p> <p>Your company culture embraces adopting the best approaches <input type="checkbox" value="1" name="Q1">yes <input type="checkbox" value="0" name="Q1">no</p> <p>You have defined processes, roles, and responsibilities <input type="checkbox" value="1" name="Q1">yes <input type="checkbox" value="0" name="Q1">no</p> <p>Your staff is literate in using a computer for your basic on the job tasks <input type="checkbox" value="1" name="Q1">yes <input type="checkbox" value="0" name="Q1">no</p> <p>You are ready to begin implementing more systematic operations <input type="checkbox" value="1" name="Q1">yes <input type="checkbox" value="0" name="Q1">no</p> <p>You want to expand, grow, or diversify more efficiently <input type="checkbox" value="1" name="Q2">yes <input type="checkbox" value="0" name="Q2">no</p> <p>You effectively communicate the reasons and value of your changes <input type="checkbox" value="1" name="Q3">yes <input type="checkbox" value="0" name="Q3">no</p> <p>You want to adopt changes to smooth out basic team processes <input type="checkbox" value="1" name="Q3">yes <input type="checkbox" value="0" name="Q3">no</p> <p>Your key people will support, advocate, and lead in changes for you <input type="checkbox" value="1" name="Q3">yes <input type="checkbox" value="0" name="Q3">no</p> <p>You view change as a prime mover in your business journey <input type="checkbox" value="1" name="Q3">yes <input type="checkbox" value="0" name="Q3">no</p> <p><input type="text" name="tally" size="5"></p> <p><input type="button" value="tally" name="B1"></p> Hey i am using a dropdown list to change an image but i doesnt work Javascript: Code: addEventListener("load", configurator, false); function configurator() { var model = document.getElementById("Model").value var afbeelding = document.getElementById("modelafbeelding") switch (model) { case "Audi A1": var foto = "./images/audia1.png" afbeelding.innerHTML = ("<img class='sizedgarage' src='" + foto + "'>"); break; case "Audi A3": var foto = "./images/audia3.png" afbeelding.innerHTML = ("<img class='sizedgarage' src='" + foto + "'>"); break; case "Audi A4": var foto = "./images/audia4.png" afbeelding.innerHTML = ("<img class='sizedgarage' src='" + foto + "'>"); break; case "Audi A5": var foto = "./images/audia5.png" afbeelding.innerHTML = ("<img class='sizedgarage' src='" + foto + "'>"); break; case "Audi A6": var foto = "./images/audia6.png" afbeelding.innerHTML = ("<img class='sizedgarage' src='" + foto + "'>"); break; case "Audi R8": var foto = "./images/audir8.png" afbeelding.innerHTML = ("<img class='sizedgarage' src='" + foto + "'>"); break; } } HTML: Code: <tr> <td><select id="Model" name="Model"> <option>Audi A1</option> <option>Audi A3</option> <option>Audi A4</option> <option>Audi A5</option> <option>Audi A6</option> <option>Audi R8</option> </select></td> <div id="modelafbeelding"></div> </tr> when I upload a new javascript file to the server and refresh the webpage, the webpage behaves as if the old script is on the server, this happens with IE and firefox, even if I shut the programs down and restart them, can anyone help? Hello all, I made a fade script that will fade any element in or out. Works great on all browser I've tested but IE 7. With IE I have only tested this will IE 8 and IE 7. IE 7 the effect doesn't work. No error message or anything. I'm unsure what to do from here. I was hoping I could find some help here. Code: function fade(obj, duration, toggle) { steps = 1000; elem = document.getElementById(obj); function fadeIn() { for(var i = 0; i <= 1; i+=(1/steps)) { setTimeout("elem.style.opacity = "+ i +"", i * duration); setTimeout("elem.style.filter='alpha(opacity="+ i * 102 +")'", i * duration); } } function fadeOut() { for(var i = 0; i <= 1; i+=(1/steps)) { setTimeout("elem.style.opacity = "+ (1-i) +"", i * duration); setTimeout("elem.style.filter='alpha(opacity="+ (1-i) * 102 +")'", i * duration); } } /* One for Fade in and anything will be fade out*/ if(toggle == 1) { fadeIn(); } else { fadeOut(); } } Thanks, Jon W Hello again, I have written the following code: <script language="Javascript"> var win=0 </script> <Form name="Form"> <Input type="button" name="button" value="Click" onClick="Good()"> </form> <script language="Javascript"> function Good() { if (win=0) { alert('You win!') } else { alert("You lose!") } } </script> Based on the following, when I click the button it should say "You win!" as win=0 but it keeps saying "You lose!". Why is this happening? So here is the story I paid for some to create a slideshow, and it works fine in the orginial html document but when i copy and paste the code into my html document the scroller to the left of the image stops moving up and down I put the working file at this address: http://rusty813.comuv.com/ my files at this address where i am: http://rusty813.comuv.com/sample2.html the guy i paid to do work refuses to help even those i advertised the price in my ad and he wanted me to give it to pay him more to tell which code to change but go ahead take a look at the coding thanks alot for your guys help hello, I found this script : http://roshanbh.com.np/2008/06/accor...ng-jquery.html I implemted this into my website http://test.tamarawobben.nl but as you can see it don't work. Can anyone help me figure out why the script does not work. Roelof |