JavaScript - Stumped On Why My 'elementid' Is Undefined-why?
First time posting, I hope I'm doing this right. I'm having problems with the following code, it is just a simple form but I keep getting an error message saying " my elementId is undefiened and I can not find out where I messed up.
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Form Help</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> <script type="text/javascript"> /* <![CDATA[ */ function showHelp(elementID) { var curElement = document.getElementById(elementId); var helpElement = document.getElementById("box"); switch (elementId) { case "username": helpElement.innerHTML = "Enter a unique user name that is between 5 and 12 characters. "; break; case "password": helpElement.innerHTML = "Enter a password between 6 and 10 characters tht contains both upper and lowercae letters an at least one numeric character. "; break; case "password_confirm": helpElement.innerHTML = "Confirm your selected password. "; break; case "challenge": helpElement.innerHTML = "Enter your mother's maiden name. This value will be used to confirm your identity in the event that you forgot your password. "; break; } helpElement.innerHTML +="<a href=''onclick=\"document.getElementById('box').style.visibility = 'hidden';return false;\">Close</a>"; document.getElementById("box").style.visibility = "visible"; document.getElementById("box").style.left = curElement.offsetWidth + 20 + "px"; document.getElementById("box").style.top = curElement.offsetTop + "px"; } /* ]]> */ </script> </head> <body> <h1>Form Help</h1> <form action="" method="get" enctype="application/x-www-form-urlencoded"> <p><strong>User Name</strong><br /> <input type="text" id="username" size="50" onmouseover="this.style.cursor='help'" onclick="showHelp(this.id)" /></p> <p><strong>Password</strong><br /> <input type="password" id="password" size="50" onmouseover="this.style.cursor='help'" onclick="showHelp(this.id)" /></p> <p><strong>Confirm Password</strong><br /> <input type="password" id="password_confirm" size="50" onmouseover="this.style.cursor='help'" onclick="showHelp(this.id)" /></p> <p><strong>What is your mother's maden name?</strong><br /> <input type="password" id="challenge" size="50" onmouseover="this.style.cursor='help'" onclick="showHelp(this.id)" /></p> </form> <div id="box" style="position: absolute; visibility: hidden; width: 250px; background-color:#C0FFFF; font: Comic Sans MS; color: #A00000;border:1px dashed #D00000"></div> </body> </html> Similar TutorialsGreetings, Perhaps someone with the knowledge could assist me with this problem ... Basically, I need to put some code together to automatically redirect a page back to the referring page after a short delay ... and frankly I'm banging my head against a brick wall LOL OK ... got this in HTML to auto redirect to a specific web page after a defined delay : Code: <meta HTTP-EQUIV="REFRESH" content="10; url=http://www.****.co.uk/index.htm"> ... and I have this javascript for redirecting back to the referring page using a button : Code: <form method="POST"> input type="button" name="B1" value="Try it now" onclick="history.back();"> </form> So the question is how to combine the two so that I can get the page to return to the referring page after a delay automatically (that is, without having to press a button) ???? Any assistance would be really appreciated. Many thanks. O T T Hi all Sorry my first post is a question...but I hope you can help me out all the same. My name's Steve, and I have struggled (like all heck!) to figure this scenario out. I owe you a beer if you can help! OK, here's the scenario: I'm using a very basic redirect script, such as: Code: <html> <body> <script language="javascript" type="text/javascript"> function redirect(URL) { document.location=URL; return false; } </script> <a href="http://www.mywebsite.com" onclick="return redirect('http://www.mywebsite/contactme.html');">This Works</a> </body> </html> ...nothing you haven't seen a million times, right? BUT! I'd like the page I'm redirecting to (http://www.mywebsite/contactme.html) to open up an invisible iFrame, and then redirect the "parent" URL ("http://www.mywebsite.com") to an external site... So, 1) The visitor clicks on a link on my site (say, contactme.html) 2) The visitor is redirected to another page on my site (in an invisible iFrame)...e.g. mywebsite.com/processing.html 3) The iFrame loads in another invisible iFrame (for example, http://3rdpartysite.com/updatecontact.html) 4) The visitor on the contactme.html page is then redirected to a different domain (e.g. http://3rdpartysite.com/done.html) I've spent literally WEEKS trying to get this code going, and I'm now admitting defeat! I'm sure it's possible, but JS is not my specialist subject... ...at all I'd really appreciate ANY pointers, because I have a deadline to meet! Kind regards, Steve Hi all. I'm experiencing an issue with dijit.Tree/ForestStoreModel/ItemFileWriteStore and I just can't seem to figure out what's going on. If I start with an empty store model ... var myData= { "identifier" : "id", "label" : "name", "items" : [] }; var myStore = new dojo.data.ItemFileWriteStore({ data: myData }); var myModel = new dijit.tree.ForestStoreModel({ sto masterStore, query: {type: 'task'}, rootId: "tasks_id", rootLabel : "Tasks", childrenAttrs: ["children"] }); If I eventually execute newItem on the store, the tree is not updated. myStore.newItem( { id: "2", name : "someName2", type : 'task', children : [], } ); However, if during declaration of my data, I include 1 item, ie. var myData= { "identifier" : "id", "label" : "name", "items" : [ {"id" : "1", "name" : "someName", "type" : "task"} ] }; Then I can subsequent call newItem as many times as I wish, and the tree is updated correctly. If anybody has any ideas, I'm all eyes. Thanks for looking! I have a widget that lives on a blank/fresh Blogger.com account, and with test pictures, it seems to work fine. However, when I throw in Amazon ads it breaks. Images with links as sample data, rotate and display fine. Changing them to amazon code, they break. What's going on? Am I missing an escape character? Code: <script language="Javascript" type="text/JavaScript"> var ad = new Array() ad[0]=' <iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=netbooknewsco-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0051VVOB2" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> ' ad[1]='<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=netbooknewsco-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0051VVOB2" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> ' function randomorder(targetarray, spacing){ var randomorder=new Array() var the_one var z=0 for (i=0;i<targetarray.length;i++) randomorder[i]=i while (z<targetarray.length){ the_one=Math.floor(Math.random()*targetarray.length) if (targetarray[the_one]!="_selected!"){ document.write(targetarray[the_one]+spacing) targetarray[the_one]="_selected!" z++ } } } </script> <script language="Javascript" type="text/javascript" ></script> <script> randomorder(ad, ' ') </script> It seems like it should be simple, but I don't see what I'm missing. Right now, the search button displays directly under my input field. I've gone through the CSS, but can't figure out where my code is forcing the button onto its own line. What am I missing? How can I bring it up to the same line?? Code: <form role="search" method="get" id="searchform" action="http://www.centerpie.com/" > <div> <input type="text" value="" maxlength="100" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"> </div> </form> Hello! I have a really simple JavaScript calculator I'm running, and for the life of me can not figure out how to solve this crazy number problem. It's not doing the math properly, and javascript is not my strongest suit. All my script does is take user input of numbers into a form field, subtract that from another form and multiply the answer of those two forms by whatever the user put in. Example: 210 (minus) 120 (multiplied by) .90 = 81 Here is the actual script: Code: // Calculator function CalculateSum(Atext, Btext, Ctext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); form.Answer.value = A - B * C; } /* ClearForm: this function has 1 argument: form. It clears the input and answer fields on the form. It needs to know the names of the INPUT elements in order to do this. */ function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.input_C.value = ""; form.Answer.value = ""; } // end of JavaScript functions --> And the html I am using: Code: <form name="Calculator" method="post"> <p>Base Average<input type=text name="input_A"></p> <p>Current Average:<input type=text name="input_B"></p> <p>Percentage of:<input type=text name="input_C"></p> <p>Your ball speed is: (miles per hour) <input name="Answer" type=text readonly> </p> <p> <input type="button" value="Calculate Handicap" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form)"> <input type="button" value="Clear" name="ClearButton" onClick="ClearForm(this.form)"> </p> </form> Any help would be greatly appreciated! I have two google maps loading on my page. The first loads with a body onload call the second when a button is clicked. After the button is clicked I get the error message "map is not defined". I have reviewed my code and I can not see where I have forgotten to define a var (if I am understanding the error messaage correctly - I assume that is the problem)". My code is: Code: <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html {height:250px} body {height:250px} #map_canvas {width:30%; height:250px;} #placemap_canvas {width:100%; height:250px;} </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true" /> </script> <script type="text/javascript"> function initialize() { var latlng = new google.maps.LatLng ( <?php include("dbconnect.php"); $result = mysql_query("SELECT * FROM countries WHERE Country='{$_SESSION['Country']}'"); while($row = mysql_fetch_array($result)){ echo $row['Map']; } mysql_close($con); ?>); var myOptions = { zoom: 4, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } </script> //Here starts the code for the second map called by a button click <script type="text/javascript"> var geocoder; var submap; function createGMapFromAddress(){ geocoder = new google.maps.Geocoder(); var sublatlng = new google.maps.LatLng(0,0); var map_options = { zoom: 4, center: sublatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var submap = new google.maps.Map(document.getElementById("placemap_canvas"), map_options); } function codeAddress(location){ alert(location); var address = location; alert(address); geocoder.geocode({address: address}, function(results, status){ if (status == google.maps.GeocoderStatus.OK && results.length){ if (status != google.maps.GeocoderStatus.ZERO_RESULTS){ map.set_center(results[0].geometry.location); } } else { alert("Geocode was unsuccessful due to: " + status); } }); } </script> I was playing around with JavaScript today, just seeing if I could make image rollovers. I successfully switched out the first image, but I couldn't get it switched out with the original. My code: Code: window.onload = initAll; function initAll() { // var nav = document.getElementById("navigation"); var patt = /^http:\/\/www\.[a-z\/\.-]+\.jpe?g$/i; for (var i = 0; i < document.images.length; i++) { if (patt.test(document.images[i].src)) { document.images[i].onmouseover = switchy; var newbySrc = document.images[i].src; document.images[i].onmouseout = function() { UNswitchy(newbySrc); } } } } function switchy() { var newbert = new Image(); // the image below is the same one for every image, as I'm just testing newbert.src = "http://www.hogwarts-rpg.net/images/buttons/home.jpg"; this.src = newbert.src; } function UNswitchy(myImgSrc) { var newBern = new Image(); newBern.src = myImgSrc; this.src = newBern.src; } Since taking the mouse off the image wouldn't switch it back, I guessed that the UNswitchy() function was messing up. So, I commented out the code in there and added alert(), and alert() told me that this.src (in UNswitchy()) was undefined. Why would it be, since it worked fine in switchy()? Hi, I'm not sure did I post this to the right area, but here's my problem... Let's make this simple, I am totally newbie in coding. I installed a lightbox patch to FCKeditor, and I tried to modify it a bit so I could add a title into it. I kind of managed but... Here's the html code which I added to the html file: Code: <div> <br /> <input id="txtTitleLightBox" style="width: 100%" type="text" /> </div> And these are the modified codes which I added to the js file: Code: var rel = oLink.rel; if (rel) { var type; if (rel.indexOf("[") > 0) type = rel.substring(0,rel.indexOf("[")); else type = rel; var oE = GetE('rad'+type); if (oE) { GetE('txtTitleLightBox').value= title; GetE('txtGroupLightBox').value= rel.substring(rel.indexOf("[")+1, rel.indexOf("]")); GetE('chkLightBox').checked = true; GetE('rad'+type).checked = true; } } Code: if (GetE('chkLightBox').checked && oLink) { var rel = "lightbox" var rad = document.getElementsByName('radLightBoxType') for (var i=0; i < rad.length; i++) { if (rad[i].checked) { rel = rad[i].value; break; } } oLink.title = title var title = GetE('txtTitleLightBox').value = title; oLink.rel = rel var group = GetE('txtGroupLightBox').value if (group) { oLink.rel += "[" + group + "]" } } And what I added as new code were Code: oLink.title = title var title = GetE('txtTitleLightBox').value = title; and Code: GetE('txtTitleLightBox').value= title; The result is (eg) this kind of html text: Code: <a title="undefined" rel="lightbox" href="image/path"><img width="200" height="113" alt="" src="image/path" /></a> So the title is undefined even if I fill something to the txtTitleJavaScript box... If you want to investigate the full files, they are he http://jump.fm/IYOXH .. thanks :s i am getting an error according to firebug of 'id_con is undefined'.i have made sure all entries are correct and i cannot see how to fix this error. i would be grateful if someone could show me how to correct this error. the error is occuring on this line: Code: itemlist+= items[i].id_con.substr(3)+","; Code: <script src="js/jquery.js"></script> <script src="js/flexigrid.js"></script> <link rel="stylesheet" href="css/flexigrid/flexigrid.css" type="text/css" /> <script type="text/javascript"> $(function() { $("#flex1").flexigrid( { url: 'staff.php', dataType: 'json', colModel : [ {display: 'ID', name : 'id_con', width : 40, sortable : true, align: 'left'}, {display: 'Name', name : 'name_con', width : 150, edit: true, sortable : true, align: 'left'}, {display: 'Email', name : 'email_con', width : 150, sortable : true, align: 'left'}, {display: 'Phone', name : 'phone_con', width : 250, sortable : true, align: 'left'}, {display: 'Mobile', name : 'mobile_con', width : 150, sortable : true, align: 'left'}, {display: 'Fax', name : 'fax_con', width : 150, sortable : true, align: 'left'}, {display: 'Notes', name : 'notes_con', width : 250, sortable : true, align: 'left'} ], buttons : [ {name: 'Add', bclass: 'edit', onpress : test}, {separator: true}, {name: 'Edit', bclass: 'edit', onpress : test}, {separator: true}, {name: 'Delete', bclass: 'delete', onpress : test}, {separator: true} ], searchitems : [ {display: 'Name', name : 'name_con', isdefault: true}, {display: 'Email', name : 'email_con'} ], sortname: "id_con", sortorder: "asc", usepager: true, title: "Staff", useRp: true, rp: 10, showTableToggleBtn: false, resizable: false, autowidth: true, autoheight: true, singleSelect: true } ); }); function test(com,grid) { if($('.trSelected',grid).length>0){ if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')){ var items = $('.trSelected',grid); var itemlist =''; for(i=0;i<items.length;i++){ itemlist+= items[i].id_con.substr(3)+","; } $.ajax({ type: "POST", dataType: "json", url: "delete1.php", data: "items="+itemlist, success: function(data){ alert("Query: "+data.query+" - Total affected rows: "+data.total); $("#flex1").flexReload(); } }); } else if (com=='Add') { alert('Add New Item'); } else if (com=='Edit') { alert('Edit Item'); } } $('b.top').click ( function () { $(this).parent().toggleClass('fh'); } ); } </script> I am trying to read data from excel file and use the same to populate a select menu. If any cells are blank, I want to ignore. But I am unable to do this. The dropdown gets populated with blanks. Following is the peice of code: var excel_cell = excel_file.ActiveSheet.Cells(i,1); alert(excel_cell); if(excel_cell=='undefined') ; else document.forms.form1.Products.add(new Option(excel_cell,excel_cell)); I am unable to check for undefined. How do I handle this ?? Hi, so I have this function: Code: function centerZoom() { var bounds = new google.maps.LatLngBounds(); for (var i = 0; i < gmarkers.length; i++) { if (!gmarkers[i].isHidden()) { var point = gmarkers[i].getPoint(); bounds.extend(point); } map.setZoom(map.getBoundsZoomLevel(bounds)); map.setCenter(bounds.getCenter()); } } which I call he Code: for (var j = 0; j < gmarkers.length; j++) { var str=gmarkers[j].myname.toLowerCase(); var patt1=inp; if (str.match(patt1)) { found = true; gmarkers[j].show(); centerZoom(); } which I thought was pretty straightforward, but I keep getting a "centerZoom is undefined" message. The only place I don't get that is if I take it out of the initialize sequence, but it doesn't work then anyway (and from what I understand, being that it contains var bounds = new... it has to go in initialize. Here's the rest of the page, if anybody has any ideas Hello, I'm a JavaScript newbie and would welcome any assistance. I am getting the following error: inputField is undefined on line 19 of my js file. I have spent hours trying to figure out the problem and I am stuck. Thank you for your help!!! Here is my JavaScript code (followed by my HTML code): function validateRegEx(regex, input, helpText, helpMessage) { // See if the input data validates OK if (!regex.test(input)) { // The data is invalid, so set the help message and return false if (helpText != null) helpText.innerHTML = helpMessage; return false; } else { // The data is OK, so clear the help message and return true if (helpText != null) helpText.innerHTML = ""; return true; } } function validateNonEmpty(inputField, helpText) { // See if the input value contains any text if (inputField.name.length == 0) { /*The data is invalid, so set the help message*/ if (helpText != null) helpText.innerHTML = "Please enter the missing information."; return false; } else { //The data is OK, so clear the help message if (helpText != null) helpText.innerHTML = ""; return true; } } function validateLength(minLength, maxLength, inputField, helpText) { // See if the input value contains at least minLength but no more than maxLength characters return validateRegEx(new RegExp("^.{" + minLength + "," + maxLength + "}$"), inputField.value, helpText, "Please enter a value " + minLength + " to " + maxLength + " characters in length."); } function validateZipCode(inputField, helpText) { // First see if the input value contains data if (!validateNonEmpty(inputField, helpText)) return false; // Then see if the input value is a ZIP code return validateRegEx(/^\d{5}$/, inputField.value, helpText, "Please enter a 5-digit ZIP code."); } function validateDate(inputField, helpText) { // First see if the input value contains data if (!validateNonEmpty(inputField, helpText)) return false; // Then see if the input value is a date return validateRegEx(/^\d{2}\/\d{2}\/(\d{2}|\d{4})$/, inputField.value, helpText, "Please enter your date of birth (for example, 05/13/1959)."); } function validatePhone(inputField, helpText) { // First see if the input value contains data if (!validateNonEmpty(inputField, helpText)) return false; // Then see if the input value is a phone number return validateRegEx(/^\d{3}-\d{3}-\d{4}$/, inputField.value, helpText, "Please enter a phone number (for example, 123-456-7890)."); } function validateEmail(inputField, helpText) { // First see if the input value contains data if (!validateNonEmpty(inputField, helpText)) return false; // Then see if the input value is an email address return validateRegEx(/^[\w\.-_\+]+@[\w-]+(\.\w{2,3})+$/, inputField.value, helpText, "Please enter an email address (for example, johndoe@acme.com)."); } function placeOrder(form) { if (validateLength(1, 20, form["instrument"], form["instrument_help"]) && validateNonEmpty(form["name"], form["name_help"]) && validateNonEmpty(form["address"], form["address_help"]) && validateNonEmpty(form["city"], form["city_help"]) && validateNonEmpty(form["state"], form["state_help"]) && validateZipCode(form["zipcode"], form["zipcode_help"]) && validatePhone(form["phone"], form["phone_help"]) && validateEmail(form["email"], form["email_help"]) && validateDate(form["date"], form["date_help"]) && validateNonEmpty(form["user"], form["user_help"]) && validateNonEmpty(form["pass"], form["pass_help"])) { // Submit the information to the server form.submit(); } else { alert("I'm sorry but it appears you skipped something."); } } Here is my html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Offbeat Customer Information</title> <meta name="description" content="Offbeat Music Store selling all things musical" /> <meta name="keywords" content="music, musician, instruments, musician's accessories, music, customer information, subscriptions, sales" /> <link rel="stylesheet" href="labs.css" type="text/css"/> <script type="text/javascript" src="mod7.js"></script> </head> <body onload="document.getElementById('instrument').focus()"> <div class="topbanner" align="center"> <img id="logo" src="images/offbeatlogo.png" alt="OffBeat Music Store" width="50%" height="50%" /> </div> <div id="leftcolumn"> <div class="nav"> <ul> <li><a href="mod1.html">iRock</a></li> <li><a href="mod2dq.html">Mod 2 DQ</a></li> <li><a href="mod2.html">Order Form</a></li> <li><a href="index.html">Home</a></li> <li><a href="mod4.html">SFA</a></li> <li><a href="mod5.html">Vendor Showcase!</a></li> <li><a href="mod6.html">Vendor Showcase Redux</a></li> <li><a href="mod7.html">New Customer Account Form</a></li> <li><a href="mod8.html">Mod 8</a></li> <li><a href="mod9.html">Mod 9</a></li> <li><a href="mod10.html">Mod 10</a></li> <li><a href="mod11.html">Mod 11</a></li> <li><a href="mod12.html">Mod 12</a></li> <li><a href="mod13.html">Mod 13</a></li> <li><a href="mod14.html">Mod 14</a></li> </ul><br /></div></div> <div id="rightcolumn"> <br /> <p>Join the OffBeat family and keep up to date on all of our product offerings and sales by completing this form. You'll also receive a special coupon for your birthday!</p><br /> <form name="form" action="offbeatinfo.htm" method="POST" id="form"> <div class="formfield"> What instrument do you play/are you interested in?: <input id="instrument" name="instrument" type="text" size="20" onblur="validateLength(1, 20, this, document.getElementById('instrument_help'))" /> <span id="instrument_help" class="help"></span> </div><br /><br /> <div class="formfield"> Name: <input id="name" name="name" type="text" size="32" onblur="validateNonEmpty(this, document.getElementById('name_help'))" /> <span id="name_help" class="help"></span> </div><br /><br /> <div class="formfield"> Street address: <input id="address" name="address" type="text" size="36" onblur="validateNonEmpty(this, document.getElementById('address_help'))" /> <span id="address_help" class="help"></span> </div><br /><br /> <div class="formfield"> City: <input id="city" name="city" type="text" size="36" onblur="validateNonEmpty(this, document.getElementById('city_help'))" /> <span id="city_help" class="help"></span> </div><br /><br /> <div class="formfield"> State: <input id="state" name="state" type="text" size="2" onblur="validateNonEmpty(this, document.getElementById('state_help'))" /> <span id="state_help" class="help"></span> </div><br /><br /> <div class="formfield"> ZIP Code: <input id="zipcode" name="zipcode" type="text" size="5" onblur="validateZipCode(this, document.getElementById('zipcode_help'))" /> <span id="zipcode_help" class="help"></span> </div><br /><br /> <div class="formfield"> Phone number: <input id="phone" name="phone" type="text" size="12" onblur="validatePhone(this, document.getElementById('phone_help'))" /> <span id="phone_help" class="help"></span> </div><br /><br /> <div class="formfield"> Email address: <input id="email" name="email" type="text" size="32" onblur="validateEmail(this, document.getElementById('email_help'))" /> <span id="email_help" class="help"></span> </div><br /><br /> <div class="formfield"> Your month and date of birth (MM/DD/YYYY): <input id="date" name="date" type="text" size="10" onblur="validateDate(this, document.getElementById('date_help'))" /> <span id="date_help" class="help"></span> </div><br /><br /> <div class="formfield"> Enter a User Name: <input id="user" name="user" type="text" size="12" onblur="validateNonEmpty(this, document.getElementById('user_help'))" /> <span id="user_help" class="help"></span> </div><br /><br /> <div class="formfield"> Enter your password (4 to 7 letters and/or numbers): <input id="pw" name="pw" type="text" size="7" onblur="validateNonEmpty(this, document.getElementById('pass_help'))" /> <span id="pass_help" class="help"></span> </div><br /><br /> <input type="button" value="Save" onClick="placeOrder(this.form);" /> </form> <div id="footer" align="center"> <br /><br /> <a href="mod1.html" title="iRock">iRock</a> <a href="mod2dq.html" title="Mod 2 DQ">Mod 2 DQ</a> <a href="mod2.html" title="Order Form">Order Form</a> <a href="index.html" title="Home">Home</a> <a href="mod4.html" title="SFA">SFA</a> <a href="mod5.html" title="Vendor Showcase!">Vendor Showcase!</a> <a href="mod6.html" title="Vendor Showcase Redux">Vendor Showcase Redux</a> <br /> <a href="mod7.html" title="New Customer Account Form">New Customer Account Form</a> <a href="mod8.html" title="Mod 8">Mod 8</a> <a href="mod9.html" title="Mod 9">Mod 9</a> <a href="mod10.html" title="Mod 10">Mod 10</a> <a href="mod11.html" title="Mod 11">Mod 11</a> <a href="mod12.html" title="Mod 12">Mod 12</a> <a href="mod13.html" title="Mod 13">Mod 13</a> <a href="mod14.html" title="Mod 14">Mod 14</a> <br /><br /> <p align="center">Copyright © 2010 WEB 200 Labs Last updated: February 2010<br /> <a href="mailto:SunnyOne99@hotmail.com">Sue Raymond @SunnyOne99@hotmail.com</a></p> <p> <a href="http://validator.w3.org/check?uri=referer"><img style="border:0" src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a> <a href="http://jigsaw.w3.org/css-validator/check/referer"> <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a> </p> </div></div> </body> </html> I've been working through a tutorial on OOP in javascript. Upon keyup, the code below gives this error: Quote: charCounterObj[x] is undefined This is my first attempt at anything like this, so apologies for what are no doubt egregious and fundamental misunderstnadings about how to implement something like this. I've stripped away everything that's irrelevant, but there's still quite a bit of code here. I'm hoping this isn't too much wade through, but perhaps someone would be kind enough to give it the once-over. There may be something obvious that jumps out to the seasoned eye... Code: //CharCounter Class function charCounterClass(formType) { //Properties this.counter = $('#'+formType+'_commentsCounter'); this.textarea = $('#'+formType+'_comment'); this.maxlength = $('#'+formType+'_commentMaxlength').text(); this.textLen = this.textarea.val().length; //Methods this.cch = function() { $(this.counter).val(this.textLen); //... } } var charCounterObj = []; var charCounter = []; var x = 0; $("input.charCounter").each(function() { charCounter[x] = $(this).val(); if (charCounter[x] == true) { charCounterObj[x] = new charCounterClass(formType[x]); $('#'+formType[x]+'_comment').keyup(function() { charCounterObj[x].cch(); }); } x++; }); Thanks for any input. New to javascript, so I'm trying to work through a rather older, but helpful nonetheless book entitled "Head Rush Ajax". I'm only finishing up the first chapter...lol and my code is not doing what its supposed to be doing. I'm sure its something simple like a typo, but I have been over it several times and cant spot the problem. When I try to run the script in IE8, it throws an error saying object expected. line 43 code 0 Here is my complete script. According to the book I should be able to click the button and the values will update only once. PHP Code: var request = null; function createRequest() { try { request = new XMLHttpRequest(); } catch (trymicrosoft) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { request = null; } } } if (request == null) alert("Error creating request object!"); } function getBoardsSold() { createRequest(); var url="getUpdatedBoardSales-ajax.php"; request.open("GET", url, true); request.onreadystatechange = updatePage; request.send(null); } function updatePage() { if (request.readyState == 4) { var newTotal = request.responseText; var boardsSoldEl = document.getElementById("boards-sold"); var cashEl = document.getElementById("cash"); replaceText(boardsSoldEl, newTotal); // Figure out how much cash katie has made var priceEl = document.getElementById("price"); var price = getText(priceEl); var costEl = document.getElementById("cost"); var cost = getText(costEl); var cashPerBoard = price - cost; var cash = cashPerBoard * newTotal; //update the cash for the slopes on the form cash = Math.round(cash * 100) / 100; replaceText(cashEl, cash); } } Thanks for any help in advance! When I try to assign an object to an array I get the error: Uncaught TypeError: Cannot set property '0' of undefined The array is defined as: Code: var animation_JD = [[]]; Here i try to assign an object (was working fine with single dimension array) Code: animation_JD[group][animationID] = (animation); More code if people would like it: Code: var group = params.group || "default"; var animationID = getNextID_animator_JD(group); animation = new Object(); animation.repeat = params.repeat || "1"; animation.wait = params.wait || "never"; animation.currentStage = 0; animation.currentFrame = 0; animation.active = false; animation.running = false; animation_JD[group][animationID] = (animation); return animationID; getting undefined alert. Why? Code: <script> function openFile(f){ alert(f); } </script> File Location: <a onclick="openFile(this.value)"; > Click to view File</a> <BR> <textarea name = "fileLoc">TEST VALUE</textarea> I am using a checkbox to turn on and off some labels on a line on a google map, which is working fine if the line is already drawn, using this function: Code: function distboxclick(labelsbox) { if (labelsbox.checked) { for (var i=0; i<distmarkers.length; i++) { if (distmarkers[i].mLabel != null) distmarkers[i].mLabel.show(); } } else { for (var i=0; i<distmarkers.length; i++) { if (distmarkers[i].mLabel != null) distmarkers[i].mLabel.hide(); } } } but the thing is that I want the labels to be turned off to begin with and switched on if the box is checked. Which is also fine, using this snippet: Code: if (prevMarker){ var dist = getSegmentDistance(prevMarker.mMarker, distmarker); var label = new ELabel(point, dist, "labelstyle", new GSize(10,-15)); distmarkers[numMarkers-1].mLabel = label; distlabels.push(label); map.addOverlay(label); label.hide(); drawOverlay(); } but what I am trying to do now is make sure that if the box is checked before the line starts to be drawn then the labels will come up straight away. So I figured all I had to do was add in the following to the above: Code: if (labelsbox.checked){ label.show(); } else { label.hide(); } and pass the labelsbox variable to the function where that is all happening. But instead I get a "labelsbox is undefined" error... If I take that if statement out I see that labelsbox is defined, but that doesn't really help. I guess I'm putting things in the wrong order or something, but I'm kind of baffled. You can see my test page here. Thanks in advance for any suggestions. I am transferring my pages to using templates and it works well. I now came to a page where I play a sound when the mouse is over the picture and stops when it leaves. I added two items to the 'pix' array to include this and did the same way as I've done before but now when the mouse enters a picture I get errors "'mouseOver' is undefined" and "'mouseOut' is undefined". Can anyone spot the error? test.php Code: <h1>PICTURE TEST</h1> <div id="contents"></div> <script> var pix = [ {figu "figure", picfile:"bp/p01.jpg", alternative: "pic1", caption: "Picture 1", mouseOver: "sJoid.play();", mouseOut: "sJoid.stop();"} ]; $.get("/tmpl/_test.tmpl.htm", function(templates) { $("#contents").empty(); $("#contents").append(templates); $("#testTemplate").tmpl(pix).appendTo("#contents"); }); </script> _test.tmpl.htm Code: <script id="testTemplate" type="x-jquery-tmpl"> <img src="/pics/${picfile}" alt="${alternative}" onmouseover="$(mouseOver)" onmouseout="$(mouseOut)" /> </script> |