Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ajax - hidden input 2

Status
Not open for further replies.

ag1060

Programmer
Aug 26, 2011
27
US
Hello coders,

I'm trying to create this ajax live search and I need to pass on 'hidden' input type...

So here's where i'm stuck:

Code:
			$query = $db->query("SELECT pid, ptitle FROM projects WHERE ptitle LIKE '$queryString%' LIMIT 10");
				if($query) {
				
					while ($result = $query ->fetch_object()) {
						
	         			echo <<<EOF
					<li onClick="fill('$result->ptitle');">$result->ptitle</li>
					<input type="hidden" name="pid" value=$result->pid>
					
						
EOF;
	         		}
				}

So basically I need to pass the hidden input "pid" to each value. The 'fill' puts the data into the textbox and that part works fine. But I also need to add the hidden input 'pid'...So far it just displays the same 'pid' rather than the correct one depending on the result. I'm sure there's a better way to approach this. any clue?

thanks in advance.
 
no reason that I can see why the value would be the same for each <li>. The code looks correct (ish - see below). i suspect that the value in the database table must be the same so check the underlying data.

and change the code to the below

Code:
echo <<<EOF 

<li onClick="fill('{$result->ptitle}');">{$result->ptitle}</li> <input type="hidden" name="pid" value="{$result->pid}" /> 

EOF;

but I can't really see why you're doing this. why not just add the pid (if you need it) to the fill() method?
 
I'd say calling every hidden input "pid" will likely cause some confusion when accessing the actual value.

I agree with jpadie, that passing the pid value to the fill function may be a better choice.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Hello,

Thanks for replying. It does work when I put on the 'fill' part. I don't want the 'pid' to be displayed to the user since I only want the user to select the result. Here's a screenshot of what I have:



So basically I want the 'pid' to be hidden so the user would only see the title they have chosen. This way I could just fetch the pid from the table and display.
 
So what's the problem?

Just passing the value to the fill function won't show the value anywhere but in the function call.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top