stn003801 Posted April 21, 2010 Share Posted April 21, 2010 Hi all, I have a form which is auto filled from a mysql look up, which works fine, however from one look up i want to populate three fields. At present i can fill any field i want by changing the fill in the php script to correspond to either of the three fields. the problem is i can not work out how define the results from php, In the scrip below you can see that i have added fill 1 and fill12 which correspond to two form fields, with this script it fills in the second form field (Fill12) with the products model number but leaves the first field (fill1) empty. What i am trying to do is have (fill1) display the product model number and fill12 the product name. I have spent a day on this and just can not seem to get anywhere. echo '<li onClick="fill;fill12(\' '.$result->products_model.'\');">'.$result->products_model.' '.$result->products_name.'</li>';'fill12(\' '.$result->products_model.'\');">'.$result->products_model.' '.$result->products_name.'</li>'; Any ideas would be greatly appeciated. Thanks Stan Link to comment https://forums.phpfreaks.com/topic/199235-on-click-fill-with-php/ Share on other sites More sharing options...
andrewgauger Posted April 21, 2010 Share Posted April 21, 2010 echo '<li onClick="fill;fill12(\' '.$result->products_model.'\');">'.$result->products_model.' '.$result->products_name.'</li>';'fill12(\' '.$result->products_model.'\');">'.$result->products_model.' '.$result->products_name.'</li>'; What Javascript function are you calling to fill the first one? If it is "fill" you need a () after fill If it is "fill1" you need to put a 1() after fill If it requires arguments you need ($arg) after fill. Link to comment https://forums.phpfreaks.com/topic/199235-on-click-fill-with-php/#findComment-1045911 Share on other sites More sharing options...
stn003801 Posted April 22, 2010 Author Share Posted April 22, 2010 Hi Thanks for the reply, much appreciated, i tried the code but it's just the same, with regards to calling the first javascript, i use fill(thisValue) and then add say a one after the fill like you mentioned. Here is a link to the page: http:www.pestcontrolonline.net/lookup/index.htm As you will see it puts the product code in to the second box, when i want the product code in to the first box and then the product name in the second. Thanks Stan Link to comment https://forums.phpfreaks.com/topic/199235-on-click-fill-with-php/#findComment-1046321 Share on other sites More sharing options...
andrewgauger Posted April 22, 2010 Share Posted April 22, 2010 What I'm trying to tell you is you call the same function twice. The first reference should be to fill1() and the second to fill2(). you are over writing the value by calling the same function twice. Oh, and it just errors on IE and does nothing on Chrome for me. FYI. Link to comment https://forums.phpfreaks.com/topic/199235-on-click-fill-with-php/#findComment-1046422 Share on other sites More sharing options...
stn003801 Posted April 22, 2010 Author Share Posted April 22, 2010 Hi Thanks, I get that much but i just don't know where, as i have the fields and the fills all named differently like you said fill, fill12, fill13 each have (this.Value)after them, so i assume that the php side of it is alright with the modified code you supplied, and that my error now lies in the way the javascript is working. Thanks for the update as well what version of ie did you use as it works in mine a little untidy but it functions once again thanks Stan Link to comment https://forums.phpfreaks.com/topic/199235-on-click-fill-with-php/#findComment-1046451 Share on other sites More sharing options...
andrewgauger Posted April 22, 2010 Share Posted April 22, 2010 Here is where I am confused. On the website you quoted the function is: function fill2(thisValue) { $('#inputString2').val(thisValue); setTimeout("$('#suggestions2').hide();", 200); } and I cannot find any: <li onClick="fill;fill12( So..... what I wanted to let you know is on the website url you provided, the functions you describe are not executing, and the code you are having trouble with is not there. Would you help me understand how these two itemes correlate? Link to comment https://forums.phpfreaks.com/topic/199235-on-click-fill-with-php/#findComment-1046499 Share on other sites More sharing options...
stn003801 Posted April 22, 2010 Author Share Posted April 22, 2010 ok, on the index.htm page it has the following javascript function lookup(inputString) { if(inputString.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else { $.post("rpc.php", {queryString: ""+inputString+""}, function(data){ if(data.length >0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } // lookup function fill1(thisValue) { $('#inputString').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } function fill2(thisValue) { $('#inputString12').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } function fill3(thisValue) { $('#inputString13').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } Which calls the rpc.php file which has the following code. $db = new mysqli('localhost', '' ,'', ''); if(!$db) { echo 'ERROR: Could not connect to the database.'; } else { if(isset($_POST['queryString'])) { $queryString = $db->real_escape_string($_POST['queryString']); if(strlen($queryString) >0) { $query = $db->query("SELECT products.products_model, products.products_id, products.products_price, products_description.products_name FROM products JOIN products_description ON products_description.products_id = products.products_id WHERE products_model LIKE '$queryString%' LIMIT 10"); if($query) { while ($result = $query ->fetch_object()) { echo '<li onClick="fill1;fill2(\' '.$result->products_model.'\');">'.$result->products_model.' '.$result->products_name.' '.$result->products_price.'</li>';'fill2(\' '.$result->products_name.'\');">'.$result->products_name.'</li>'; } } else { echo 'ERROR: There was a problem with the query.'; } } else { } } else { echo 'There should be no direct access to this script!'; } } Thanks for your help. stan Link to comment https://forums.phpfreaks.com/topic/199235-on-click-fill-with-php/#findComment-1046509 Share on other sites More sharing options...
andrewgauger Posted April 22, 2010 Share Posted April 22, 2010 So I went and got Firefox and it still doesn't work. I have a bluecoat appliance between me and the internet and it must be stopping me from accessing the page. So here is what I can tell you: 1. Your text boxes are: inputstring inputstring12 inputstring13 2. Your fill functions are: fill fill12 fill13 3. The line you reference executes fill12($result->products_model) on Click but 'fill2(\' '.$result->products_name.'\');" is not inside the onClick. What I think you want to do is replace: onClick="fill1;fill2(\' '.$result->products_model.'\');" replace wtih: onClick="fill12(\''.$result->product_id.'\');fill13(\''.$result->product_model.'\');" and remove: ;'fill2(\' '.$result->products_name.'\');">'.$result->products_name.'</li> from the end of the line. Link to comment https://forums.phpfreaks.com/topic/199235-on-click-fill-with-php/#findComment-1046579 Share on other sites More sharing options...
stn003801 Posted April 23, 2010 Author Share Posted April 23, 2010 The problem with that peice of code is that it is the end part that provides the list of results and so by removing that there is no look up list. ANyway i have tried re-writing it so many times i am just so lost now as no changes seem to make any difference is till can not get the info to go into the first and second boxes and so i think i will just start again and see how that fares. Thanks for your help, much appreciated. Stn Link to comment https://forums.phpfreaks.com/topic/199235-on-click-fill-with-php/#findComment-1047141 Share on other sites More sharing options...
andrewgauger Posted April 23, 2010 Share Posted April 23, 2010 I would rewrite it so that a single function takes multiple arguments and fills multiple text boxes. Link to comment https://forums.phpfreaks.com/topic/199235-on-click-fill-with-php/#findComment-1047155 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.