JavaScript - Amending Showhint Function Java + Php Problems
Hi,
I am trying to amend the showHint Function from w3schools. I adapted the basic script to allow multiple calls and I don't have a permanent array so I made my php page create one from the table. Have tried to play around with this a bit but I currently get nothing. My script is: Code: <head> <script type="text/javascript"> function showHint(str,FILE+str,ID){ if (str.length==0){ document.getElementById(ID).innerHTML=""; return; } if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET",FILE,true); xmlhttp.onreadystatechange=function(){ if {xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } xmlhttp.send() } </script> </head> <body> <label>Search by name: </label> <input type="text" class="input" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'Search':this.value;" onkeyup="showHint('getNames.php?q=','txtHintName')" Value="Search" /> <br /> <div id="txtHintName"></div> <br /> There will be more calls but I thought I would try and get one working first. My Name.php is: PHP Code: <?php $con = mysql_connect("localhost","user","password"); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $result=mysql_query("SELECT * FROM members"); while($row = mysql_fetch_array($result)){ echo "$a[]='" . $row['name'] . "';"; } $q=$_GET["q"]; if (strlen($q) > 0){ $hint=""; for ($i=0; $i<count($a); $i++){ if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q)))){ if ($hint==""){ $hint=$a[$i]; }else{ $hint=$hint . " , ".$a[$i]; } } } } if ($hint == ""){ $response="no suggestion"; }else{ $response=$hint; } echo $response; ?> mysql_close($con); ?> Nothing happens. I have names in my db so they are there to be called. Similar TutorialsGood morning Guru's and Experts, I really need your help with this one. It seems that the function this_week('end') is returning a bad date of 12/33/2014 (mm/dd/yyyy) where it should properly read: 01/02/2015 Code: function this_week(x) { var today, todayNumber, fridayNumber, sundayNumber, monday, friday; today = new Date(); todayNumber = today.getDay(); mondayNumber = 1 - todayNumber; fridayNumber = 5 - todayNumber; if (x === 'start') { //var start_dd = today.getDate() + mondayNumber var start_dd = today.getDate() var start_mm = today.getMonth() + 1 var start_yyyy = today.getFullYear() return start_mm + '/' + start_dd + '/' + start_yyyy } if (x === 'end') { var end_dd = today.getDate() + fridayNumber var end_mm = today.getMonth() + 1 var end_yyyy = today.getFullYear() return end_mm + '/' + end_dd + '/' + end_yyyy } } Reply With Quote 12-29-2014, 07:43 PM #2 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts I understand that you are trying to get the date next Friday. Try this script:- Code: <span id = "info"></span> <script type = "text/javascript"> var curr = new Date(); // get current date var first = curr.getUTCDate() - curr.getUTCDay(); // First day is the day of the month - the day of the week var last = first + 5; // last day is the first day + 5 = Friday var lastday = new Date(curr.setDate(last)); var yy = lastday.getUTCFullYear(); var mth = lastday.getUTCMonth()+1; if (mth<10) {mth = "0" + mth} var dy = lastday.getUTCDate(); if (dy<10) {dy = "0" + dy} // now manipulate the display of year,month,date as desired var result = mth + "/" + dy + "/" + yy; document.getElementById("info").innerHTML = "Week Ending Friday " + result; </script> Lottery: A tax on people who are bad at math. hi every body, when iam usig java script function to textbox,For text length minimum 4 chars, alert is raising enter minimum 4 chars, but cursor is not focus on text box, when i click on alert "OK". Here the code written. function min() { var len=document.getElementById("tx1").value; if(len!="") { if(len.length==4) { alert("Chars 4 Letters Entered"); } else { alert("Enter 4 chars") document.getElementById("tx1").select(); document.getElementById("tx1").focus(); } } } Yours Narasimha Rao k I'm trying to reduce the space between the page content and the footer..this is the code i'm using to resize and the method call is implemneted in master page pageload() Code: function resize() { var windowHeight; if (document.getElementById("leftnav") && document.getElementById("content")) { // document.getElementById('leftnav').style.height = document.getElementById('content').offsetHeight - 20 + 'px'; if (document.getElementById("content").offsetHeight >= 698) { document.getElementById("leftnav").style.height = document.body.clientHeight + "px"; document.getElementById("content").style.height = document.body.clientHeight + "px"; } } This method resizes based on the content but it gives more extra space between the content and the footer which is not our site standards. Any suggestions please? thanks Hi I've just found out that a piece of code is not working as expected in certain browsers - but the way in which it goes wrong is not consistent, so maybe it's something wrong with my code. Oddly enough, it works exactly as I was expecting when viewed in IE. Here's the code... any help would be much appreciated. Thanks Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script type="text/javascript"> function fillboxAddress() { if (document.getElementById('tbAddress').innerHTML == '') { document.getElementById('tbAddress').innerHTML = 'Address'; } } function clearboxAddress() { if (document.getElementById('tbAddress').innerHTML == 'Address') { document.getElementById('tbAddress').innerHTML = ''; } } </script> </head> <body> <p><textarea name="tbAddress" rows="2" cols="20" id="tbAddress" onfocus="clearboxAddress()" onblur="fillboxAddress()">Address</textarea></p> </body> I have a function where in I call another function that assigns a value to a var. e.g. Code: function setVar{ var thisVar = 'hello'; return thisVar; } function callFuncSetVar { var newVar = setVar(); alert(newVar); } For some reason my code below is returning 'undefined'. But when I place an alert(); before the 'return' it shows the correct value. However when I place an alert(); to show the var that is set to what the function returns it says 'undefined'. Firebug throws no errors. I am using a little bit of jQuery. I am using a javascript audio player on a webpage that has an option to download the track by right clicking on a link called 'mp3' at the end of each track in the playlist. When the user right clicks on the track name however all that can be downloaded is an html file. I am trying to find a way of changing this so that right clicking on the track and choosing the 'save link as' option will download the mp3. I have been led to believe that I can use a script such as this one: http://abeautifulsite.net/blog/2008/...-click-plugin/ to generate a custom content menu for downloading tracks, or somehow downloading the mp3, but I am at a loss at to how to do this. Here's a screenshot of a track in the playlist: And here is the source: Code: {name:"foster manganyi na tintsumi ta tilo - zion (ndzi teke riendzo no. 1) <span style=\"color:#BDBDA1; font-size:12px;\">[from nick]</span>",mp3:"./songs//nick/zion.mp3"} I would be grateful for any advice on getting this working, Thanks, Nick First of all, I must say that I am recently introduced to JavaScript and I am not fully aware of its complete functionality. So I have an HTML document which has defined within a its body a JavaScript function and I have also a JApplet class which is also loaded in the HTML and can call the JavaScript function. But I have also another Java class which is not an applet and I would like to find a way for this class to be able to call the JavaScript function (but it is essential for this class not to be an applet). I am aware that this would raise some security concerns but it is for local usage and I am interested to hear some ways if possible for this to be done. Thank You beforehand to all of you! Hi, Can anyone tell me How to send values from application resources.properties file to a java script function in a jsp Thanks in Advance, John Ven Apologies for the confusing title. I have a scipt Code: ....style: google.maps.NavigationControlStyle.SMALL } }); <? $query = mysql_query("SELECT * FROM `family_support` WHERE 1"); while ($row = mysql_fetch_array($query)){ $org_name=$row['org_name']; $lat=$row['lat']; $long=$row['long']; $org_address=$row['org_address']; echo ("addMarker($lat, $long,'<b>$org_name</b><br/>$org_address');\n"); } ?> center = bounds.getCenter(); map.fitBounds(bounds); } </script> I want the $query to be the same as another query set up further down the page; Code: $sql_result= "SELECT * FROM family_support WHERE org_name LIKE '%$org_name%'"; if ($area != 'All') { $sql_result .=" AND area LIKE '%$area%'"; } if ($services != 'All') { $sql_result .=" AND services LIKE '%$services%'"; } if ($hardiker != 'All') { $sql_result .=" AND hardiker = '$hardiker'"; } My php is dire and help with putting these together would help me display markers on a map for all results from a search form rather than display all records within the db as is happening at present.... Also would I need to move the script from the head tag? Hello, I have a function that I call that tells me the checked value of a group of radio boxes. You pass in the form name and radio group name and it gives you the value of the one that is checked. I have a dynamic list of existing shipto addresses that a user can select one in order to have something shipped to a previously used shipto address. If I have more than one, my code works but if there is only one radio option and they click it, the object is deemed undefined. I need for this function to handle a single radio option on the page as it is possible in some cases. Here is my code Code: function get_radio_checked_value( form_name, radio_name ) { var radioObj = document.forms[ form_name ].elements[ radio_name ]; for(var i = 0; i < radioObj.length; i++) { if(radioObj[i].checked) return radioObj[i].value; } } And my usage is usually like this Code: var tempradio = get_radio_checked_value( 'frm_shipto', 'rad_shipto' ); In the above example if I have more than one address / radio option, tempradio holds the correct value otherwise if just one address available it holds undefined Any help would be greatly appreciated. I am coding an actionscript app and need to call javascript function in page that embeds the swf file. I am doing this as Action Script 2.0 and am testing in Firefox 1.5 x (flash pluggin version 7) I am getting the following error message: (not part of the error text) re object/embed id/name _DoFSCommand(command, args) (.swf/actionscript call to javascript) in Firefox/1.5.0.3 on Mac OS 10.3x (error text-- from FF javascript console) Error: plugin.SetWindow is not a function Source File: javascript: function jsScriptObject(obj) { this.wrappedJSObject = obj; } jsScriptObject.prototype = { evaluate : function(expression) { return new jsScriptObject(eval(expression)); } }; var plugin = document.embeds['SWFO']; plugin.SetWindow(new jsScriptObject(window),879801055); Line: 1 This set up works in version 10 flash pluggin, as is, in Firefox 3.5.2 Can anyone give me a clue about this? A little further info to possibly save someone some time: I am working on an actionscript 3.0 version that uses externalInterface in Action Script, so I don't need advice to upgrade. I am trying to target older browsers as well as newer ones. Thank you for time and attention; JK Hi, I am just a noob and this is my first go at javascript and html I am trying to figure out how to display info from an array in the <textarea>, I have tried a number of things nothings worked and I know it must be something simply but have tried a number of things I also have to clear the <textarea> after it displays the info mentioned above and I think I have that sorted but I also have to have the <textarea> display all signup info stored in the array when a user clicks on a button Here's the code Code: function show() { var myArray = new Array(); myArray[0] = document.getElementById('fullname').value; myArray[1] = document.getElementById('Address').value; myArray[2] = document.getElementById('Phone').value; document.writeln('Thank you for signingup,' + ' ' + myArray[0] + '. Your details will be confirmed by E-mail to ' + myArray[2] ); document.writeln("<br>") document.writeln('Details:') document.writeln("<br>") for (var i=0; i<myArray.length; i++) {document.write(myArray[i] + "<br />"); } } Thanks I'm new to coding, And would like to know if java is capable of: Playing a sound file when a name or word is seen on the screen. Or, In this case on a windows sidebar gadget. Thanks ok, so, I honestly have no clue why it wont work.. I'm workin in html and I put some javascript code(im learnin) so here it is, please help! <script> code = 0 function mf() { code += 1 if (code >= 1) { code = 0 {document.getElementById("test").innerHTML = "I have changed";} } else { code = 1 {document.getElementById("test").innerHTML = "Click below to change me!";} } } </script> <p id = "test">Click below to change me!</p> <button type = "button" onclick = "mf()">click here!</button> What is JAVA? From where I can learn. Please guide me the best institution that is teaching JAVA in the world. Any online tutorial or site where I can get online material. I am not familiar with this program nor i have any idea. I am waiting for your response because i want to start it immediately. I have been trying to learn java coding from a book and have run into a coding question that I'm confused about. Can someone help? I have a one dimensional array of positive integers. I'm trying to create another array with the same length and scan the original array for finding the maximum integer. I am then needing to copy that maximum integer in first position of the created array and set the maximum integer in the original array to zero. For second round, I need to write code to find the maximum integer in the original array and copy that in second position of created array and set the maximum integer in the original array to zero. I need to repeat this until all numbers in original array is zero. My created array should be sorted in positive integer numbers. I need to write this sort method that accepts a one dimensional array of integers that return the sorted array testing this method using the main method. I was hoping someone could help me fix this javascript code. I have been working for hours and it does not work. <html> <head> <title>Moondoe's Coffee House</title> </head> <script type="text/javascript"> var drink, ounces; prompt( "Enter the drink type:espresso, latte, cappuccino, americano" ); prompt( "Enter the ounce size: 8, 12, 16" ); var shots = prompt ( "Enter the number of shots" ); if ( drink == "espresso") price = 1.40; if ( drink == "latte") || drink == "cappuccino" ) { if ( ounce == 8 ) price = 1.95; else if ( ounce == 12 ) price = 2.35; else if ( ounce == 16 ) price = 2.75; } if ( drink == "americano" ) price = 1.20 + ( ( (ounce/8) -1 ) * .30 ); price = price + ( (shots-1) * .50 ); price = price * 1.055; price = Math.round ( price*100 ) /100; alert ( "Your " + ounce + "oz. " + drink + "with " + shots + "\nshots of espresso costs: $ " + price ); alert( "drink = " + drink + "ounce = "ounce + "shots = "shots ); </script> </html> Hey guys! I have this website mmosaga.com and in need of some help to fix my BG. Im trying to get my BG to rescale to various of monitor sizes. My monitor width is 1440 and my BG images are Width: 1566 Height:768. I want that position to show up on all the other browsers including IE. Here the code I use PHP Code: <html> <head> <script language="javascript"> function randomBackground() { var myImages = Array(); myImages[0] = 'Florenga.jpg'; myImages[1] = 'pangar.jpg'; myImages[2] = 'GrandChaseBG.png'; myImages[3] = 'ADBG.png'; myImages[4] = 'AionBG.png'; myImages[5] = 'FiestaBG.jpg'; myImages[6] = 'GalaxyOnlineBG.jpg'; myImages[7] = 'GunzBG.png'; myImages[8] = 'IrisOnlineBG.png'; myImages[9] = 'MabinogiBG.png'; myImages[10] = 'APB.jpg'; myImages[11] = 'S4LeagueBG.jpg'; myImages[12] = 'APB.jpg'; myImages[13] = 'WorldOfTanksBG.jpg'; myImages[14] = 'Elsword.jpg'; myRandomNumber = Math.floor(Math.random()*myImages.length); document.body.style.backgroundImage = 'URL('+myImages[myRandomNumber]+')'; } </script> <style type="text/css"> body { background-attachment: fixed; background-repeat: no-repeat; } </style> </head> <body onload="randomBackground();"></body> I'm not really good with javascript and need help with a problem. I'm creating a pop-up window that goes to another site but sends the url it's coming from in the url it's going to. Ok here's what I have if that's confusing. Code: <head> <script type="text/javascript"> function popupwin(url) { var width = 650; var height = 250; var left = (screen.width - width)/2; var top = (screen.height - height)/2; var params = 'width='+width+', height='+height; params += ', top='+top+', left='+left; params += ', scrollbars=1'; newwin=window.open(url,'popupwin', params); if (window.focus) {newwin.focus()} return false; } </script> </head> <body> <a href="javascript: void(0)" onClick="popupwin('http://example.com/check.php?id=http://$_SERVER[SERVER_NAME]$_SERVER[REQUEST_URI]'); return false;">Centered popup window</a> </body> Now that above code works fine in most cases and on most sites. The problem is that one forum I've tried it on has a seo mod which means the php comand $_SERVER[REQUEST_URI] isn't the same that's in the address bar. Instead of showing Code: http://sitename.com/forum/main-forum/1-test-post-title-some-list.html it's showing Code: http://sitename.com/forum/showthread.php?p=1 After Googling I know that document.write(location.href) will give me the exact url of the seo url as it appears in the address bar which is what I want. Can anyone show me how to combine document.write(location.href) with my code. I know it's probably easy for most but I only really know basic html and php and I'm only new to javascript. Thanks in advance. Hello everyone, I needed some help on finding a complete code which implements DES in either c++ or Java. Thanks |