JavaScript - Need Help Debugging A Probably Only Small Error...
first of all, hello all
i found this forum while running out of ideas and being extremely desperate to fixing a probably small javascript error in a script. the script is supposed to open a small form window that allows the user to input an email address and update it to proceed. the form item is initially unchecked, but as the user clicks it and enter his email address, it updates the value of the email address and the box becomes "checkable". the problem is that with both IE and firefox, the box doesn't close again, doesn't get checkable and basically doesn't work. in the firefox debugging console, I found the following error: Quote: Error: document.getElementById(input_array[i]) is null Source File: sell_item.php Line: 1106 does anyone have an idea what could be wrong? the part responsible in the javascript for this section is: Code: <script language="javascript"> function pg_popup_open(id) { if (document.getElementById(id).style.display == 'block') { document.getElementById(id).style.display = 'none'; } else { document.getElementById(id).style.display = 'block'; } return false; } function pg_update_settings(id, input_array) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url = '' + 'ajax_files/direct_payment_box.php'; var action = url + '?id=' + id + '&user_id=' + 100001; var chk_disabled = false; for ( var i in input_array ) { action += '&' + input_array[i] + '=' + document.getElementById(input_array[i]).value; if (document.getElementById(input_array[i]).value == '') { chk_disabled = true; } } xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4) { var response = xmlHttp.responseText; } }; xmlHttp.open("GET", action, true); xmlHttp.send(null); document.getElementById('checkbox_' + id).disabled = chk_disabled; if (chk_disabled == true) { document.getElementById('checkbox_' + id).checked = false; } document.getElementById(id).style.display = 'none'; return false; } </script> and the html code that is supposed to pop up the box is: Code: <input type="checkbox" name="payment_gateway[]" id="checkbox_pg_paypal" value="1" disabled> <span class="contentfont"><a href="javascript:;" onclick="pg_popup_open('pg_paypal');">PayPal</a></span> <script language="javascript"> var array_pg_paypal = new Array(); array_pg_paypal[0] = 'pg_paypal_email';</script> <div class="smallfont"><b>PayPal Email Address</b><br> <input type="text" name="pg_paypal_email" id="pg_paypal_email" value="" /></div> <div align="right"><input type="button" value="Proceed" onclick="pg_update_settings('pg_paypal', array_pg_paypal);" /></div> i understand this is asking a lot, but if someone has a spare second that is a javascript guru, i promise i will name my first born after you!! lol Similar TutorialsHi everybody. I've been trying to figure out how to fix the following error I get in the latest Internet Explorer for marinebio.org: Message: 'this.submenus[...].getElementsByTagName(...).0' is null or not an object Line: 547 Char: 3 Code: 0 URI: http://marinebio.org/_n/s/main.js The code at line 547 in main.js is: Code: this.submenus[i].getElementsByTagName("span")[0].onclick = function() { in the function: Code: SDMenu.prototype.init = function() { var mainInstance = this; for (var i = 0; i < this.submenus.length; i++) this.submenus[i].getElementsByTagName("span")[0].onclick = function() { mainInstance.toggleMenu(this.parentNode); }; if (this.markCurrent) { var links = this.menu.getElementsByTagName("a"); for (var i = 0; i < links.length; i++) if (links[i].href == document.location.href) { links[i].className = "current"; break; } } if (this.remember) { var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)"); var match = regex.exec(document.cookie); if (match) { var states = match[1].split(""); for (var i = 0; i < states.length; i++) this.submenus[i].className = (states[i] == 0 ? "collapsed" : ""); } } }; I've been using the Dynamic Drive's Slashdot sliding menu script for at least a year without any problems. All pages validated before the ads were added. I've pulled nearly all other scripts but it still errors out. Works fine in FF and Chrome. Going to strip the home page to nothing and start building it back but if anyone has any ideas, I'd really appreciate it. Maybe it's time to upgrade the vertical sliding menu script entirely, if anyone can recommend a better one, that would be great too. I know just enough javascript to be dangerous apparently.... Hello, I'm a student web developer. I'm debugging some JavaScript code I just created that simply extracts a table, reorders it and replaces it when the user clicks on a button ('Order results' - top right of the table). (It's a small script). It's for a PHP based polling application, completely of my own creation, which is under construction (only the JavaScript doesn't work). You can see all the code if you use Firebug. Go to the following link and vote for something; that will take you to a page the JavaScript is located. http://www.samuellockyer-development...s/examples.php (I'm linking because I think the context of the page may help.) (Notice the type error alert.) (Update: Not anymore.) (There are NO syntax errors.) You will find the area of the bug quickly by looking at the comments. (Marked by !!BUG!!) (Update: Not anymore, look at the posts below to find them now.) I am very new to JavaScript, but I wrote all the code, so I will be able to answer questions easily. This is a last resort by the way, I need this to work within about two days and I would be SO grateful for any help!! You can vote as many times as you like - I can just zero everything before I demo the app. I've been working on that for days, and can't find the problem. Could one of you help? I wrote a low-level digit-shift cipher, but the script doesn't work. Code: <head> <script type="text/javascript"> function ciphertext() { var t = document.getElementById.('t') t = t.toUpperCase() var n = 0 var o = "" if(n=0) { o=o+t n=n+1 } if(n=1) { if(t=="A") o=o+"B" if(t=="B") o=o+"C" if(t=="C") o=o+"D" if(t=="D") o=o+"E" if(t=="F") o=o+"G" if(t=="G") o=o+"H" if(t=="H") o=o+"I" if(t=="I") o=o+"J" if(t=="J") o=o+"K" if(t=="K") o=o+"L" if(t=="L") o=o+"M" if(t=="M") o=o+"N" if(t=="N") o=o+"O" if(t=="O") o=o+"P" if(t=="P") o=o+"Q" if(t=="Q") o=o+"R" if(t=="R") o=o+"S" if(t=="S") o=o+"T" if(t=="T") o=o+"U" if(t=="U") o=o+"V" if(t=="V") o=o+"W" if(t=="W") o=o+"X" if(t=="X") o=o+"Y" if(t=="Y") o=o+"Z" if(t=="Z") o=o+"A" else o=o+t n=n-1 } document.getElementById('op').innerHTML = o.value } </script> </head> <body> <b id="op">This is your result</b> <input type="text" id='t' /> <button onclick="ciphertext()">Submit</button> </body> I've been working on that for days, and can't find the problem. Could one of you help? (Pardon me if I am being blunt, but why doesn't this work?) I've been messing with this for hours and I can't seem to find where I've gone wrong with it, I think I need a fresh pair of eyes to give it a look over. Anyways here's my entire piece of code. I know it's a lot to look at but if anyone can help me get this working that would be great, it's starting to give me a headache just to look at it. Anyways from what I can tell the problem is somewhere in the wDesQuote() function but I can't seem to pin it down. Code: //Start Ajax Code var XMLHttpRequestObject = false; if (window.XMLHttpRequest) { XMLHttpRequestObject = new XMLHttpRequest(); } else if (window.ActiveXObject) { XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP"); } function getData(dataSource, divID){ if(XMLHttpRequestObject){ var obj = document.getElementById(divID); XMLHttpRequestObject.open("GET", dataSource); XMLHttpRequestObject.onreadystatechange = function(){ if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200){ obj.innerHTML = XMLHttpRequestObject.responseText; } } XMLHttpRequestObject.send(null); } } //End Ajax Code //Start Div Updater function textUpdate(text, divID){ if(XMLHttpRequestObject){ var obj = document.getElementById(divID); obj.innerHTML = text; XMLHttpRequestObject.send(null); } } //End Div Updater //Money Formater function roundNumber(num, dec) { var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec); return result; } //End Money Formater function wDesQuote() { var eBizCard = document.getElementById('eBizCard').checked; var basic = document.getElementById('basic').checked; var mobile = document.getElementById('mobile').checked; var pages = document.getElementById('pages').value * 20; var host = document.getElementById('hostY').checked; var cTemp = document.getElementById('cTemp').checked; var anime = document.getElementById('anime').checked; var addMobile = document.getElementById('addMobile').checked; var eComP = document.getElementById('eComP').checked; var eComI = document.getElementById('eComI').value; var eComQ = 0; var forum = document.getElementById('forum').checked; var blog = document.getElementById('blog').checked; var wUpd = document.getElementById('wUpd').checked; var bUpd = document.getElementById('bUpd').checked; var mUpd = document.getElementById('mUpd').checked; var nUpd = document.getElementById('nUpd').checked; var logo = document.getElementById('logo').checked; var bCard = document.getElementById('bCard').checked; var pCard = document.getElementById('pCard').checked; var brochure = document.getElementById('brochure').checked; var mTotal = 0; var uTotal = 0; if(eBizCard == true && host == true){ uTotal = 149.95; mTotal = 9.95; }else if(eBizCard == true && host == false){ uTotal = 149.95; mTotal = 0; }else if(mobile == true && host == true){ uTotal = 299.95; mTotal = 9.95; }else if(mobile == true && host == false){ uTotal = 299.95; mTotal = 0; }else{ eBizCard = 0; mobile = 0; basic = 499.95; if(host == true){ host = 9.95; } else{ host = 0; } if(cTemp == true){ cTemp = 100; }else{ cTemp = 0; } if(anime == true){ anime = 150; }else{ anime = 0; } if(addMobile == true){ addMobile = 275; }else{ addMobile = 0; } if(eComP == true){ eComP = 200; eComQ = roundNumber(eComI * 0.59,2).toFixed(2); if(eComQ == "NaN"){ alert("Please enter numbers only into the item quantity box"); break; } }else{ eComP = 0; eComI = 0; } if(forum == true){ forum = 50; }else{ forum = 0; } if(blog == true){ blog = 50; }else{ blog = 0; } if(wUpd == true){ wUpd = 175; }else{ wUpd = 0; } if(bUpd == true){ bUpd = 100; }else{ bUpd = 0; } if(mUpd == true){ mUpd = 60; }else{ mUpd = 0; } if(nUpd == true){ nUpd = 0; }else{ nUpd = 0; } if(logo == true){ logo = 75; }else{ logo = 0; } if(bCard == true){ bCard = 90; }else{ bCard = 0; } if(pCard == true){ pCard = 140; }else{ pCard = 0; } if(brochure == true){ brochure = 280; }else{ brochure = 0; } } var uTotal = pages + cTemp + anime + addMobile + eComP + eCompQ + forum + blog + wUpd + bUpd + mUpd + nUpd + logo + bCard + pCard + brochure; var mTotal = host + mUpd + bUpd + wUpd + nUpd; if(mTotal == 0){ document.getElementById('totalDisplay').innerHTML = "Your total is $" + uTotal; }else{ document.getElementById('totalDisplay').innerHTML = "Your total is $" + uTotal + " a monthly fee of $" + mTotal; } } I'm used to PHP, where I can use var_dump to find out about a variable wherever I call it. Or, having the script crash entirely and give me an idea of what mistake I made, when I made a mistake. With JS, neither of those appear to be true. I was told I can use console.log or console.dir to get something similar to var_dump, but as you can see: it's giving me no output. I need a way to help me find the mistakes I make. How can I get console.dir to work? See the image below: Large image: http://i.imgur.com/4cw89OO.png what is wrong with this Code: function addfavorites(classid,userid) { // alert("here"); var urltoajax = "addfavorites.php?j=1&classid="+ classid + "&userid="+ userid; urltoajax = urltoajax + '&rnd=' + Math.round(Math.random() * 10000) alert(urltoajax); $.ajax({ url: urltoajax, cache: false, success: function(html) { $("#message").html(html); } }); //alert('here 2'); } i get an error Object doesn't support this property or method This question hovers between PHP and JavaScript, but I think it fits here a little better. I've got a web app that does a lot of asynchronous calls to various PHP pages. I'm familiar with using an iFrame or div to hold a controller, then making forms post to that controller so you can see the output. However, I'm not doing a lot of submitting forms. Typically, I utilize the onclick event of various elements to initiate an XmlHttpRequest that jumps over to a PHP page and back. I'm looking for a way to easily debug my PHP code. Right now I'm using Firebug (on Firefox) to look at the HTTP requests. I can see the post data and response and all that, which is good. However, it requires a good amount of clicking and time to get to that data. Is there an easier way to do this? Ideally I'd love to include some sort of debug window that displays all of the PHP controller errors and things that I echo out. In short, what's wrong with this? I'm sure you'll test it, but it just posts the JS inside the Bold tag instead of the grade. This includes the innerHTML script. Code: <html> <head> <script type="text/javascript"> function grade() { var tot = 1; var g = 0; var qId0 = document.getElementById('0').value; if (qId0 == "t") { g = g + 1; } g = g / tot; g = g * 100; document.getElementById("grade").innerHTML = grade; } </script> </head> <body> <b id="grade">Your Grade Here</b> <ol> <li><select id="0"> <option value="d">Test Question</option> <option value="f">false</option> <option value="t">true</option> <option value="f">false</option> </select> <button onclick="grade()">Submit</button> </body> </html> When I hit "submit" with the right answer, I get: function grade() { var tot = 1; var g = 0; var qId0 = document.getElementById('0').value; if (qId0 == "t") { g = g + 1; } g = g / tot; g = g * 100; document.getElementById("grade").innerHTML = grade; } When I hit "submit" with the wrong answer, I get the same. Can someone explain this to me and tell me how to fix it? (Also, I would appreciate it if you could point out any unrelated bugs you come across ) I am trying to debug this with FireBug Code: function chapter12_nodeOne() { //create an element var element = document.createElement('input'); //set some attributes element.setAttribute('type', 'button'); element.setAttribute('value', 'submit'); //appendd the element into a DIV document.getElementById('myDiv').appendChild(element); //uses EventUtil to attach an event listener (1) EventUtil.addHandler(element, 'click', function() { alert('added event handler') }); } var EventUtil = { (2)addHandler: function(element, type, handler) { //check if the element and the browser support DOM Level 2 event attachment //if the user is not browsing with IE if (element.addEventListener) { element.addEventListener(type, handler, false); } //if user is browsing with IE else if (element.attachEvent) { element.attachEvent("on" + type, handler); } //if user is using a browser that only supports DOM Level 0 event attachment else { element["on" + type] = handler; } }, removeHandler: function(element, type, handler) { //check if the element and the browser support DOM Level 2 event attachment //if the user is not browsing with IE if (element.removeEventListener) { element.removeEventListener(type, handler, false); } //if user is browsing with IE else if (element.detachEvent) { element.detachEvent("on" + type, handler); } //if user is using a browser that only supports DOM Level 0 event attachment else { element["on" + type] = null; } }, preventDefault: function(event) { if(event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; } } }; I put a breakpoint on the line marked with (1), I am trying to go to line (2) with all the available options FireBug gives, but unfortunately I get the end of chapter12_nodeOne function. Any ideas why? This page should work, but it doesn't. My debugging says that I have a invalid character on line 2 and on line 39 it is "object expected". Here's the page: <HTML> <HEAD> <TITLE>The Golf Page</TITLE> <STYLE> BODY {font-family:Arial, Helvetica, sans-serif; font-size: 18pt; color:blue; background-color:rgb(255,255,128)} </STYLE> <SCRIPT SRC="Ball.gif"> var x = new Array(-395, -389, -383, -377, -371, -365, -359, -353, -346, -340, -334, -328, -322, -316, -310, -304, -297, -291, -285, -279, -273, -267, -261, -255, -248, -242, -236, -230, -224, -218, -212, -206, -199, -193, -187, -181, -175, -169, -163, -157, -150, -144, -138, -132, -126, -120, -114, -108, -101, -95, -93, -91, -88, -86, -83, -81, -78, -76, -73, -71, -69, -66, -64, -61, -59, -56, -54, -51, -49, -47, -44, -42, -39, -37, -34, -32, -29, -27, -24, -22, -20, -17, -15, -12, -10, -7, -5, -2, 0); var y = new Array(-300, -300, -300, -299, -298, -297, -296, -294, -292, -290, -288, -285, -282, -279, -276, -272, -268, -264, -260, -255, -250, -245, -240, -234, -228, -222, -216, -209, -202, -195, -188, -180, -172, -164, -156, -147, -138, -129, -120, -110, -100, -90, -80, -69, -58, -47, -36, -24, -12, 0, -5, -10, -14, -18, -22, -25, -29, -32, -34, -37, -39, -41, -43, -45, -46, -47, -48, -48, -48, -48, -48, -48, -47, -46, -45, -43, -42, -40, -37, -35, -32, -29, -26, -23, -19, -15, -11, -6, 0); index=0 function moveBall() { if(index <=[x.length-1]) { placeIt("Ball", x[index], y[index]); index++; setTimeout("moveBall()", 5); } else { ("showIt()", 5); setTimeout("showIt('Slogan')", 5); setTimeout("showIt('Slogan1')", 10); setTimeout("showIT('Marquee')", 15); } } </SCRIPT> </HEAD> <BODY onLoad="moveBall(Ball);"> <DIV ID="Marquee" visibility:hidden font-family: Time New Roman, Times, serif; font-style:italic> <CENTER> <MARQUEE BGCOLOR="#BBBBBB"> A beautiful day for GOLF...Sunny...No WINDS...TEMP:68-70 </MARQUEE> </CENTER> </DIV> <SCRIPT SRC="Golf.js"></SCRIPT> <DIV ID="Title" STYLE="border-left:1px solid blue; border-right:3px solid blue; border-top:1px solid blue; border-bottom:3px solid blue; padding-left:395;padding-top:260;padding-bottom:0; background-color:rgb(0,255,0)"> THE G<SPAN ID="Ball" position:relative; left:0; top:0><IMG SRC="Ball.gif" BORDER=0 width="17" height="17"></SPAN>LF PAGE </DIV> <DIV ID="Slogan" STYLE="color:black; font-family: Times New Roman, Times, serif; font-style:italic; font-weight:bold; position:absolute; left:120; top:100; z-index:2; visibility:hidden"> Your Online Source of Golf Equipment </DIV> <DIV ID="Slogan2" STYLE="color:white; font-family: Times New Roman, Times, serif; font-style:italic; font-weight:bold; position:absolute; left:121; top:101; z-index:1; visibility:hidden"> Your Online Source of Golf Equipment </DIV> </BODY> </HTML> The function moveBall and its contents should be checked as well, although it should be correct. But the page won't load properly. The marquee is suposed to be hidden until the function executes, and it is displayed. As far as I know the only errors are in the onLoad and function, everything else is right. Any help would be appreciated. Thanks I've been playing around with a madlibs exercise while trying to learn simple javascript. I have three input boxes and a button display an alert containing the input from the boxes. Am I right to be assigning variable names to the values from the text boxes and then referencing those variables in my alert? I'm sorry if this is a dumb question but I've been working on it for hours and can't get past this point. Inset a name: <input type="text" id="textbox1" size="10"/> </br> Insert a verb : <input type="text" id="textbox2" size="10"/> </br> Insert a place: <input type="text id="textbox3" size="10"/> <input type="button" value="CLICK WHEN FINISHED" onClick="name = document.getElementById('textbox1').value; verb = document.getElementById('textbox2').value; place = document.getElementById('textbox3').value; alert('Mad Lib :' + name + " " + verb + " " + place);" /> Hello all i've made Contact me form with JS validation , my qs is : i do not want the alert pop up small window a post text the alert in DIV i have read it's innerHTML here the JavaScript Code: function isEmpty( inputStr ) { if ( null == inputStr || "" == inputStr ) { return true; } return false; } // Vadate name function checkname (strng){ var error=""; if (strng == ""){ error = "Please Enter your name." } return error; } //Vadate last name function checkprename (strng){ var error=""; if (strng == ""){ error = " Please Enter your name" } return error; } function checkPhone (strng) { var error = ""; if (strng == "") { error = "Vous n'avez pas inscrit un numero de telephone.\n"; } var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters if (isNaN(parseInt(stripped))) { error = "vous entrez le numero de telephone errone."; } if (!(stripped.length == 10)) { error = "vous entrez le numero de telephone errone.\n"; } return error; } //Validate Email function checkEmail (strng) { var error=""; if (strng == "") { error = "Vous n'avez pas entre une adresse email.\n"; } var emailFilter=/^.+@.+\..{2,3}$/; if (!(emailFilter.test(strng))) { error = "S'il vous plait entrer une adresse email valide.\n"; } else { //test email for illegal characters var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ if (strng.match(illegalChars)) { error = "L'adresse email contient des caracteres illegaux.\n"; } } return error; } Now here in html Code: function checkWholeForm(theForm) { var why = ""; why += checkname(theForm.name.value); why += checkprename(theForm.prename.value); why += checkEmail(theForm.Email.value); why += checkPhone(theForm.Phone.value); if (why != "") { var leDiv = document.getElementById('errormsg'); var nouveauDiv = document.createElement('div'); var divIdName = 'errormsg'; nouveauDiv.setAttribute('id',divIdName); nouveauDiv.innerHTML = "u had Enter wrong information bla bla"; leDiv.appendChild(nouveauDiv); var nouveauDiv2 = document.createElement('div'); var divIdName = 'errormsg'; nouveauDiv2.setAttribute('id',divIdName); nouveauDiv2.innerHTML = ' '; leDiv.appendChild(nouveauDiv2); return false; } return true; } MY qs is how to let the innerHTML past past each error from the validate.js file which i call it erorr i mean near to input filed of phone it will be div id erorrmsg and in this div will past the error from the validate.js which it code from my start of this post thanks for advance Hi all, I got a small problem. Please help me. Below is the code for toggle text. My problem is Whenever I click Toggle div 1 a Contents of div1 opens. I want a code to hide Contents of div1 when I click Toggle div 2(Shows only Contents of div2) or Toggle div 3 (Shows only Contents of div3) and vice versa. Code: <div align="left" id='div1' style='display:none'>Contents of div1</div> <div align="left" id='div2' style='display:none'>Contents of div2</div> <div align="left" id='div3' style='display:none'>Contents of div3</div> <button onclick="toggle(1)">Toggle div 1</button> <button onclick="toggle(2)">Toggle div 2</button> <button onclick="toggle(3)">Toggle div 3</button> <script> function toggle(x){ var divx = document.getElementById('div'+x) if (divx.style.display == 'none') { divx.style.display = 'block' } else { divx.style.display = 'none' } } </script> Hey all, I have this code on my site that simply says if we are open or not. Code: <script language="Javascript"> <!-- /* Credit must stay intact Visit java-scripts.net or http://wsabstract.com for this script */ now = new Date if (now.getHours() <21) { document.write("We are Currently : Open") } else if (now.getHours() <9) {* * document.write("We are currently : Closed")} else { * *document.write("We are currently : Closed")} //--> </script> I wish to know how I can change this code so that I can add some colour and change the size of the font. Any help would be great. Hello. I have created a button so that when a person click it, it should turn the text into Bold font weight - Fortunately it works, However i tried adding an alternative which is when the text is already turned into Bold font weight the person could click the button in order to switch the text into normal mode, simply cancel the Bold - Unfortunately it doesn't work at all - Can Some one review my little script and help me solve it out ? PHP Code: <script type="text/javascript"> function bold(id) { if (document.getElementById) { document.getElementById(id).style.fontWeight = 'bold'; } else if (document.all) { document.all[id].style.fontWeight = 'bold'; } } //@@@@@@@@@@@(Now the rest of the code down bellow is what i have added so that i could click an cancel the bold mode or (document.all) { document.all[id].style.fontWeight = 'normal'; } </script> and that's the image code : PHP Code: <img src="Bold.bmp"width="42" height="39" title="Bold Font" onclick="bold('bodytext')" style="cursor:pointer;" /> I have a piece of code that pulls reviews and allows a business owner to drop the reviews on to their website. I need to limit the number of reviews and ideally I'd like to do that with just the snippet the biz owner drops into their site. Is this possible? Here's a sample of the code: <div id="repagent_reviews"></div><script type="text/javascript" src="http://awebsite.com/anotherwebsite/wp-admin/admin-ajax.php?action=repagent_reviews_js&id=1182"></script> thanks! confused Hi all, I found a small fading script online which suits my needs though I need some help changing it around a bit as it seems to only work once in a page (i.e. a second occurance of the code doesn't work though the first one continues). Also, I'm not quite sure how to put it into a .js external page and then call the specific function as many times as I want in the body and have it all work. Please advise on this issue (i.e. Putting the code in an external file and then calling the fadeIn() function as many times as I want in the body). Thanks. BTW, the concept is a fixed imaged with the js fading another image over the top of that first image in and out over and over again. All the images and application of the js will be the same for all occurrences on the page (don't know if that's relevant to the solution I'm asking for but throwing it in there just in case). Here is the code: Code: <html> <body style="background:#000;"> <div style="float:left;"> <img style="float:left;" id="me" src="fade_arrow2.png"/> <img style="float:left;margin-left:-44px;" src="fade_arrow1.png"/> <script type="text/javascript"> var element = document.getElementById('me') ; var duration = 4000; /* 1000 millisecond fade = 1 sec */ var steps = 20; /* number of opacity intervals */ var delay = 5000; /* 5 sec delay before fading out */ /* set the opacity of the element (between 0.0 and 1.0) */ function setOpacity(level) { element.style.opacity = level; element.style.MozOpacity = level; element.style.KhtmlOpacity = level; element.style.filter = "alpha(opacity=" + (level * 100) + ");"; } function fadeIn(){ for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + i + ")", i * duration); } setTimeout("fadeOut()", delay); } function fadeOut() { for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + (1 - i) + ")", i * duration); } setTimeout("fadeIn()", duration); } /* start the effect */ fadeIn(); </script> </div> </body> </html> ok i am trying to make a countdown timer from 20 seconds when i click start where am i going wrong with this Code: <html> <head> </head> <body> <script type="text/javascript"> function timer() { var milisec=0 var seconds=20 document.counter.d2.value=20 function display() { if (milisec<=0){ milisec=9 seconds-=1 } if (seconds<=-1){ milisec=0 seconds+=1 } else milisec-=1 document.counter.d2.value=seconds+"."+milisec setTimeout("display()",100) display() }} </script> <form name="counter"> <center> Text Timer<br> <input type="text" size="30" name="d2"> <br> <input type="button" onclick="timer()" value="click me to start"> </center> </form> </body> </html> sorry i think this is in the wrong section...how do i remove I have a form and the Js validation wont work on it. Here is the html PHP Code: <form name="frm" action="index.php" method="POST" onsubmit="return validateForm();"> <table width="100%" border="0" cellspacing="2" cellpadding="3" class="mainForm"> <tr> <td class="normalText" align="left" style="padding:0px 0px 0px 33px"> <table border="0" cellspacing="3" cellpadding="2"> <tr> <td class="normalHeading" colspan="2" style="padding-bottom:6px"> <div id="error_msg" class="txtErrorMsg" align="center"></div> <!-- <?php echo "<p id=\"error_msg\">".$message."</p>"?> --> </td> </tr> <tr > <td class="normalText" width="30%">First Name</td> <td><input type="text" name="firstName" id="firstName" class="input1" style="width:195px" maxlength="10"/></td> </tr> <tr> <td class="normalText">Last Name</td> <td><input type="text" name="lastName" id="lastName" class="input1" style="width:195px" maxlength="10"/></td> </tr> <tr> <td class="normalText">Mobile</td> <td><input type="text" name="mobile" id="mobile" class="input1" style="width:195px" maxlength="10" onkeypress="return fnIsIntNumber(event,this);"/></td> </tr> <tr> <td class="normalText">Email</td> <td><input type="text" name="email" id="email" class="input1" style="width:195px" onblur="IsEmail(this.vlaue)"/></td> </tr> <tr> <td class="normalText">Comments</td> <td> <textarea name="comments" id="comment" cols="22" rows="3" ></textarea> </td> </tr> <tr> <td class="normalText"> </td> <td valign="middle"><input class="send" type="image" value='submit' src="images/submit.gif" name="submit" /></td> </tr> </table> </td> </tr> </table> </form> and here is the JS PHP Code: var $j = jQuery.noConflict(); function isValidEmail(str) { return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); } function validateForm(){ var firstName; var lastName; var email; var mobile; var comment; var error; firstName = $j('#firstName').val(); lastName = $j('#lastName').val(); email = $j('#email').val(); mobile = $j('#mobile').val(); comment = $j('#comment').val(); if(firstName=='' || firstName.length < 3){ error = 'Please Enter Your First Name'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(lastName=='' || lastName.length < 3){ error = 'Please Enter Your Second Name'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(email=='' || !isValidEmail(email)){ error = 'Please Enter Your Correct Email'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } //mob //$jmob_pattern = '^\d{10}$j'; if(mobile.length != 10 || isNaN(mobile)){ error = 'Please Enter Your Correct Mobile Number'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(comment.length < 10){ error = 'Please Enter A Comment More Than 10 Characters'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } return true; } Can anybody tell me what the problem is Hey guys I need a small help. I am new to Javascript. I want to save data from dropdownlist to XML file. Save function is working but I dont know how to load data list from dropdown to xml file. I can do with input element but dont know how to work with dropdown element. How to do this? Look at my codes below: HTML markup (index.html): FOCUS ON RED <body> <form name="reg" action="index.html" method="get"> Name: <input type="text" name="name_input" /> Pass: <input type="text" name="pass_input" /> <select id="language"> <option name="select_afrikaans">Afrikaans</option> <option name="select_english">English</option> </select> <br /> <input type="button" value="SAVE" onclick="javascriptk_click();" /> </form> </body> Javascript: function ok_click() { var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0"); xmlDoc.async = false; xmlDoc.load("data.xml"); if (xmlDoc.readyState == 4 && xmlDoc.parseError.errorCode == 0) { var root = xmlDoc.documentElement; var _input_name = xmlDoc.createTextNode(document.reg.name_input.value); var _input_pass = xmlDoc.createTextNode(document.reg.pass_input.value); var _select_afrikaans = xmlDoc.createTextNode(document.reg.select_afrikaans.value); var _select_english = xmlDoc.createTextNode(document.reg.select_english.value); var input_name = xmlDoc.createNode(1, "USER", ""); var input_pass = xmlDoc.createNode(1, "PASS", ""); var input_select = xmlDoc.createNode(1, "LANGUAGE", ""); input_name.appendChild(_input_name); input_pass.appendChild(_input_pass); select_afrikaans.appendChild(_select_afrikaans); select_english.appendChild(_select_english); var cust = xmlDoc.createNode(1, "CUST", ""); cust.appendChild(input_name); cust.appendChild(input_pass); cust.appendChild(select_afrikaans); cust.appendChild(select_english); root.appendChild(cust); SaveXML(xmlDoc, "data.xml"); alert("Save!"); } } // It is working fine function SaveXML(xmlDoc, filename) { var outputXML = new String(xmlDoc.xml); var mfObj = new ActiveXObject("Scripting.FileSystemObject"); var absPath = getPath(); var file = mfObj.CreateTextFile(absPath + filename, true); file.Write(outputXML); file.Close(); } //it is working fine function getPath() { var path = document.location; var str = new String(path); var end = str.lastIndexOf("/"); var absolutePath = str.substring(8, end) + "/"; absolutePath = absolutePath.replace(/ /g, " "); return absolutePath; } XML File: <?xml version="1.0"?> <DATA> <CUST> <USER>natalie</USER> <PASS>80</PASS> </CUST> ........ here should display xml data from dropdown list.....how? </DATA> Your help would much appreciated. Thank you very much Regards Natz |