JavaScript - .getelement Function Returning "undefined"
Here is a clip of code from a script project im working on. Now my document.getElementsByTagName is returning a "undefined" value.
Can anyone tell me whats wrong with my code? Code: <a href="http://www.anotherrandomsite.com" style="text-decoration: none; color: #EDDBAF; font-size: 16px;"> <center style="margin-left: 10px; margin-right: 10px;"> <font style="color: #EDDBAF; font-size: 16px;" id="title"></font> </center> </a> <li id="name"><a http="http://www.randomsite.com" style="color: blue;">John Doe</a></li> <script type="text/javascript"> var pname = document.getElementById('name').getElementsByTagName('a'); //now if i remove the ".getElementsByTagName('a')" it will actually work, but it also includes the <a> tag thats within the <li> tag, which i dont want. document.getElementById('title').innerHTML=pname.innerHTML; </script> Similar TutorialsHi, My webpage can work normally in IE but not in Safari(e.g. when I clicked on some buttons like 'Delete' button, the page opened in Safari stays the same while it should delete the object chosen). When I tried debugging on Safari, after clicking the 'update' button, this message error appeared: "TypeError: Result of expression 'this.form.fireEvent' [undefined] is not a function". I believe this code makes the incompatability between the 2 browser: Code: function DeleteClick() { var frmSWO = document.getElementById("form"); var answer = confirm("Do you really want to delete?") if (answer != 0) { frmSWO.action = "/domsWeb/mtd/doms/web/operation/eDepotMNR/controller/manageWorkOrder/DeleteJobOrImage.do"; frmSWO.method = "post"; this.form.fireEvent('onsubmit'); frmSWO.submit(); } } Any suggest how should I amend the script for it to work on 2 browser concurrently? Thanks all! Hi everyone, I'm using a JavaScript to upload multiple files, namely this one: http://valums.com/ajax-upload/ The script has the ability to post additional parameters to the server, by calling the function setParams Code: var doktyp = "default"; var uploader = new qq.FileUploader({ element: document.getElementById('file-uploader-scope'), action: 'uploads.php', // additional data to send, name-value pairs debug: true, onSubmit: uploader.setParams ({ dateityp: getCheckedValue(document.forms['doktyp'].elements['dateityp']), comment: jQuery('#dateityp').val() }) }); Without the onSubmit: part the script works well and does as it's supposed to, but with it FireBug reports "uploader is undefined" und the script seizes to function. Now JavaScript istn't my strong suit, so I have been reading up on this for the last two hours, tried calling that function from a different place, tried to modify it, but no luck; the error remains the same (or slightly different; if I point at the class in question directly, the function doesnt work...). I would appreciate any advice you could give. Hi, window.clipboardData.getData("text") is giving undefined on remote server(unix). When deployed locally(windows xp) it is coming giving correct value. In both cases the brower is IE running on windows xp. Is there anything wrong in the way I am reading the clipboard data? Alright so this is my problem. I'm using ajax to validate my form without refreshing the page. Everything works but the message part of my contact form. The name, email, and subject get passed but the message returns back as "undefined". I've looked through some of the older posts with the keyword being undefined and I didn't really find anything that helped. I've been trying to get this working for like days now an I'm sure its something really simple and right under my nose. So I will post my html for the form and the validation code. I want to thank all who help. Here is the HTML Code: <div id="forminfo"> <form name="contact" method="post" action=""> <dl> <dt id="name"><label for="fName" class="">Name</label></dt> <dd><input type="text" class="text" name="fName" id="fName" style="width:200px; height:20px;" /></dd> <label class="error" for="fName" id="fName_error">This field is required.</label> <dt id="eMail"><label for="email" class="">Email</label></dt> <dd><input type="text" class="text" name="email" id="email" style="width:200px; height:20px;" /></dd> <label class="error" for="email" id="email_error">This field is required.</label> <dt id="subject"><label for="subject">Subject</label></dt> <dd><input type="text" size="8" maxlength="40" name="subject" id="subj" style="width:200px; height:20px;" class="text" /></dd> <label class="error" for="subject" id="subj_error">This field is required.</label> <dt id="comments">Message</dt> <dd><textarea name="memo" class="text2" id="memo"></textarea></dd> <dd><input type="submit" class="button" id="submit" name="submit" value="" /></dd> </dl> </form> </div><!--forminfo--> Here is the JavaScript/AJAX Code: $(function() { $('.error').hide(); $('input.text-input').css({backgroundColor:"#FFFFFF"}); $('input.text-input').focus(function(){ $(this).css({backgroundColor:"#FFFFFF"}); }); $(".button").click(function() { // validate and process form // first hide any error messages $('.error').hide(); var name = $("input#fName").val(); if (name == "") { $("label#fName_error").show(); $("input#fName").focus(); return false; } var email = $("input#email").val(); if (email == "") { $("label#email_error").show(); $("input#email").focus(); return false; } var subject = $("input#subj").val(); if (subject == "") { $("label#subj_error").show(); $("input#subj").focus(); return false; } var comments = $("input#memo").val(); if (comments == "") { $("input#memo").focus(); return false; } var dataString = 'fName='+ name + '&email=' + email + '&subj=' + subject + '&memo=' + comments; //alert (dataString);return false; $.ajax({ type: "POST", url: "bin/process.php", data: dataString, success: function() { $('.formContainer').html("<div id='message'></div>"); $('#message').html("<h2>Contact Form Submitted!</h2>") .append("<p>I will be in touch soon.</p>") .hide() .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='images/check.png' />"); }); } }); return false; }); }); runOnLoad(function(){ $("input#fName").select().focus(); }); Code: <script type="text/javascript"> function loadText() { var t1=setTimeout("document.getElementById('data').innerHTML='<center><img style=\"margin-top:30px;\" src=\"loading.gif\" /></center>'",0000); var t2=setTimeout("document.getElementById('data').innerHTML='THEPAGE'",6000) } </script> The above is in the header, and I'm calling it in the html. Code: <script type="text/javascript"> document.write(loadText()); </script> in the page it displays properly, but then it also says "undefined" not sure why? anyone have any ideas? I've been testing my site in firefox and safari and everything was a OK. Now IE is telling me that "pagetracker" is undefined and its not taking me to the other links on my site. Also the content on the first page is not showing up in IE. jonathaneiger.com Hiya, I would like to ask your help regarding this damned error message that comes out only in Internet Explorer and makes impossible to submit the form. The javascript code is: Code: function checkForm() { var cname, cspouse, cemail, chphone, ccellular, caddress, ccity, cstate, czip, cpets, cvolunteer, cadditional; with(window.document.volApplForm) { cname = Name; cspouse = Spouse; cemail = Email; chphone = HomePhone; ccellular = Cellular; caddress = Address; ccity = City; cstate = State; czip = Zip; cpets = Pets; cvolunteer = Volunteer; cadditional = Additional; } var ALERT_TITLE = "Oops!"; var ALERT_BUTTON_TEXT = "Close"; if(document.getElementById) { window.alert = function(txt) { createCustomAlert(txt); } } function createCustomAlert(txt) { d = document; if(d.getElementById("modalContainer")) return; mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div")); mObj.id = "modalContainer"; mObj.style.height = document.documentElement.scrollHeight + "px"; alertObj = mObj.appendChild(d.createElement("div")); alertObj.id = "alertBox"; if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px"; alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px"; h1 = alertObj.appendChild(d.createElement("h1")); h1.appendChild(d.createTextNode(ALERT_TITLE)); msg = alertObj.appendChild(d.createElement("p")); msg.innerHTML = txt; btn = alertObj.appendChild(d.createElement("a")); btn.id = "closeBtn"; btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT)); btn.href = "#"; btn.onclick = function() { removeCustomAlert();return false; } } if(trim(cname.value) == '') { alert('Please enter your name'); function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cname.focus();} return false; } else if(trim(cemail.value) == '') { alert('Please enter your email'); function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cemail.focus();} return false; } else if(!isEmail(trim(cemail.value))) { alert('Email address is not valid'); function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cemail.focus();} return false; } else if(trim(chphone.value) == '') { alert('Please enter your valid phone number'); function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); chphone.focus();} return false; } else if(trim(ccellular.value) == '') { alert('Please enter valid cell phone number'); function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); ccellular.focus();} return false; } else if(trim(caddress.value) == '') { alert('Please enter your valid address'); function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); caddress.focus();} return false; } else if(trim(ccity.value) == '') { alert('Please enter your city'); function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); ccity.focus();} return false; } else if(trim(cstate.value) == '') { alert('Please enter valid state name'); function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cstate.focus();} return false; } else if(trim(czip.value) == '') { alert('Please enter valid zip code'); function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); czip.focus();} return false; } else if(trim(cvolunteer.value) == '') { alert('Please fill in all fields'); function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cvolunteer.focus();} return false; } else if(trim(cadditional.value) == '') { alert('Please fill in all fields'); function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cadditional.focus();} return false; } else { cname.value = trim(cname.value); cspouse.value = trim(cspouse.value); cemail.value = trim(cemail.value); chphone.value = trim(chphone.value); ccellular.value = trim(ccellular.value); caddress.value = trim(caddress.value); ccity.value = trim(ccity.value); cstate.value = trim(cstate.value); czip.value = trim(czip.value); cpets.value = trim(cpets.value); cvolunteer.value = trim(cvolunteer.value); cadditional.value = trim(cadditional.value); return true; } } function trim(str) { return str.replace(/^\s+|\s+$/g,''); } function isEmail(str) { var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn |bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk| dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs |gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr| kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum |mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr |pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf |tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za| zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i; return regex.test(str); } And when trying to submit the form, I get the error message: Code: Line: 177 Character: 4 Code: 0 Error Message: 'undefined' is null or not an object URL: https://localhost/ruff/scripts/validationVol.js Do you have an idea what could be the problem? As I checked line 177, it seems to be OK. I checked the web, but didn't find anything related to this message in a situation like this. Thanks in advance for your comments. Whenever this function sorts itself out, the value of the variable I want ends up "undefined". It starts here in my code with this link. $sort is the variable that's giving me trouble. If I echo it here, it works correctly. Code: <a id='showMoreLink' onclick='showMorePosts($showMoreCount,$sort)'>Show more...</a> Here is snippets of the showMorePosts function Code: function showMorePosts(str,sortBy) { xmlhttp.open('GET','ajaxQueries.php?sort='+sortBy+'&q='+str,true); xmlhttp.send(); } And here is where I am echoing $sort in ajaxQueries.php, and getting "undefined". Note that $q works just as it should. (All I can think is q is an integer, and sort is a string) PHP Code: $q=$_GET['q']; $sort=$_GET['sort']; echo $sort.$q; Hello. My goal is to write a form input to the cookie. The rest of the cookie works, and if I declare var user_email = 'muppet';, the content becomes "muppet". However, if I try to do something more dynamic, like var user_email = document.addform.email it becomes "undefined". I tried adding ".value" to that as well. I have been at this since yesterday, and tried solutions like running a setEmail() function, or getElementById. Here is my cookie writing function, which I call with onsubmit="createCookie('userEmail',user_email,365)" Code: <script type="text/javascript"> var user_email = 'muppet'; function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } </script> The form looks like this: Code: <form name="addform" action="http://formmail.dreamhost.com/cgi-bin/formmail.cgi" method="post" onsubmit="createCookie('userEmail',user_email,365)"> <input type="hidden" name="required" value="email" /> <input type="hidden" name="redirect" value="http://www.saverally.com/confirmed.html" /> <input type="hidden" name="recipient" value="addme@saverally.com" /> <input type="hidden" name="subject" value="add to list" /> Your Email: <input type="text" name="email" name=email size="20" value="" /> <input type="submit" value="Send"/> </form> Thanks! I am trying to manipulate a an image gallery that functions well. Now, I have the ability to pull information from a user's preference pannel and need to place it in the an href="" // And other information in each of the "src" | "url" | "alt". Any ideas would be truly helpful. This is what I am working with at the moment and it doesn't work (obviously because it is adding code inside a span). Here is what I am starting from: [CODE] var title01Span = document.getElementById('title01Span'), //Finds the id that I want prefs = new gadgets.Prefs(), // Pulls from the user's preferences yourtitle01 = prefs.getString("title01"); // Pulls the correct string from those preferences title01Span.innerHTML = yourtitle01; // replaces the span.id with that text but I need to be able to do this in the src / href / url / etc. [CODE] Thank you so much! I seriously could use as much help as possible! I had some code written for me. Basically it outputs something like this based on user input: Code: <span>name 1 - <a href=\"test1b\" rel="nofollow" target=\"_blank\">test1a</a> - $12</span><br/> <span>name 2- <a href=\"test2b\" rel="nofollow" target=\"_blank\">test2a</a> - $24</span><br/> What it used to look like: Code: /** * @FUNCTION: finalize :: PUBLIC * This is a shorter version of the codes you * had before and also have a more faster speed */ $.finalize = function(g) { /* Setting global variables */ var i,k,d,p,j,n=0,t=[],f=[],preview=false,addbr='',addExtra='', o=document.getElementsByTagName('div'), s=document.getElementById(g), /* Creating getName function */ getName=function(o){ /* Setting getName global variables */ var i,n= ['Motherboard','CPU','RAM','Video Card', 'Hard Drive','Power Supply','Case', 'Operating System','Other'] ; /* Obtaining and returning the result */ for(i=0;i<n.length;i++){if(n[i].toLowerCase()== o.toLowerCase().replace('_',' ')){return n[i];}} }; /* Obtaining the full total */ $.findTotal(); /* Looping through all active boxes */ for(i=0;i<o.length;i++) { /* Splitting current box class by spaces */ k = o[i].className.split(' '); /* Looping through each class items */ for(j=0;j<k.length;j++) { /* Checking if this item is equal to itemBox */ if(k[j] == 'itemBox') { /* Setting d as the current box that contains itemBox in the class */ d = document.getElementById(o[i].id); /* If d's display is not empty and doesn't equal none */ if(d.style.display !== '' && d.style.display !== 'none') { /* Setting up the loops global variables */ var h=d.getElementsByTagName('input'),name='', text='',link='',quantity='',price='',run=false; /* Looping through each of the inputs and obtaining the correct information */ for(p=0;p<h.length;p++) { /* If current input name contains [name] and is not disabled */ if(h[p].name.indexOf('[name]') !== -1 && !h[p].disabled) { /* Obtaining the correct name for the current box */ name = getName(h[p].name.match(/computer\[(\w+)\]\[name\]/)[1]); /* IF current input value is not empty and Setting the variable as the current inputs value */ if(h[p].value !== '') {text = ' '+h[p].value;run = true;} /* If current input name contains [link] and is not disabled and the value is not empty */ } else if(h[p].name.indexOf('[link]') !== -1 && !h[p].disabled && h[p].value !== '') { /* If variable text is not empty output the forum URL and Custom text string */ if(text.substr(1) !== '') {link = ' <a href="'+h[p].value+'" rel="nofollow" target="_blank">'+text.substr(1)+'</a>';} /* If variable text is empty output the forum URL string */ else {link = '" rel="nofollow" target="_blank">'+h[p].value+'</a>';} run = true; /* If current input name contains [quantity] and is not disabled and the value is not empty */ } else if(h[p].name.indexOf('[quantity]') !== -1 && !h[p].disabled && h[p].value !== '') { /* Setting the variable as the current inputs value */ quantity = ' ('+parseInt(h[p].value)+')'; run = true; /* If current input name contains [price] and is not disabled and the value is not empty */ } else if(h[p].name.indexOf('[price]') !== -1 && !h[p].disabled && h[p].value !== '') { /* Setting the variable as the current inputs value */ var add = (text !== '' | link !== '' | quantity !== '')?' -':''; price = add+' $'+parseInt(h[p].value); run = true; } } /* Checking if link is not empty, if it is check if text is not empty and if that is then set as empty */ link = (link !== '')?link:(text !== '')?text:''; name = (run)?name+' -':''; /* Add this full string to the global array */ f[n] = "<span>"+name+''+link+''+quantity+''+price+"</span><br/>"; /* Add 1 to the number n */ n++; /* Allowing preview */ preview = true; } } } } if(total && f.join('') !== '') {addExtra+="\n\n<p>Total Price: $"+total+"</p>";} /* If s exists set the innerHTML as the full f array imploded by \n at the end of each array item */ if(s) {for(i=0;i<f.length;i++){if(f[i]!==''){t[i]=f[i];}}s.value=t.join("\n")+addExtra;} /* Updating the total */ $.findTotal(); /* Checking if preview is true */ if(preview && f.join('') !== '') { /* Displaying the preview to the user */ $.preview('display','preview'); } else { /* Hiding the preview from the user */ $.preview('hide','preview'); } }; But for some reason, when I change the part in red, it starts saying undefined: Code: /** * @FUNCTION: finalize :: PUBLIC * This is a shorter version of the codes you * had before and also have a more faster speed */ $.finalize = function(g) { /* Setting global variables */ var i,k,d,p,j,n=0,t=[],f=[],preview=false,addbr='',addExtra='', o=document.getElementsByTagName('div'), s=document.getElementById(g), /* Creating getName function */ getName=function(o){ /* Setting getName global variables */ var i,n= ['Speakers 1','Speakers 2','AMP','Source Comp. 1', 'Source Comp. 2','Source Comp. 3','Other'] ; /* Obtaining and returning the result */ for(i=0;i<n.length;i++){if(n[i].toLowerCase()== o.toLowerCase().replace('_',' ')){return n[i];}} }; /* Obtaining the full total */ $.findTotal(); /* Looping through all active boxes */ for(i=0;i<o.length;i++) { /* Splitting current box class by spaces */ k = o[i].className.split(' '); /* Looping through each class items */ for(j=0;j<k.length;j++) { /* Checking if this item is equal to itemBox */ if(k[j] == 'itemBox') { /* Setting d as the current box that contains itemBox in the class */ d = document.getElementById(o[i].id); /* If d's display is not empty and doesn't equal none */ if(d.style.display !== '' && d.style.display !== 'none') { /* Setting up the loops global variables */ var h=d.getElementsByTagName('input'),name='', text='',link='',quantity='',price='',run=false; /* Looping through each of the inputs and obtaining the correct information */ for(p=0;p<h.length;p++) { /* If current input name contains [name] and is not disabled */ if(h[p].name.indexOf('[name]') !== -1 && !h[p].disabled) { /* Obtaining the correct name for the current box */ name = getName(h[p].name.match(/computer\[(\w+)\]\[name\]/)[1]); /* IF current input value is not empty and Setting the variable as the current inputs value */ if(h[p].value !== '') {text = ' '+h[p].value;run = true;} /* If current input name contains [link] and is not disabled and the value is not empty */ } else if(h[p].name.indexOf('[link]') !== -1 && !h[p].disabled && h[p].value !== '') { /* If variable text is not empty output the forum URL and Custom text string */ if(text.substr(1) !== '') {link = ' <a href="'+h[p].value+'" rel="nofollow" target="_blank">'+text.substr(1)+'</a>';} /* If variable text is empty output the forum URL string */ else {link = '" rel="nofollow" target="_blank">'+h[p].value+'</a>';} run = true; /* If current input name contains [quantity] and is not disabled and the value is not empty */ } else if(h[p].name.indexOf('[quantity]') !== -1 && !h[p].disabled && h[p].value !== '') { /* Setting the variable as the current inputs value */ quantity = ' ('+parseInt(h[p].value)+')'; run = true; /* If current input name contains [price] and is not disabled and the value is not empty */ } else if(h[p].name.indexOf('[price]') !== -1 && !h[p].disabled && h[p].value !== '') { /* Setting the variable as the current inputs value */ var add = (text !== '' | link !== '' | quantity !== '')?' -':''; price = add+' $'+parseInt(h[p].value); run = true; } } /* Checking if link is not empty, if it is check if text is not empty and if that is then set as empty */ link = (link !== '')?link:(text !== '')?text:''; name = (run)?name+' -':''; /* Add this full string to the global array */ f[n] = "<span>"+name+''+link+''+quantity+''+price+"</span><br/>"; /* Add 1 to the number n */ n++; /* Allowing preview */ preview = true; } } } } if(total && f.join('') !== '') {addExtra+="\n\n<p>Total Price: $"+total+"</p>";} /* If s exists set the innerHTML as the full f array imploded by \n at the end of each array item */ if(s) {for(i=0;i<f.length;i++){if(f[i]!==''){t[i]=f[i];}}s.value=t.join("\n")+addExtra;} /* Updating the total */ $.findTotal(); /* Checking if preview is true */ if(preview && f.join('') !== '') { /* Displaying the preview to the user */ $.preview('display','preview'); } else { /* Hiding the preview from the user */ $.preview('hide','preview'); } }; Hello, I run a online gaming website, and I'm having problems with certain websites iframing our games. Actually I'm ok with iframing, as long as they include the banner ad located just beneath our games. But often times unscrupulous webmasters will iframe only the game, preventing us from generating any revenue from the banner ad (and costing us additional bandwidth charges). I'm hoping to find a way to detect the dimensions of the iframe, so that I may dynamically resize the game, in order to include the banner ad within the iframe. Does anybody know how to extract the "height" and "width" attribute values from an <iframe> tag sitting on a different site? Regards, Steve Hi all, I'm having a bit of a problem.. I need to disable the submit button on body onload, and i need to re-enable it when "i agree" is checked. the problem is, it wont do this.. it literally stays disabled, even after check mark.. code: Code: <html> <head><title>Metal Detecting</title></head> <body onload="disable()" oncontextmenu="return false;"> <script> function disable(){ if(document.forms.test.agree.checked == false){ document.forms.test.s1.disabled = true; } } function enable(){ if(document.forms.test.agree.checked == true){ document.forms.test.s1.disabled = false; } } function checkCheckBox(f) { if (f.agree.checked == false) { alert('You MUST agree to the terms by checking the box above.'); return false; }else{ enable() return true; } } var max=255; function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit){ // if too long...trim it! field.value = field.value.substring(0, maxlimit); // otherwise, update 'characters left' counter }else{ countfield.value = maxlimit - field.value.length; } } function submitonce(theform){ //if IE 4+ or NS 6+ if (document.all||document.getElementById){ //screen thru every element in the form, and hunt down "submit" and "reset" for (i=0;i<theform.length;i++){ var tempobj=theform.elements[i] if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") //disable em tempobj.disabled=true } } } function checkdata(which) { var pass=true; var t1 = document.forms.test; for (i=0;i<which.length;i++) { var tempobj=which.elements[i]; if (tempobj.name.substring(0,8)=="required") { if (((tempobj.type=="text"||tempobj.type=="textarea")&& tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&& tempobj.selectedIndex==0)) { pass=false; break; } } } if (!pass) { shortFieldName=tempobj.name.substring(8,30).toUpperCase(); alert("The "+shortFieldName+" field is a required field."); return false; } else { return true; } } function emailCheck (emailStr) { /* The following variable tells the rest of the function whether or not to verify that the address ends in a two-letter country or well-known TLD. 1 means check it, 0 means don't. */ var checkTLD=1; /* The following is the list of known TLDs that an e-mail address must end with. */ var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; /* The following pattern is used to check if the entered e-mail address fits the user@domain format. It also is used to separate the username from the domain. */ var emailPat=/^(.+)@(.+)$/; /* The following string represents the pattern for matching all special characters. We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ] */ var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; /* The following string represents the range of characters allowed in a username or domainname. It really states which chars aren't allowed.*/ var validChars="\[^\\s" + specialChars + "\]"; /* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes). E.g. "jiminy cricket"@disney.com is a legal e-mail address. */ var quotedUser="(\"[^\"]*\")"; /* The following pattern applies for domains that are IP addresses, rather than symbolic names. E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */ var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; /* The following string represents an atom (basically a series of non-special characters.) */ var atom=validChars + '+'; /* The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */ var word="(" + atom + "|" + quotedUser + ")"; // The following pattern describes the structure of the user var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); /* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */ var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); /* Finally, let's start trying to figure out if the supplied address is valid. */ /* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. */ var matchArray=emailStr.match(emailPat); if (matchArray==null) { /* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. */ alert("Email address seems incorrect (don't forget to add an @ and a . to your email address!)"); return false; } var user=matchArray[1]; var domain=matchArray[2]; // Start by checking that only basic ASCII characters are in the strings (0-127). for (i=0; i<user.length; i++) { if (user.charCodeAt(i)>127) { alert("Ths username contains invalid characters."); return false; } } for (i=0; i<domain.length; i++) { if (domain.charCodeAt(i)>127) { alert("Ths domain name contains invalid characters."); return false; } } // See if "user" is valid if (user.match(userPat)==null) { // user is not valid alert("The username doesn't seem to be valid."); return false; } /* if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid. */ var IPArray=domain.match(ipDomainPat); if (IPArray!=null) { // this is an IP address for (var i=1;i<=4;i++) { if (IPArray[i]>255) { alert("Destination IP address is invalid!"); return false; } } return true; } // Domain is symbolic name. Check if it's valid. var atomPat=new RegExp("^" + atom + "$"); var domArr=domain.split("."); var len=domArr.length; for (i=0;i<len;i++) { if (domArr[i].search(atomPat)==-1) { alert("The domain name does not seem to be valid."); return false; } } /* domain name seems valid, but now make sure that it ends in a known top-level domain (like com, edu, gov) or a two-letter word, representing country (uk, nl), and that there's a hostname preceding the domain or country. */ if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) { alert("The address must end in a well-known domain or two letter " + "country."); return false; } // Make sure there's a host name preceding the domain. if (len<2) { alert("This address is missing a hostname!"); return false; } // If we've gotten this far, everything's valid! return true; } </script> Please contact us!<br><br> *Please note you can submit the form ONLY once. Any double form submissions will be deleted.<br> <form name="test" id="test" method="POST" onsubmit="return checkdata(this), emailCheck(this.email.value), checkCheckBox(this)" action="send.php"> <div id = "div01" style="width: 100; height: 25;"> Firstname: <input name="requiredfirstname" id="firstname" type="text" /> Lastname: <input name="requiredlastname" id="lastname" type="text" /> Email: <input name="requiredemail" id="email" type="text" /><br /><br /> </div> <H4>Your statement: </H4> <textarea onKeyDown="textCounter(this.form.statement,this.form.counter,max);" onKeyUp="textCounter(this.form.statement,this.form.counter,max);" name="requiredstatement" id="statement" rows="15" cols="40"></textarea><br /> Characters left: <input readonly="readonly" value="255" size=3 maxlength=3 type="text" name="counter" id="counter"><br/><br /> <textarea name="license" cols="40" rows="15" id="license">Blah!</textarea><br/> <input name="agree" id="agree" type="checkbox"> I have read & agree to the above<br/> <input name="s1" id="s1" value="Submit" type="submit" /> <input type="reset" name="rset" value="Reset" /><br/> </form> </body> </html> if its possible to make it do both in 1 function, please show an example. if you have to use 2 functions, then also show me an example. ANY help is GREATLY appreciated! Hello, recently I have been to many government websites where I have noticed that the programmer has used window.open() method in JavaScript to link to different pages instead of using <a> tags! I was just getting curious to know whether it is normal or has it been used due to security concerns(if any, I don't know)? Any comments? ok so Code: document.write("Goodbye!"); works but I put ^ that inside a function Code: function SayHello () ( document.write("Goodbye!"); ) and it stops working? I know the function call works because when I place some code to display an image in SayHello function, it displays the image. Quote: <html> <head> <script type="text/javascript"> var a = january var b = febuary var c = march function test() { document.getElementById("test").innerHTML=a; <!-- needs to be A on first function click, b on second, c on third, etc..^^--> } </script> </head> <body> <p id="test"></p> <!-- the <p> should go to next month upon each function --> <input type="button" value="asdf" onclick="test()" /> </body> </html> I tried to explain it pretty well in the comment tags, thanks! I'm trying to get the following function working Code: function jump(document_root, mode, cat, id, qs) { var response = confirm("Are you sure that you want to completely delete this record"); if(response) { var url = document_root+"/"+mode+"/"+cat+"/"+id+qs; window.location(url); return true; } else return false; } It called with the following Code: <a href="" onclick="jump('/tradedoubler_admin/web', 'Pages', 'Delete', '011' ,'');">Delete</a> But the redirect isnt working i get the following error : Code: Error: uncaught exception: [Exception... "Cannot convert WrappedNative to function" nsresult: "0x8057000d (NS_ERROR_XPC_CANT_CONVERT_WN_TO_FUN)" location: "JS frame :: http://192.168.1.99/tradedoubler_admin/web/scripts/pagejump.js :: jump :: line 7" data: no] Is any one familiar with this error? It's suppose to be a pop up box that asks if the user really want to delete this record, if he clicks yes it redirects to delete it, but if not it doesn't do anything. Hello im having trouble with my onclick button specifically the "doall" is there a problem with my function or the button? Console says ReferenceError: doAll is not defined but I have set the function doAll so I don't get what's wrong. <!DOCTYPE html> <HTML> <HEAD><TITLE>Choice</TITLE> <meta content="text/html;charset=utf-8" http-equiv="Content-Type"> <meta content="utf-8" http-equiv="encoding"> <SCRIPT Language="javascript"> muresources="" muresources["classical"]= "<A HREF='http://net.com/classical.file1'>Meditative classical music<A><P> <A HREF='http://net.com/classical.file2'>Provoking classical music<A>" muresources["rock"] = "<A HREF='http://net.com/rock.file1'>Popular rock music<A><P> <A HREF='http://net.com/rock.file2'>Exciting rock music<A>" muresources["ethnic"] = "<A HREF='http://net.com/mexican.file1'>Mexican music<A><P> <A HREF='http://net.com/Indian.file2'>Indian music<A>" function getLink() { temp = muresources[choice] temp2 = "<TITLE>Custom Links</TITLE><H3>" +document.m.pername.value+", here are some links for you</H3><P>"+temp } function writeIt(){ diswin = window.open(); diswin.document.open(); diswin.document.write(temp2); diswin.document.close() } function doAll(){ getLink(); writeIt() } </SCRIPT> </HEAD> <BODY > <H3> Choose the kind of music you prefer<BR> and this page will fetch links of interest to you</H3> <HR> <FORM NAME="m" > Choose a kind of music<P> <INPUT TYPE="radio" NAME="mus" VALUE="classical" OnClick="choice='classical'" >Classical <BR> <INPUT TYPE="radio" NAME="mus" VALUE="rock" OnClick="choice='rock'">Rock<BR> <INPUT TYPE="radio" NAME="mus" VALUE="ethnic" OnClick="choice='ethnic'">Ethnic<BR> <HR> Please type your name<P> <INPUT TYPE="text" NAME="pername" SIZE=25> <HR> <INPUT TYPE="button" NAME="sub" VALUE="Show me links" OnClick=doAll()> <INPUT TYPE="reset" NAME="res" > </FORM> <SCRIPT> choice = "classical" document.m.mus[0].checked = true document.m.mus[1].checked = false document.m.mus[2].checked = false </SCRIPT> </BODY> </HTML> Title basically says it. I need to get the object that was just clicked, to insert into a JavaScript function. I've tried "function('this')" and similar things, but it doesn't work. I'm sure this is REALLY easy to do, but I don't know it and I have no idea what to search for. Thanks Code: <html> <body> var j=0; var temp,temp2,temp3; <script> function scor(j) { switch(j) { case 1: alert("Απαντήσατε σωστά μόνο σε μία ερώτηση.Προσπαθήστε πάλι"); break; case 2: alert("Απαντήσατε σωστά στις δύο από τις τρείς ερωτήσεις"); break; default: alert ("Συγχαρητήρια απαντήσατε σωστά και στις τρεις ερωτήσεις"); } } </script> <meta http-equiv="content-type" content="text/hmtl; charset=iso-8859-7"> <p align="center"><font size="5">Σε μία σελίδα html πόσα είναι τα μέγιστα frames που μπορούμε να τοποθετήσουμε; </p></font> <form name="for1"> <input type="radio" name="fr1"value="1" > 5 <br> <input type="radio" name="fr1"value="2" > Όσα τα pixels<br> <input type="radio" name="fr1"value="3" > Δεν υπάρχει όριο<br> <input type="button" value="Εκχώρηση Απάντησης" onClick="getVal1()"> </form> <script type = "text/javascript"> function getVal1() { for(var i=0; i<document.for1.fr1.length; i++) { if (document.for1.fr1[i].checked) { if (document.for1.fr1[i].value==2) { j++; } } } } function getVal2() { for (var i=0;i<document.for2.fr2.length;i++) { if (document.for2.fr2[i].checked) { if (document.for2.fr2[i].value==2) { j++; } } } } function getVal3() { for (var i=0;i<document.for3.fr3.length;i++) { if (document.for3.fr3[i].checked) { if (document.for3.fr3[i].value==3) { j++; } } } } </script> <p align="center"><font size="5"> Είναι απαραίτητο σε κάθε σελίδα html να υπάρχουν τα tags head και title;</p></font> <form name="for2"> <input type="radio" name="fr2" value="1"> Ναι <br> <input type="radio" name="fr2" value="2"> Όχι <br> <input type="button" value="Εκχώρηση Απάντησης" onClick="getVal2()"> </form> <p align="center"><font size="5"> Τι κάνει το εξής tag: meta http-equiv="content-type" content="text/hmtl; charset=iso-8859-7" </p></font> <form name="for3"> <input type ="radio" name="fr3" value="1"> Δημιουργεί τις προυποθέσεις για την απόκτηση τιμών <br> <input type ="radio" name="fr3" value="2"> Ισσοροπεί τις παραγράφους σε στήλες <br> <input type ="radio" name="fr3" value="3"> Επιτρέπει την κωδικοποίηση ελληνικών χαρακτήρων στην ιστοσελίδα <br> <input type="button" value="Εκχώρηση Απάντησης" onClick="getVal3()" </form> <input type ="button" value="Υπολογισμός" onClick="scor(j)"> Apart from any logical mistakes this thing i have created might have , my question is this.Why upon pressing the last button and calling the "scor(j)" function , no alerts pop up?Thanks in advance. I'm completely stumbled by this as i have no clue as what might be wrong.But then again , my experience is extremely limited |