0

Ok need some help here. I have an autocomplete setup to pull from a DB with all of the right info. I started working with dialog boxes and it worked once but stopped a little while after. Does anyone see why my autocomplete wouldn't fill in correctly in this file?

 function clientJob() {
 showDialog('<p>Enter your Client Job Code</p><input type="text" size="15" name="projectnumber" id="projectnumber" value="" /><br /><input type="button" onclick="isaclientjob()" value="Enter" />');
 } 
 $( document ).ready( 
 function()
 {showDialog('<p>Is this a client job?</p><br /><input type="button" onclick="clientJob()" value="Yes" /> <input type="button" onclick="nonclientJob()" value="No" />');
 } // function
 ) // submit
 $( '[name="projectnumber"]' ).autocomplete({
 source: "job_validate.php",
 minLength: 3
 });
 }
 );

job_validate.php

$output = array();
$job = new job;
$jobs = $job->get_from_db( "`code` LIKE '" . $_GET['term'] . "%' AND `active` = '1'",'code',10 );
foreach ( $jobs as $key => $current)
 {
 $output[$key]['value'] = $current->code . " " . $current->name;
 $output[$key]['id'] = $current->id;
 }
print_r($output);
echo json_encode($output);

Looked at the old version and reverted back to it and it seems to work fine in the first dialog box if I have the autocomplete in there but as soon as I go to the next dialog box it gets screwed up.

asked May 18, 2011 at 20:20
0

4 Answers 4

1

I noticed that you're outputting $output twice:

print_r($output);
echo json_encode($output);

Try commenting out the print_r($output); because it will mess up the JSON being transferred back to jQuery (since it's not valid JSON).

answered May 18, 2011 at 21:41
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks but I took that out at the start. Sorry that was just some error checking that forgot to take out.
@Mike Jones - You should update your post; it's there in your example.
@Mike Jones - Also, I noticed that your brackets don't line up. Are you missing something in your jQuery example?
1

Try:

 $( '[name="projectnumber"]' ).live('focus',function(){
 $(this).autocomplete({
 source: "job_validate.php",
 minLength: 3
 });
 });

Also remove the lines } //function and ) //submit

answered May 18, 2011 at 20:58

2 Comments

Yeah still getting nothing in return
Edited my response, added the 'focus' event to the live function. Working example without the job_validate.php: jsfiddle.net/8rsNB/1
1

I ended up using just one dialog box and going to different functions instead of multiple boxes. Thanks for everyones help.

answered May 19, 2011 at 18:07

1 Comment

Probably best to put this on as a comment on the accepted answer instead of a new answer.
0

Without seeing what is in job_validate.php it'll be rather difficult to answer. I would start by working back to where it was working. Adding in each line of code to see what's breaking it and then examining why.

answered May 18, 2011 at 20:43

1 Comment

@Mike - edit your original post and include it there; it's impossible to read code in a comment.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.