JavaScript - Please Help Me Find The Bug In This Code
This is the script itself - no error messages are generated.
Code: <script language="javascript" type="text/javascript"> function getXMLHTTPRequest() { try { req = new XMLHTTPRequest(); } catch(err1) { try { req = new ActiveXObject("Msxm12.XMLHTTP"); } catch(err2) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(err3) { req = false; } } } return req; } var http = getXMLHTTPRequest(); function getCattle(animal_id){ var myurl = 'find_cattle.php'; var CattleValue=animal_id; var modurl= myurl+"?d="+CattleValue; **************the alert returns the correct value from my selection and after than nothing, I never get my alert from the response portion alert("Looking For "+modurl); ******* http.open("GET", modurl, true); http.onreadystatechange=useHttpResponse; http.send(null); } function useHttpResponse(){ ************It never gets to this response alert("Made It To Response"); if (http.readyState == 4) { if(http.status == 200) { var ListValue = http.responseXML.getElementsByTagName("animal_id")[0]; document.getElementsById('cattle_data').innerHTML = animal_id.childNodes[0].nodeValue; } } } </script> thank you Similar Tutorialshello i have a form which when the user hits "submit," the info in the textboxes is entered to a database. the only textbox which is not entered to the DB is an "age" textbox, which i need to verify to see if user is 18yrs or older. if user is not 18 years or older, they get an alert telling them they arent 18+. if they are, then the form submits this is my code so far, and i dont get any alerts when i enter an age younger than 18: Code: <head> <script language="text/javascript"> var age; document.getElementById("userage").value = age; if (age >=18) document.location="feedbacksaveanddisplay.php"; else { alert('Sorry, we can not let you in!') document.location="content.html"; } </script> </head> <form method = "post" action = "FeedbackSaveAndDisplay.php"> <input type = "hidden" name = "user" value = "test"/> <input type = "hidden" name = "pwd" value = "test"/> <p>Enter your name, feedback, score</p> <table> <tr> <td>Name</td> <td> <input type = "text" name = "name" style="width:150px; height:20px;" /> </td> </tr> <tr> <td>Feedback</td> <td> <input type = "text" name = "feedback" style="width:150px; height:20px;" /> </td> </tr> <tr> <td>Score</td> <td> <input type = "text" name = "score" style="width:150px; height:20px;" /> </td> </tr> <tr> <td>Product</td> <td> <input type = "text" name = "product" style="width:150px; height:20px;" /> </td> </tr> <tr> <td>Age</td> <td> <input type = "text" name = "age" style="width:150px; height:20px;" /> </td> </tr> <tr> <td colspan = "2"> <input type = "submit" value = "Submit" /> </td> </tr> </table> </form> any tips/advice on how to fix my code? the problem i think is in the javascript... will greatly appreciate any help thanks!! Hello: Many apologies if this is not an appropriate question here... but I have googled my fingers raw and haven't been able to find a script to do what I am looking for. I have little experience with JavaScript. I have a VBA script (code at the end of this post) that returns the date corresponding to a given occurrence of a given weekday, e.g. Ask it for the 3rd Tuesday in October 2012 and it gives you 16-OCT-2012. It defaults to current year if you don't pass the Year argument. It's a pretty simple script, but I need to either finds something in JavaScript that does the same thing, or convert the VBA code to JavaScript. I can't help but think that many people have already written scripts that do this. Any chance someone can lead me in a productive direction here? Regards, Steve Jones (update - I noticed the code didn't retain its formatting, so I attached a text file) -begin VBA code- Public Function xdate(m As Integer, n As Integer, wd As Integer, Optional y As Integer = 0) As Date '// m = 1-12 (Jan-Dec), n = 1-5 (1st-4th, last), wd = 1-7 (Sun-Sat), y = 1900-9999 or left blank for current year Select Case y Case 0 ' // Default. Use the current year. y = year(Date) Case 1900 To 9999 ' // treat the value as an explicit year Case -100 To -1, 1 To 100 ' // treat the value as an offset to be applied to the current year y = year(Date) + y Case Else ' // invalid value. Insert whatever error processing you like. End Select Select Case n Case 1 To 4 '// first through fourth Case 5 '// last. We need to check to see it fell within the month specified, if not, use 4. xdate = DateSerial(y, m, (8 - weekday(DateSerial(y, m, 1), (wd + 1) Mod 8)) + ((n - 1) * 7)) If month(xdate) <> m Then n = 4 End If Case Else ' // invalid value - insert error processing code here if you like. ' // Probably should check the other arguments as well. End Select xdate = DateSerial(y, m, (8 - weekday(DateSerial(y, m, 1), (wd + 1) Mod 8)) + ((n - 1) * 7)) End Function -end vba code- I'm teaching myself how to build websites; up until now I have made websites using tables within tables and it's all fairly straight forward, now I realise that divs and css allow you to do soooo much more! I have put these files in a temp folder on my website so not to over write the current site. Basically I have followed this online tutorial (http://www.cryer.co.uk/resources/jav...show_links.htm) but when I test the slideshow, it doesn't work. the link is: www.telecaretechnology.com/telecare2/index.html Since I have started writing this, my css file seems to have had a wobbly - I assume my problem is where I'm trying to use server-side include?? Is that the best way to add these files? the javascript I have used to make the slideshow run is he http://www.telecaretechnology.com/te...2/slideshow.js I would really appreciate any advice! Kind Regards, Jamie hi I need to find the average number in javascript. I have been working on it for a while but i am getting no where yes i am new to javascript and to be honest it is doing my blonde headed brain in. can someone please take a look at it and advise me on what i am doing wrong. it is the only bit of javascript that i have to do in the course but it carries a high mark of which i can not afford to lose Any way the question is : "Write code to calculate the average height and write it out in the browser window" Code: <HEAD> <TITLE> average </TITLE> <SCRIPT LANGUAGE = "JavaScript"> //Experimental results of Table 1 stored in arrays. var Height = [15,16,17,18,19]; var Number = [2,1,6,4,2]; //Part (ii). //Write code to declare and initialise new array to represent the third row of the table. var avg = new Array(5) var avg = ["60","80","187","180","114"] ; avg[0] = "60"; avg[1] = "80"; avg[2] = "187"; avg[3] = "180"; avg[4] = "114"; //Part (iv). //Write code to calculate the average height and write it out in the browser window. avg = 0; for (var count = 1; count <= 5; count = count + 1) Array.average = function(){ var avg = 0; for(var a = 0; a < this.length; a++){ avg += this[a]; } return avg / this.length; }; document.write('average height is ' +avg + '<br>'); </SCRIPT> </HEAD> <BODY> </BODY> </HTML> sorry for my ignorance thanks in advance kelly XXXXX Hi All, I have the date in 2009-10-24 format.can anyone tell how can I get the day of any particular date entered by user. Thanks in advance... Hi, I've been trying to code a javascript fonction that uses Window.find and I'm having problems doing exactly what I want. I don't know much of java and I understand that it's not everyone who's willing to do all the work for me so I'm looking for a very kind person here I want it to find a specific string that won't change (so no use to prompt for it) in another existing page that would be loaded in a frame. When the string is found, a sound is played like an alarm. The entire thing should reload every like 5 minutes. That's the easy part. I'm having trouble with the "If found in the frame, play a sound part". I don't think it's pretty hard to do, but hey, I can't do it. As I said earlier, I understand I ask for someone to do the whole thing for me but I'm willing to pay by paypal for the service. Let's say... I don't know, ten bucks should do it. I think I've been clear with what I need but if not, please feel free to ask for more specifications. Thanks for your time. Hello, Below is the javascript I'm debugging (or trying to) but just can't see where the error is: The code should send a message "GOOODDD!!!" when the input box is empty (nothing typed in) and should send a message (BAAADD!!!) when a string of theee a's are typed in ("aaa"). The problem is that no matter what I type in the script ALWAYS sends me a "GOOODD!!" message. I guess it is a simple glitch but I just can't figure it out. I'd appreciate any help Thank You. Code: <script language="javascript" type="text/javascript"> <!-- function textCheck(that) { var mytext=document.getElementById("BLABLA") if (mytext == "aaa") alert("BAAAAADDDDD!!!!" + mytext.value); else alert(" GOOOODDDD!!!!" + mytext.value); } --> </script> </head> <body> <form id="form1" method="get" onsubmit="textCheck(this)" /> <input name="BLABLA" size="3" type="text"/> Input Data <br/><br/> <input name="Submit1" type="submit" value="submit" /> </body> </html> This is a function designed to return an array of all elements in "body" with a particular tag name and class name. It works fine up until the if (needles.length == 0); { line, according to my debugging. It seems to fail there though and I can't figure out why. It's probably just some noob error that I've missed but I can't for the life of me find it Thanks in advance for any help, it's greatly appreciated! Code: function getElementsByClassName(tagname, classname) { var haystack = document.getElementById('body').getElementsByTagName(tagname); var needles = []; var i; for (i in haystack) { if (haystack[i].hasClassName(classname)) { needles.push(haystack[i]); continue; } } if (needles.length == 0); { needles = 0; } return needles; } Hello. Please excuse my ignorance but I am not too clued up on javascript. Im hoping someone may be able to help me out here. I have managed to locate a script which will find text on a page, but I have a couple of requests. Firstly the script will only search up. I would like the search box to be at the top of a page but the only way to get it to work correctly is placing it at the bottom of the page. Secondly would some kind soul advise me how to place the script in an external file and then link to it. Thanks in advance. function textSize(updown) { var size = Number(readCookie('user-font-size')); if (size == 0) { size = 12; // No Cookie, Set A Default Size Of 12px } size = size + Number(updown); // Adjust The Current Size if (size > 20) { size = 20; } // Stop At 13 if (size < 12) { size = 12; } // Stop At 10 writeCookie('user-font-size', size, 12); // Update The Cookie document.body.style.fontSize = size + 'px'; // Set The Users Text Size } function writeCookie(name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = '; expires=' + date.toGMTString(); } else { expires = ''; } document.cookie = name + '=' + value + expires; } function readCookie(name) { name += '='; var cs = document.cookie.split(';'); for (var i = 0; i < cs.length; i++) { var c = cs[i]; while (c.charAt(0) == ' ') { c = c.substring(1, c.length); } if (c.indexOf(name) == 0) { //-----------// return c.substring(name.length, c.length); // Gotcha // } //-----------// } //------------// return null; // Failed // } //------------ <img id="plustext" class="zoom-in" alt="Increase text size" src="Zoom-In-icon.png" onclick="textSize (2);" style="cursorointer" /> <img id="minustext" class="zoom-out" alt="Decrease text size" src="Zoom-Out-icon.png" onclick="textSize (-2);" style="cursorointer" /> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vel fringilla arcu. Cras ullamcorper nunc ac sapien gravida ultrices. Curabitur mollis consectetur elit non tempus. Duis blandit luctus feugiat. Nullam eget tellus at quam dapibus tempus in scelerisque ligula. Phasellus turpis ante, tincidunt at aliquam vel, luctus vitae leo. Suspendisse dignissim vehicula est, ac dapibus justo pellentesque eu. </p> cheers hope thats enough code Ant. Hello, please tell me where can I find script visible on page www.frendzel.pl (Big picture changing every few second to another from the list on the left)
Hi Guys & Girls, I am looking for help with a technical issue, which my programmer can't find the answer to. My website has a demonstration facility which allows a client to enter their website which then in turn creates a video transparency overlaying their own website. The problem is some sites with Flash, overlay my transparency video so that you cant see my demo video. Any ideas please. Thanks Maximillion I am trying to do a title case project and can't figure out where I went wrong. Any help would be appreciated. <!DOCTYPE html> <html lang="en"> <head> <title>Title Case</title> <meta charset="utf-8"> <script type="text/javascript"> function titleCase() { var word = document.forms[0].string.value.split(" "); var cword = ""; for (var i = 0; i < word.length; i++) { cword = cword + word[i].substr(0, 1).toUpperCase() + word[i].substr(1).toLowerCase() + ((i < word.length - 1) ? " " : ""); } return cword; } </script> </head> <body> <h1>Title Case</h1> <form action="" method="get"> <p><input type="text" name="string" /> <input type="button" value="Convert to Title Case" onclick="titleCase()" /></p> </form> </body> </html> Hello, I have recently started a website which tells visitor's IP address, location and others details. I want to add some more functions to it. I found no way to detect visitors Internet Service Provider (ISP) using PHP. I would like to know if there is any way to do so in Javascript. Click the below link to view the site: Show IP Please help me ASAP. Regards, Wasif K. Hi All, Just a quick question! Is it possible to have a text box input searching for the entered text on another webpage in the same way Find In Page would do? I have a webpage that I want users to input an item, and that this will open the targeted webpage and bring you to (and highlight) the matched item(s) like find in page does. Is this possible or is the easiest way to just make users open the link to the target page and just complete the find in page search there? Thanks Glen Hi all. Is it possible to command a find in page search from another html? I have a 'main page' and 'directory page' The directory page has find in page command on it, so if users can open the directory link from the main page and then search that page using the find in page search box. To speed this up, is there any way I can have a text box on my main page that when I enter text and submit that it carries across the text entry to the find in page box on the directory page and starts this search for me? I need to complete this using javascript so if this is possible I would great appreciate any help. Thanks I have a problem finding Form in javascript. document.getElementById('MyForm'); return "HTMLUnknownElement". But if I add a dummy form previous for the one I actually want to find, then: document.getElementById('DummyForm'); returns "HTMLUnknownElement", and then document.getElementById('MyForm'); Returns "HTMLFormElement", that is what need. But this unknown element, the dummy form creates a lot of other problems with my site so this solution is no good for me. Why cant I find my Form? Thanks. I need some help finding a "find on page" script that will display the results in the middle of the page for IE. I have tried several different ones to no avail. The ones that work in all the browsers display the result in IE at the very bottom of the page. I am not very familiar with programing in Java and I am unable to modify any for my needs. The one I found that did work in IE didn't work in any other browsers. Please help, Thx
I was trying to sum every number in the array and I wrote this function: Code: function sumArray(array) { var total = 0, i; for (i = 0; i <= array.length - 1; i++) { if(typeof array[i] == "number") { array[i] += total; } } return total; } I don't know why but it always returns "0". In other words, the initial value of "total" (if it was 5, it returns 5 etc...). I really can not see what is wrong here, any suggestions? Error: Code: Error ``TypeError: window.event is undefined'' [x-] in file ``file:///C:/Users/Martyn%20Ball/Desktop/test.php#'', line 6, character 0. Code: Code: <html> <head> <title>Testing Javascript</title> <script type="text/javascript"> function test() { alert(window.event.clientX); } function doSomething(e) { var posx = 0; var posy = 0; if (!e) var e = window.event; if (e.pageX || e.pageY) { posx = e.pageX; posy = e.pageY; } else if (e.clientX || e.clientY) { posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } // posx and posy contain the mouse position relative to the document // Do something with this information } </script> </head> <body> X Position: <div id="x"></div> Y Position: <div id="y"></div> <br /> <a href="#" onMouseOver="test()">Test Link</a><br /> <a href="#" onClick="doSomething('y')">Type of Event</a> </body> </html> (Taken from external website so I can understand how it works). |