JavaScript - Ajax, How To Limit Result From Suggestion Box?
Hi, I have this code to get hints (PHP file):
Code: <?php include("include/session.php"); $GetNames = "SELECT firstname, lastname, username FROM users"; $GetNamesConnect = $database->query($GetNames); While($row = mysql_fetch_array($GetNamesConnect)) { $a[$row['username']] = $row['firstname'] . " " . $row['lastname']; } //get the q parameter from URL $q=$_GET["q"]; //lookup all hints from array if length of q>0 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]; } } } } // Set output to "no suggestion" if no hint were found // or to the correct values if ($hint == "") { $response="no suggestion"; } else { $id = $row['username']; $response= "<a href='profile.php?user=$row['username']'>$hint</a>"; } //output the response echo $response; ?> This is the display part (Javascript/Ajax) 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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <script type="text/javascript"> function showHint(str) { if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","gethint.php?q="+str,true); xmlhttp.send(); } </script> </body> </html> What I want to do it to limit the names suggested to 10, how would I do this? Similar TutorialsI am very new to web development and I need a push in the right direction here. This is my problem; I am making a web page that will be used privately by two people. I need to find a way to go to an FTP site that can only be accessed by web browser (that is what IT told me) and download a file that has a constant name "prevhour.log" and save this file to a directory so that it can be read (not sure how, my boss is doing that end) and the data will be dumped, and this data will be extrapolated into a gas gauge style dashboard. I need some way of this to be done as automated as possible. Thank you for your time. Rick Hi; I am implementing a Ajax auto suggestion search from database. I find an example from http://www.roscripts.com/Ajax_autosu...abase-154.html . I have not problem with the php part about search from database, but i got a problem from the search from, i added a listerner to input tag, but it still not auto suggest anyword when i type any of word, Could any one help me, Thanks. PHP Code: <html> <head> <title>roScripts - Ajax auto-suggest</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <script src="lib/prototype.js" type="text/javascript"></script> <script src="src/scriptaculous.js" type="text/javascript"></script> <script src="src/unittest.js" type="text/javascript"></script> <script src="lib/builder.js" type="text/javascript"></script> <script src="src/controls.js" type="text/javascript"></script> <script src="src/effects.js" type="text/javascript"></script> <link rel="stylesheet" href="css/style.css" type="text/css" /> </head> <body> <div id="container"> <form method="post" action="response.php"> <label for="testinput">Search</label><br /> <input type="text" id="search" name="search" autocomplete="off" class="input" value="" onkeyup="autoSuggest();" /><br /> <div id="update" style="display:none;position:relative;"></div> <input type="image" name="register" class="submit-btn" src="http://www.roscripts.com/images/btn.gif" alt="submit" title="submit" /> </form> <script type="text/javascript" language="javascript" charset="utf-8"> function autoSuggest(){ new Ajax.Autocompleter('search','update','response.php', { tokens: ','} ); Autocompleter.show(); } </script> </div> </body> </html> Hello, I am creating a little script that allows me to scroll my content sections in and out though Ajax and CSS. I have have successfully made it slide in from the top but I have one problem, sliding out! I wrote a clip for 'aniOut' that works also but I cant seem to make one load before the other in transition. I am not very good with javas cript anyone have any suggestions? So far this only is working for Chrome. My site is live with the working slide in at The Mind Company. Also I am having a load issue with some browsers and computers where the page must be refreshed in order to view proper, any suggestions? CSS: Code: header { z-index:100; position:relative; display: block; background-color: #272727; height:100px;} #contentBody { min-height:48em;} footer { position:relative; display: block; background-color: #272727; height:168px; } #aboutPage { display:none;} #productPage { display:none;} #contactPage { display:none;} .aniIn { z-index:0; -webkit-animation-name: ANIMATEin; -webkit-animation-duration: 0.25s; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: ease-in; } @-webkit-keyframes ANIMATEin { from { margin-top:-4000px; } to { margin-top:0px; } } .aniOut { -webkit-animation-name: ANIMATEout; -webkit-animation-duration: 2s; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: ease-in; } @-webkit-keyframes ANIMATEout { from { margin-top:0px; } to { margin-top:3000px; } } Script: Code: function $_(IDS) { return document.getElementById(IDS); } function ani(){ document.getElementById(classID).className ='aniOut'; } function checkPage(classID, url){ var tmp = ''; var sel = document.getElementsByTagName('section'); for (var i=0; i<sel.length; i++){ if (sel[i].id == classID) { tmp = 'block' } else { tmp = 'none' } $_(classID).className ='aniIn'; sel[i].style.display = tmp;} $_(classID).style.display = 'block'; loadContent(classID, url); } function loadContent (classID, url){ var xmlhttp; if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest();} xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(classID).innerHTML=xmlhttp.responseText;}} xmlhttp.open("GET","content/"+url,true); xmlhttp.send();} HTML: Code: <!-- Header Areas: (Constent visual)--> <header> <li><a href="#" onclick="checkPage('aboutPage', 'about.html');return false">About</a></li> <li><a href="#" onclick="checkPage('productPage', 'projects.html');return false">Projects</a></li> <li><a href="#" onclick="checkPage('contactPage', 'contact.html');return false">Contact</a></li> </header> <!-- Content Areas: (Variable visual)--> <div id="contentBody"> <section id="aboutPage"></section> <section id="productPage"></section> <section id="contactPage"></section> </div> <!-- Footer Area: (Constant visual)--> <footer></footer> I am starting a new project soon. Now, the project is still in the stage of planning. But I am quite confuse now which programming language to implement. I am going to design a system where the normal users will update the data with the system while the data required changes will need system administrator to apporve it. I will need a database to keep those records (the data required update) so that the system admin can refer to the database and make changes. Do I have another choice instead of using Microsoft Access 2007 macros or VBA ? I prefer a web-based programming. Any suggestion, please ? I've been using Coffeecup free version for HTML/CSS needs and it works fine as if you forget say one or two values, the prompt feature works fine. Im now getting into Javascript and can see that it is a very useful language, however are there any editors that will provide prompt/suggestion pop ups when editing which are free? If possible, one that combines HTML/CSS/Javascript all together. I've seen this:- http://download.cnet.com/Free-JavaSc...-10907077.html And was going to give it a download. But anyone know of any others or can recommend the above? Thanks Hello, I have a specific need in javascript. Can I be guided in this context if its possible or not??? I am using virtuemart extension in joomla to make an ecommerce website. I will try to explain my requirement with the example. Following is the sample category tree with number. 1.0 .....1.1 ..........1.1.1 ..........1.1.2 .....1.2 ..........1.2.1 ..........1.2.2 .....1.3 ..........1.3.1 ..........1.3.2 2.0 .....2.1 ..........2.1.1 ..........2.1.2 .....2.2 ..........2.2.1 ..........2.2.2 .....2.3 ..........2.3.1 ..........2.3.2 Now I have a drop down main menu as 1.0 and 2.0. I want that when i click on 1.0 all the nodes of 1.0 should be opened and 2.0 should be closed and similarly when i click on 2.0 all its child nodes should be opened and 1.0 should be closed. What happen with most extensions is that at a time only one child is opened. If i click on 1.0 then only 1.1 or 1.2 or 1.3 will remain open at a time. Does this kind of customization can be done or is available in javascript .... I hope i will be helped... Thanks a lot for the time. Hi, I am hoping I just need to be pointed in the right direction with this. I have Page1. When Page1 body onloads it uses Ajax to call PartA Within PartA I have a message board so members can write messages which will be sent to my database in PartA[1] and immediately posted for view on to PartA[2]. As I want to have my request to the server updating regularly I want to have PartA[2] on a timed loop to refresh - I do not need the content of PartA[1] to refresh. So the order of events would look like this: Page1 | onload call | v PartA / \ V V PartA[1] PartA[2] (loads once) (constantly refreshes) What I am not sure about is that I have <body> and <head> attributes in Page1 only. I have already used my body onload to call PartA (and can't use it to call PartA[2] before PartA has loaded anyway). I do not want the user to have to click a button or do anything to call up PartA[2]. So my question is how would I get PartA[2] to automatically load within PartA? I hope I have made this clear, but if I haven't let me know and I will try again. Is it possible to limit a textarea input with a max amount of letters? So if the form said 1,000 character limit. Can it block it after the 1,000th one is reached? Dear Friends, please give your solution about below problem. I call function test".$i."(){ edit($('$paket_id')); } function for editing in line text. <div onclick="test".$i."(this)"><img src="./images/edit01.png"></div> http://www.freeimagehosting.net/l5raa But when I click to call link, the textarea are opening again. How I can limit this? hi, i am now playing with the time. can you please tell me how to make the time move in downwards, i mean a countdown like format, e.g the time will start countdown and end in 2 days? here's my initial noob code for creating time Code: <script type="text/javascript"> var today = new Date(); h = today.getHours(); m = today.getMinutes(); s = today.getSeconds(); function showDate(){ if(document.getElementById('but').value = "locked"){ h = checktime(h); m = checktime(m); s = checktime(s); } document.getElementById('t').innerHTML = h +":"+m+":"+s; } function checktime(i){ if(i < 10){ i = "0" + i; } return i; } function ocl(){ var x = true; if(x){ document.getElementById('but').value = "locked"; showDate(); } } function mo(){ document.getElementById('but').value = "lock me ?"; x = false; } </script> <h3> <a id="t"></a> </h3> <input type="button" id="but" value="unlocked" onmouseover="mo();" onclick="ocl();" /> I have a script which allow a user to move users from one multiple selectbox to another and it works fine, but... I want to be able to restrict a user to only move x amount of users from one box to another. I want to create an alert when the user try to add a user to much... The javascript: Code: $().ready(function() { $('#add').click(function() { return !$('#box1 option:selected').remove().appendTo('#box2'); }); $('#remove').click(function() { return !$('#box2 option:selected').remove().appendTo('#box1'); }); }); The HTML: Code: <table> <tr> <td valign="top"><select multiple id="box2" style="width:250px;height:200px;"></select></td> <td width="100%" align="center"><a href="#" id="add">Add</a><br><a href="#" id="remove">Remove</a></td> <td valign="top"> <select multiple id="box2" style="width:250px;height:200px;"> <option value="1">User 1</option> <option value="2">User 2</option> <option value="3">User 3</option> <option value="4">User 4</option> </select> </td> </tr> </table> Hope this makes sense... Thanks in advance... Thank you for your help with this. I am newer to JS and appreciate the assistance. I am using iScroll for an image gallery on the iPad. I can place 120 columns equalling 122,880 pixels in width. After that the content fails to display. How can I get additional 180 columns that I have to display? Hi All I am not a genius when it comes to javascript so if anyone could help, I would really be grateful. scenario: I am creating a custom product (75g) which will be made up of 3 others products (25g + 25g + 25g). The 3 options will be made up of a combination of smaller products each with their own options (25g, 50g, 75g) which will allow the customer to have one of each or fill up all 3 with just one type. Here is what I have in code already: Code: <div class="wrapperAttribsOptions"> <h4 class="optionName back">Organic Sour Worms</h4> <div class="back"> <input name="id[14][48]" value="48" id="attrib-14-48" type="checkbox"><label class="attribsCheckbox" for="attrib-14-48">25g</label><br> <input name="id[14][49]" value="49" id="attrib-14-49" type="checkbox"><label class="attribsCheckbox" for="attrib-14-49">50g</label><br> <input name="id[14][50]" value="50" id="attrib-14-50" type="checkbox"><label class="attribsCheckbox" for="attrib-14-50">75g</label><br> </div> <br class="clearBoth"> </div> <br class="clearBoth"> <div class="wrapperAttribsOptions"> <h4 class="optionName back">Organic Sugar Bears</h4> <div class="back"> <input name="id[15][51]" value="51" id="attrib-15-51" type="checkbox"><label class="attribsCheckbox" for="attrib-15-51">25g</label><br> <input name="id[15][52]" value="52" id="attrib-15-52" type="checkbox"><label class="attribsCheckbox" for="attrib-15-52">50g</label><br> <input name="id[15][53]" value="53" id="attrib-15-53" type="checkbox"><label class="attribsCheckbox" for="attrib-15-53">75g</label><br> </div> <br class="clearBoth"> </div> <br class="clearBoth"> <div class="wrapperAttribsOptions"> <h4 class="optionName back">Organic Fruit Cocktail</h4> <div class="back"> <input name="id[16][54]" value="54" id="attrib-16-54" type="checkbox"><label class="attribsCheckbox" for="attrib-16-54">25g</label><br> <input name="id[16][55]" value="55" id="attrib-16-55" type="checkbox"><label class="attribsCheckbox" for="attrib-16-55">50g</label><br> <input name="id[16][59]" value="59" id="attrib-16-59" type="checkbox"><label class="attribsCheckbox" for="attrib-16-59">75g</label><br> </div> <br class="clearBoth"> </div> <br class="clearBoth"> <div class="wrapperAttribsOptions"> <h4 class="optionName back">Organic Jelly Bears</h4> <div class="back"> <input name="id[17][57]" value="57" id="attrib-17-57" type="checkbox"><label class="attribsCheckbox" for="attrib-17-57">25g</label><br> <input name="id[17][58]" value="58" id="attrib-17-58" type="checkbox"><label class="attribsCheckbox" for="attrib-17-58">50g</label><br> <input name="id[17][60]" value="60" id="attrib-17-60" type="checkbox"><label class="attribsCheckbox" for="attrib-17-60">75g</label><br> </div> <br class="clearBoth"> </div> What I need to do is to some how ensure that the product is filled with 75g worth of the other products. Another option may to not use the 'grams' but rather use the 3 compartments that will be filled so 25g = 1, 50g = 2, 75g = 3 etc. Note: Name, Values, Ids are made dynamically by the cart, and I cannot change those as they are used for adding to cart and updating account info etc. PLEASE PLEASE PLEASE if anyone can help, I would really appreciate it. ----------------------------- Jay Hello, Is there any way that I can add a limit for the amount of time that a javascript loader bar stays on screen? The specific loading screen I am using is http://www.fliesen-info-spanien.net/loadbox.php. This loading box actually activates once the page is loaded apparently, but in my instance, it is loading then disappearing in the matter of a second, but I wouldnt mind leaving it up for a couple of seconds, say 3-5. Is there any line of code I can add to do this? Andy I want to limit a textarea to 500 characters. So somebody can't type in more than 500 characters or paste anything with more then 500 characters in the text box. However, if somebody were to enter something into the fields favoritedrink OR to favortefood, then I want the limit to change to 100 characters for the textarea. How can I do that using Javascript? I am using the form code below as an example. Code: <form action=""> <input type="text" name="firstname"><br /> <input type="text" name="lastname"> <textarea rows="2" cols="20" name="description"></textarea> <input type="text" name="favoritefood"> <input type="text" name="favoritedrink"> </form> I need some help for my site and would so much appreciate if somebody can help me with my problem. Thanks so much for any help. hello, i want to make a word limit on textarea in the below form any body help me- thank you. please reply me by editing below code Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>freebacklinkcreator.blogspot.com submit form</title> </head> <body> <form method="post" action="sendeail.php"> <!-- DO NOT change ANY of the php sections --> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> Your Name: <br /> <select name="visitor" size="1"> <option value=" Business ">Business </option> <option value=" Finance ">Finance </option> <option value=" Reference ">Reference </option> <option value=" Shopping ">Shopping </option> <option value=" Arts and Entertainment ">Arts and Entertainment </option> <option value=" Computers ">Computers </option> <option value=" Health ">Health </option> <option value=" News and Media ">News and Media </option> <option value=" Regional ">Regional </option> <option value=" Society ">Society </option> <option value=" Education ">Education </option> <option value=" Internet ">Internet </option> <option value=" Recreation ">Recreation </option> <option value=" Science and Technology ">Science and Technology </option> <option value=" Sports ">Sports </option> <option value=" Jobs ">Jobs </option> <option value=" Online ">Online </option> <option value=" Money ">Money </option> <option value=" Affiliate Programs ">Affiliate Programs </option> </select> <br /> Your Email:<br /> <input type="text" name="visitormail" size="35" /> <br /> <br /> <br /> Site Title:<br /> <input type="text" name="attn" size="35" /> <br /><br /> Site Description: <br /> <textarea name="notes" "rows="4" cols="40"></textarea> <br /> <input type="submit" value="Send Mail" /> <br /> </form> </body> </html> Hi - I have the following requirement for a textarea: Limit the number of lines to 8 Limit the number of characters to 20 per line Force a line beak when the user reaches he end of a line but break the line at the start of the last word (not half way through the word). Allow pasting into the field and auto-format the line/character count Keep he cursor where it should be (don't move it to the end of the field after any formatting) This is more complicated than it sounds - anyone worked on something similar? Hi, Have a dynamic table in JS that adds rows. Want a max of 8 rows. How can that be done? [CODE] <script language="Javascript" type="text/javascript"> function addRow() { var tbl = document.getElementById('ReqDtTbl'); var lastRow = tbl.rows.length; var iteration = lastRow; var row = tbl.insertRow(lastRow); var cellLeft = row.insertCell(0); var textNode = document.createElement('input'); textNode.size = 7; textNode.name = 'startdate' + iteration; cellLeft.appendChild(textNode); var cellRight = row.insertCell(1); var el = document.createElement('input'); el.type = 'text'; el.name = 'enddate' + iteration; el.id = 'enddate' + iteration; el.size = 7; cellRight.appendChild(el); // the last cell! var cellRightSel = row.insertCell(2); var sel = document.createElement('select'); sel.name = 'TypeHrs' + iteration; sel.options[0] = new Option('-Select-', '""'); sel.options[1] = new Option('Comp Time', 'Comp Time'); sel.options[2] = new Option('Credit Hrs', 'Credit Hrs'); sel.options[3] = new Option('Overtime', 'Overtime'); sel.options[4] = new Option('Rel Comp', 'RelComp'); cellRightSel.appendChild(sel); var cellRight = row.insertCell(3); var el = document.createElement('input'); el.type = 'text'; el.name = 'No. of Hours' + iteration; el.id = 'No. of Hours' + iteration; el.size = 7; cellRight.appendChild(el); } [CODE] John Hi, I want to have a textbox in which only numeric values will be allowed whose maximum limit is 240( 230.99 should be allowed). I am unable to do that. I am able to format the value entered by placing . in proper places and also I have limited upto two decimal places. But the problem is the cursor is not moving left when I have entered a value and I am unable to limit the value upto 240. It is taking any huge number also. Please help. My code is as below :- <html> <head> <script> function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } function format(input){ var num = input.value.replace(/\,/g,''); if(!isNaN(num)){ if(num.indexOf('.') > -1){ num = num.split('.'); if(num[1].length > 2){ num[1] = num[1].substring(0,num[1].length-1); } input.value = num[0]+'.'+num[1]; } else { input.value = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'') }; } else { input.value = ""; } } </script> </head> <body> <label for="time">Files staged in the last -</label> <input name="time" id="time" type = "text" value="24" onkeypress="return isNumberKey(event)" onkeyup="format(this);"/> <span>hours</span> </body> </html> |