JavaScript - Inputfield Is Undefined
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> Similar TutorialsOK, I am a newbe I am backfilling for a coworker. They are auto generating a page pulling from a database. It is creating something like this: Code: <td colspan='2' class='normal' nowrap><input type='checkbox' name='Network/Other Equipment[1]' checked><b> Data Cabinet - 7ft - 0113</td></tr> <td colspan='2' class='normal' nowrap><input type='checkbox' name='Network/Other Equipment[2]' checked><b> Data Cabinet - 5ft -0463</td></tr> <td colspan='2' class='normal' nowrap><input type='checkbox' name='Network/Other Equipment[3]' > Router</td></tr> I am trying to pull the values out. I have been trying Code: <tr><td><input type='button' class='button' name='Calculate' value='Calculate' onclick="testIt(this.form)"></td></tr> Code: <script language='javascript'> function testIt(formname) { alert(frm.Satellite Equipment[1].value); } </script> Not working. How can I grab the value from something like this: name='Network/Other Equipment[1]' ? Also, Are the checkboxes automatically put into an array? thanks 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()? 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 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 ?? 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; Hi, Ihave this html/jscript hybrid and when i run it in firefox the error console says a value is undefined when i click it the very first <html> is highlighted???? any one no why? 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! 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 build a status string for all the checkboxes on a form. If the checkbox is checked add 127 to the string else add 0 to the string. All works fine until i have just 1 checkbox on the form. I then get an undefined error from alert(checkBoxes.length); Any ideas ? Code: HTML <form name="myform" method="POST" action="" onsubmit="return checkTheBox();"> <ul> <li> <input type="checkbox" name="col_box[]" /> </li> <li> <input type="checkbox" name="col_box[]" /> </li> </ul> <input type="submit" value="Submit Form" /> </form> JAVASCRIPT <script type = "text/javascript"> function checkTheBox() { var checkbox_status =""; var checkBoxes = document.myform.elements['col_box[]']; alert(checkBoxes.length); for (i = 0; i < checkBoxes.length; i++){ if(document.myform["col_box[]"][i].checked){ checkbox_status = checkbox_status + "127,"; } else { checkbox_status = checkbox_status + "0,"; } } alert (checkbox_status); } </script> 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 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> 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'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. 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. 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 Hi, I'm new to javascript and have a small but annoying problem with an array. The script rotates a randomly selected banner from an array and changes the banner every few seconds. The problem is that when the page is first loaded the word 'undefined' displays next to the first banner. When the second banner is displayed everything works fine. Here is the function I am using Code: function randomBanner() { var myBanners=new Array(3); var i = Math.floor(Math.random() * 3); myBanners[0]="image 1"; myBanners[1]="image 2"; myBanners[2]="image 3"; document.getElementById('banners').innerHTML = myBanners[i]; setTimeout("randomBanner()",5000 ); } and here is the html Code: <head> <script type="text/javascript" src="rotator.js"></script> </head> <body> <div id="banners"> <script type="text/javascript">document.write(randomBanner());</script> </div> </body> I have tried declaring the variables and even the array itself outside the function to no avail. I have set up a test page so you can view the problem here Please can someone help? In order to better understand the DOM data structure, I am trying to write a JavaScript that will produce something like HTML from the DOM data structure. My current problem is that when I include a <br> tag in my source HTML, it reports that its parent is undefined, and this is breaking my code. So, given the following code, why does the <br> tag report that it's parent is undefined. Code: <html> <head> <title>br.parent</title> <script type="text/javascript"> function brTest() { var jBR = document.getElementsByTagName("br")[0]; alert("<br>.nodeType = " + jBR.nodeType + "\n<br>.nodeName = " + jBR.nodeName + "\n<br>.ParentNode = " + jBR.ParentNode); } </script> </head> <body onload = "brTest();"> <p>Now is <br> the time.</p> </body> </html> Thanks for any help you can provide. Jerry Hi, I am having 1 JS file 'common.js', which has 2 functions: func1(); func2(); and 2 PHP files: file1 and file2. I am calling func1() from file1 (<html><body onload="javascript:func1()"...) and initializing some global variables in func1. Then i am calling func2() from file2 and reading those variables, but those i am getting undefined. Is it because the variables were initialized in a function which was called by some file, that i am not able to access in a function called by another file, like a scope problem? I thought since both the functions are in same file, the global variables in that file are accessible to all functions in that file. Please help! Thanks! ok im having a bit of problem with this. code : <input type="hidden" value="&nsbp;" name="b1r1c1"> (insde a table} <td></script>function ba1r1c1() { document.write(b1r1c1.value); }</script></td> (later on) <script> ba1r1c1(); </script> Whats happening is its not writing the space inside the cell but somewhere else on the page but i dont know why. The table is inside <div> tags if that helps. any help apreciated. Thanks 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> |