JavaScript - Function Placement Causing Error
hello
i am trying to include the following following in my code, but it keeps creating an error. i need to know the correct place to include the function.many thanks Code: CODE ---------------------------------------- <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, 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: 'Edit', bclass: 'edit', onpress : doCommand}, {name: 'Delete', bclass: 'delete', onpress : doCommand}, {separator: true} ], searchitems : [ {display: 'Name', name : 'name_con'}, {display: 'Email', name : 'email_con', isdefault: true}, {display: 'Position', name : 'position'} ], sortname: "name_con", sortorder: "asc", usepager: true, title: "Staff", useRp: true, rp: 10, showTableToggleBtn: false, resizable: false, autowidth: true, autoheight: true, singleSelect: true } ); }); FUNCTION ----------------------------------------------------------- function doCommand(com, grid) { if (com == 'Edit') { $('.trSelected', grid).each(function() { var id_con = $(this).attr('id_con'); id_con = id_con.substring(id_con.lastIndexOf('row')+3); alert("Edit row " + id_con); }); } else if (com == 'Delete') { $('.trSelected', grid).each(function() { var id_con = $(this).attr('id_con'); id_con = id_con.substring(id_con.lastIndexOf('row')+3); alert("Delete row " + id_con); Similar TutorialsI've been writing calculators with Javascript for over ten years and using the "to.Exponential" function for formatting and rounding. Recently, it is causing a problem for me. Here is a very shortened version of a calculator on which I am working: http://www.1728.com/count.htm This works fine for the first time it is activated but it doesn't work for the second (or any number of additional) times. (Keep clicking "calculate" and you'll see what I mean.) I didn't want to link to the original calculator (because of its size) but the "to.Exponential" function causes yet another problem in that one. When the count ('ct') is equal to five or six, the program stops working. Any help with this would be greatly appreciated. Hello there, I am using Dynamic Drive's dhtml windowfile and when I had a link for it to call the popup window, it makes my site deliver a 500 server error. Here is the line of code I'm adding: Code: echo '<td><a class="link" href="#" onClick="ajaxwin=dhtmlwindow.open('ajaxbox', 'ajax', 'pages/post.php', 'Composing Mode: Post', 'width=650px,height=400px,left=300px,top=100px,resize=0,scrolling=1'); return false">Compose</a></td>'; It is not a php issue, I plaintext the link and it still did the same thing. The suspect line is the following $('.leaveClan').attr('id') = <?php echo $id; ?>; the span with the class (there is only one) leaveClan is on the main page, and that line of javascript is on a page being called by AJAX within that page. Can anyone see why that is causing an error? Let me know if you need to see any more of the code i keep getting error Call to undefined function codeandurl() below is my code PHP Code: <?php $value= strip_tags(get_field('link',$post)); $resultid=get_field('resultid',$post); codeandurl($resultid,$value); ?> <div id="result"></div> <script type="text/javascript"> function codeandurl(resultid,url){ $( "#result" ).text(resultid); $( "#result" ).dialog({ modal: true, buttons: { Ok: function() { $( this ).dialog( "close" ); } } }); window.open(url); return false; } </script> I'm trying to "progressively enhance" one of my surveys using javascript. Basically, I have rating scales that make use of radio buttons as each point on the scale. Each radio button occupies its own cell in a table. I wrote some functions that will highlight cells on mouseover in a color corresponding to its position on the scale (e.g. the lowest point is red, the midpoint is yellow, the highest point is green). When a radio button is clicked, the background of the button's cell and preceding cells in the same row will be colored accordingly. The functions are working well in FireFox and Chrome (I just have to add a few lines using the addEvent function to make it compatible with IE). The effect looks a lot nicer when I add a function that makes the visibility of the radio buttons hidden. However, I want to make sure that there is a fallback option in case the functions that color the cells don't work for whatever reason. I would not want the radio buttons hidden in this case. Is there a method whereby I can call the "hideRadiobuttons" function only if the other functions are successfully executed? Code: <html> <head> <script> function changeBgColor(){ document.getElementById("bgc").style.background-color=333333; } </script> <style> #bgc{ width:300px; height:100px; background-color:#cccccc; } </style> </head> <body> <p id="bgc" onmouseover="changeBgColor()"> Hi There, pls change bg color </p> </body> </html> I am getting following error "SCRIPT5007: The value of the property 'changeBgColor' is null or undefined, not a Function object eventTest1.html, line 22 character 29" This is a simple code, why am I getting such a weird error. Whats wrong in here ? Thanks Can you guys please tell me why the link() function isnt working. Code: <html> <head> <script type ="text/JavaScript"> var counter = 0; var counter2 = 0; var arraynumb = 0; var arraynumb2 = 0; var global; var array = ['Mohamad', 'Karim', 'Anthony', 'Rami', 'Natalia', 'Sarah', 'Samer', 'Violette', 'Plume', 'Sharshabil']; var array2 = ["1000", "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009"]; var searchKey = document.searchform.inputVal.value; var searchKey2 = document.searchform.inputVal2.value; var searchKey3 = document.searchform.inputVal.value; function pass(){ searchKey = document.searchform.inputVal.value; for (var i = 0, len = array.length; i < len; i++){ if (array[i] == searchKey){ counter = 1; arraynumb = i; } } } function pass1(){ searchKey2 = document.searchform.inputVal2.value; for (var i = 0, len = array2.length; i < len; i++){ if (array2[i] == searchKey2){ counter2 = 1; arraynumb2 = i; } } } function access() { if (counter == 1 && counter2 == 1 && arraynumb == arraynumb2) { window.alert("You may access the website"); window.alert(array[0]); global = 1; } else{ window.alert("You may not access the website"); global = 0; } } function link() { if (global == 1 && array[0] == searchkey3 ) { window.alert("You are an administrator, you may use all the ciphers"); } else window.alert("you are not signed in, please do so"); } </script> </head> <body> <form name = "searchform" action = ""> <p>Enter username<br/> <input name = "inputVal" type = "text" size = "30"/> <input name = "search2" type = "button" value = "Search" onclick = "pass()"/> </p> <p>Enter password<br/> <input name = "inputVal2" type = "password" size = "30"/> <input name = "search" type = "button" value = "Search" onclick = "pass1()"/> <input name = "Access site" type = "button" value = "Access" onclick = "access()"/> <br/> <br/> <input name = "linkto" type = "button" value = "Shift" onclick = "link();"/> <br/> </p> <br/> <p></p> </form> </body> </html> why does my javascript function run right away when the page loads? but not wen the button is clicked? its working the opposite to how i want it to i didnt include the other html tags to help focus on this. Btw im tryna avoid the method of having the onclick="funct()" method which would be written in the button tag. Thank you. <body> <button id="mybutton">Click me</button> </body> <script type = "text/javascript"> var b = document.getElementById("mybutton"); b.onclick = funct() function funct() { alert("Thanks for clicking me!"); } </script> My isNumber function below gives 'event is not defined' error when I press the home key or the tab key - how can I fix that? Thanks PHP Code: function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode // 86 == ctrl-v // 36 == shift home to select entire field // 46 delete // 35 end // 36 home // 67 ctrl-c // 40 down key //alert(charCode); if ( (charCode == 35 || charCode == 40 || charCode == 86 || charCode == 46 || charCode == 67 || charCode == 36 || charCode == 8 || charCode == 9 || charCode == 32) || (charCode >= 48 && charCode <= 57) ) { return true; } return false; For some reason in IE this script Code: <script type="text/javascript"> //<![CDATA[ function SelectDisplayDiv(pointer){var divs = document.getElementsByClassName('hiddenDiv');for(var i =0; i < divs.length; ++i){divs[i].style.display = "none";} document.getElementById(pointer).style.display = 'block';}//]]> </script> is saying "Object doesn't support this method or property" But this script Code: function SelectDisplayDiv(pointer){var divs = document.getElementsByClassName('hiddenDiv');for(var i =0; i < divs.length; ++i){divs[i].style.display = "none";} document.getElementById(pointer).style.display = 'block';} *almost the exact same thing, just not written to the canvas by code, hard coded rather- does not. What does that error mean? Is this an IE thing? Hi, The Problem I get a error message only in IE when ever I try to call a function from an external file. I am using jQuery if that makes any difference and various plugins. Quote: Error: The value of the property '<function name>' is null or undefined, not a Function object. All the call work fine in FF, chrome, safari etc but for some reason I just can't get it to work with IE. This is getting annoying now, i have no idea what is causing it. here is an example: admin.js Code: function create_cleditor_admin_form(textarea_object) { $(textarea_object).cleditor({ height: 120, controls: // controls to add to the toolbar "bold italic underline | color highlight removeformat | bullets numbering | alignleft center alignright justify | undo redo | ", useCSS: false }); } calling code Code: $(document).ready(function() { try { create_cleditor_admin_form('textarea'); } catch(e) { alert("Error: "+e.message); } }); I have tried searching for this error on google and came up empty handed, surely it just something very stupid. Thanks in advance hi guys, im not very good with javascript/jquery, i have the following code: Code: <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(window).ready(function() { $("#responsecontainer").load("includes/inc-mess-jail.php", function(response, status, xhr) { }); var refreshId = setInterval(function() { $("#responsecontainer").load('includes/inc-mess-jail.php?randval='+ Math.random()); }, 9000); $.ajaxSetup({ cache: false }); }); </script> it basically updates the div tag: Code: <tr> <td colspan="2"> <div id="responsecontainer" align="center"></div> </td> </tr> i wanted to add an error message to it, that comes up underneath the <div id="responsecontainer" align="center"></div> that says "Error" with an id number next to it, then when your mouse goes over it a box comes out saying "there was a problem retrieving your information. the game will continue trying to resolve this" and then underneath where it says error i would like it to say the number of attempts it has tried to recollect the information. obviously i would only like this error message to come up, when it cannot refresh the information. Any help would be great, even pointing me in the right direction Eagle eyes needed! I have a function which is called twice. It allows the elements of an array to be set to a different color, successively: Code: function ln8 (arrayA,color,current) { var arrayB=(typeof arrayA == 'string')? arrayA.split(',') : arrayA; var line = document.getElementById(arrayB[current]); line.style.color = color; if (current != arrayB.length - 1) { current++; setTimeout(function() {ln8(arrayB, color, current)},8) } } It works fine the first call; the second time, FF throws an error message: 'line is null' referring to 'line.style.color = color;'. It's used in a switch function, and I've tested each case of the switch, two browsers, and still get the error. So I'm assuming the second call is the problem, but I just can't see what's wrong with it. Maybe before you wade through the code, can you think of other reasons for the error? First call: the function is at the third line of each case: Code: function makeLine5() { var a = Coin1() var b = Coin2() var c = Coin3() var h = ( a + b + c ) A=a;B=b;C=c;D=h; switch(h) { case 6: noHex2(5,'D'); noHex(Hex5Yang,'hidden',0); nodot(5, 4, 'e'); setTimeout('report5()',3000); setTimeout('ln8(Line5Yin,\'#e11\',0)',6000); setTimeout('dot(5, 4, \'f\')',10000); return false; break case 7: noHex2(5,'D'); noHex(Hex5Yin,'hidden',0); setTimeout('report5()',3000); setTimeout('ln8(Line5Yang,\'#e11\',0)',6000); return false; break case 8: noHex2(5,'C'); noHex(Hex5Yang,'hidden',0); setTimeout('report5()',3000); setTimeout('ln8(Line5Yin,\'#e11\',0)',6000); return false; break default: noHex2(5,'C'); noHex(Hex5Yin,'hidden',0);nodot(5, 4, 'f'); setTimeout('report5()',3000); setTimeout('ln8(Line5Yang,\'#e11\',0)',6000); setTimeout('dot(5, 4, \'e\')',10000); return false; } } second call: Code: function makeLine6() { var a = Coin1() var b = Coin2() var c = Coin3() var k = ( a + b + c ) A=a;B=b;C=c;D=k; switch(k) { case 6: noHex2(6,'D'); noHex(Hex6Yang,'hidden',0);nodot(6, 5, 'e'); setTimeout('report6()',3000); setTimeout('ln8(Line6Yin,\'#e11\')',6000); setTimeout('dot(6, 5, \'f\')',10000); setTimeout('lastBitz()',13000); return false; break case 7: noHex2(6,'D'); noHex(Hex6Yin,'hidden',0); setTimeout('report6()',3000); setTimeout('ln8(Line6Yang,\'#e11\')',6000); setTimeout('lastBitz()',13000); return false; break case 8: noHex2(6,'C'); noHex(Hex6Yang,'hidden',0); setTimeout('report6()',3000); setTimeout('ln8(Line6Yin,\'#e11\')',6000); setTimeout('lastBitz()',13000); return false; break default: noHex2(6,'C'); noHex(Hex6Yin,'hidden',0);nodot(6, 5, 'f'); setTimeout('report6()',3000); setTimeout('ln8(Line6Yang,\'#e11\')',6000); setTimeout('dot(6, 5, \'e\')',10000); setTimeout('lastBitz()',13000); return false;} } Hi all, I have written the following javascript code which makes a simple calculation and writes between the <span> tags using Inner HTML My code is: Code: <html> <head> <script type="text/javascript"> function hesapla() { kredimiktari = document.hesapla.miktar.value kredivadesi = document.hesapla.vade.value; faiz = document.hesapla.faiz.value; ayliktaksit1 = (kredimiktari * faiz) / kredivadesi; geriodeme1 = kredimiktari * faiz; document.getElementById('ayliktaksit').innerHTML = "<strong>Taksit / Ay :</strong>" + ayliktaksit1; document.getElementById('geriodeme').innerHTML = "<strong>Taksit / Ay :</strong>" + geriodeme1; } </script> </head> <body> <form name="hesapla"> <input type="text" name="miktar" value="Kredi Miktarı" onfocus = "if (this.value == 'Kredi Miktarı') this.value = '';" onblur = "if (this.value == '') this.value = 'Kredi Miktarı';" /> <input type="text" name="vade" value="Kredi Vadesi" onfocus = "if (this.value == 'Kredi Vadesi') this.value = '';" onblur = "if (this.value == '') this.value = 'Kredi Vadesi';" /> <input type="text" name="faiz" value="Faiz Oranı" onfocus = "if (this.value == 'Faiz Oranı') this.value = '';" onblur = "if (this.value == '') this.value = 'Faiz Oranı';" /> <div id="gosterim"><span id="ayliktaksit"></span><span id="geriodeme"></span></div> <input type='button' value='Hesapla' onClick='hesapla()'><br><br> <img src="images/dot2.png" width="180" height="2" alt="dot"/> </form> </body> </html> I am really confused as similar code on Tizag web site works fine. Code: <script type="text/javascript"> function changeText(){ document.getElementById('boldStuff').innerHTML = 'Fred Flinstone'; } </script> <p>Welcome to the site <b id='boldStuff'>dude</b> </p> <input type='button' onclick='changeText()' value='Change Text'/> Could anyone tell me what the wrong thing is about my code Many thanks in advance telmessos Hi, I have a button that when you click it displays the results of my db in a div. What I am trying to do is to get the results to update every five seconds. I thought setTimeout was the best way to achieve this. However I am getting the error message that ID is not defined on the setTimeout line. I thought it would automatically input ID into the fields marked ID when the onloadXMLDocRefresh('File.php','txtHint') button is clicked? The button works to load the script, but the refreshing the div is not. My script is: Code: <script type="text/javascript"> function loadXMLDocRefresh(File,ID){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; timer = setTimeout('loadXMLDocRefresh(File,ID)',5000); } } xmlhttp.open("POST",File,true); xmlhttp.send(); } </script> İ want to use this code but when the page opens, I get a null reference error. When I open the page a second time, this error doesn't occur. I understand when the site caches, this error doesn't occur. The error comes from tb_show function. My code: <script type="text/javascript"> function writeCookie(CookieAdi) { var dtGun = 1 var strValue = "1" if (dtGun == null || dtGun == "") dtGun = 365; var d = new Date(); d.setTime(d.getTime() + (dtGun * 24 * 60 * 60 * 1000)); var zt = "; expires=" + d.toGMTString(); document.cookie = CookieAdi + "=" + strValue + zt + "; path=/"; } function readCookie(cookieadi) { var c = document.cookie; if (c.indexOf(cookieadi) != -1) { s1 = c.indexOf("=", c.indexOf(cookieadi)) + 1; s2 = c.indexOf(";", s1); if (s2 == -1) s2 = c.length; strValue = c.substring(s1, s2); return strValue; } } writeCookie('OnerFacebook'); if (readCookie('OnerFacebook') != 1) { tb_show('', 'http://www.mobilyala.com/OnerFacebook/?KeepThis=true&TB_iframe=true&height=500&width=300&modal=true', ''); } </script> What should I do for it? First post - spent the whole afternoon trying to figure it out and have hit a wall. I'm trying to check a database of lotto numbers against 3 different values and have gotten it that to work. What I need is to give a feedback message if no match is found once the submit button is clicked. Code: function winCheck() { var grandPrize = $('#grandPrize').val(); var otherPrize = $('#otherPrize').val(); var addPrize = $('#addPrize').val(); var resultrange = $('#resultrange').val(); db.transaction( function(transaction) { transaction.executeSql( 'SELECT * FROM entries WHERE daterange = ? ORDER BY lottonum;', [resultrange], function lottoCompare(transaction, result){ for (var i=0; i < result.rows.length; i++) { var row = result.rows.item(i); rowData = [row.lottonum]; rowStr = rowData.toString(); //the if else statements should go here. if (rowStr == grandPrize){ alert('The lotto number ' + grandPrize + ' is a jackpot winner'); } if (rowStr.slice(-7) == otherPrize.slice(-7)){ alert('The lotto number ' + rowStr + ' is a winner of $40,000'); } if (rowStr.slice(-6) == otherPrize.slice(-6)){ alert('The lotto number ' + rowStr + ' is a winner of $10,000'); } if (rowStr.slice(-5) == otherPrize.slice(-5)){ alert('The lotto number ' + rowStr + ' is a winner of $4,000'); } if (rowStr.slice(-4) == otherPrize.slice(-4)){ alert('The lotto number ' + rowStr + ' is a winner of $1,000'); } if (rowStr.slice(-3) == otherPrize.slice(-3)){ alert('The lotto number ' + rowStr + ' is a winner of $200'); } if (rowStr.slice(-3) == addPrize){ alert('The lotto number ' + rowStr + ' is a winner of $200'); } } }, errorHandler ); } ); return false; } Any help is appreciated I'm trying to pass titleArray and pointsArray to the task(); I'm getting an error mgs this.assignments() is not a function. I've highlighted this.assignments() Code: <html> <head> <title>Variable - Examples 1</title> <script type="text/javascript"> function Student(firstName, lastName, email, courseID, titleArray, pointsArray){ this.firstName = firstName; this.lastName = lastName; this.email = email; this.courseID = courseID; this.title = titleArray; this.points = pointsArray; this.assignments = task; this.totalPoints = addExam; this.finalGrade = calcGrade; } Student.prototype = { constructor : Student, toString : studentInfo }; var t = this.title; var p = this.points; function task(t, p){ var title = this.t; var points = this.p; var titlePoints = ""; for (var i=0; i < points.length; i++){ titlePoints += title[i] + " : " + points[i] + "<br>"; } return titlePoints; } function addExam(){ var assignments = [30, 30, 28, 27, 29]; var exams = [41,45]; var highOfTwo = Math.max(41,45); var sum = 0; for (var i=0; i < assignments.length; i++){ sum += assignments[i]; } return sum + highOfTwo; } var totalPoints = addExam(); function calcGrade(){ var grade; if (totalPoints >= 190){ return "A+"; }else if (totalPoints >= 180){ return "A"; }else if (totalPoints >= 175){ return "B+" }else if (totalPoints >= 170){ return "B"; }else if (totalPoints >= 165){ return "B-"; }else if (totalPoints >= 160){ return "C"; }else if (totalPoints >= 150){ return "D"; }else if (totalPoints < 150){ return "F"; } } function studentInfo(){ return "Student : " + this.lastName + "," + this.firstName + "<br>"+ "eMail : " + this.email + "<br>" + "Course ID : " + this.courseID + "<br>" + "--------------------------------" + "<br>" + this.assignments() + "--------------------------------" + "<br>" + "Total Points : " + this.totalPoints() + "<br>" + "Final Grade : " + this.finalGrade(); } var titleArray = ["Assignment1","Assignment2","Assignment3","Assignment4","Assignment5","MidTerm", "Final"]; var pointsArray = [30, 30, 28, 27, 29, 41, 45]; var student = new Student("FirstName", "Lastname", "myemail@gmail.com","COIN-070B.01", titleArray, pointsArray ); </script> </head> <body> <script type="text/javascript"> document.writeln(student.toString()); </script> </body> </html> Hi Coders, I have a javascript function which lets a user to choose one of the 7 option buttons on a "mainsub.asp" page and the page will then be forwarded to one of the 7 process pages depending on what has been chosen. The problem is that firefox is angry with the first line ("if" statement) and tells the following in its error console: Error: document.forms[0].C1 is not a function Source File: [localhost...] Line: 117 Here is the code: function fSubmit(){ if (document.forms[0].C1(0).checked) document.forms[0].action="process.asp"; else if (document.forms[0].C1(1).checked) document.forms[0].action="process1.asp"; else if (document.forms[0].C1(2).checked) document.forms[0].action="process2.asp"; else if (document.forms[0].C1(3).checked) document.forms[0].action="process3.asp"; else if (document.forms[0].C1(4).checked) document.forms[0].action="process4.asp"; else if (document.forms[0].C1(5).checked) document.forms[0].action="process5.asp"; else if (document.forms[0].C1(6).checked) document.forms[0].action="process6.asp"; else document.forms[0].action="process.asp"; return; } Internet explorer does not complain about anything and does its job great. But I could not figure out how to change the code to be also compliant with Firefox? Thanks for all the comments. |