Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Your information in this site is absolutely WONDERFUL. It is the most useful site on the web to me right now. Thank You Thank You..."

Geography

Where in the world do Tek-Tips members come from?
ag1060 (Programmer)
20 Jun 12 13:02
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.
Helpful Member!  jpadie (TechnicalUser)
20 Jun 12 13:17
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?
vacunita (Programmer)
20 Jun 12 13:32
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

ag1060 (Programmer)
20 Jun 12 13:37
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:

http://s8.postimage.org/e3g2bjvz7/ajax.png


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.

Helpful Member!  vacunita (Programmer)
20 Jun 12 13:43
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

ag1060 (Programmer)
20 Jun 12 13:46
I will try that. This should work :)

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close