Jump to content

On CLick fill with php


stn003801

Recommended Posts

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

	         			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.

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

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.

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

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?

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

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.