Jump to content

AJAX, JS, PHP Predictive Text


billy_111

Recommended Posts

Woohoo!  :P

 

Yep that worked. Just to be picky, there is one final thing, because i have position:relative on the div wrapping the suggestive text, it is making it appear below the "Current" textbox, this is fine when a user is adding one author, then the second and third etc..

 

But..

 

Let's say someone comes along and clicks on "Add author" 6 times because they need to add 6 authors and start typing in the first one. What will happen in the blue suggestive text will end up appearing under the 6th textbox when typing in the 1st one  :-[

 

Can this be prevented in any way?

 

Thanks again..

Link to comment
Share on other sites

Is your demo page up to date, I'm not getting any suggestions and it works for me if I add 6 authors then click in the 1st input box and start typing the suggestion box appears underneath the 1st text box, however I don't get any suggestions when typing Peter.

Link to comment
Share on other sites

Sorry my table had only one record inside, try with "Jo.."..

 

I have noticed another problem, when you have more than one suggestion, (which you will when you type in "Jo..") I can't select the second and third option, only the first one. Maybe this is something i have done something to mess is up  >:(

 

Also can you see the drop down issue when typing into the 1st box and it appears under the 6th?

 

http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/admin/testing.php

Link to comment
Share on other sites

If you have a tool like Firebug, development is a lot easier. You can change things on the fly and look at how code is generated.

 

You still haven't updated your textbox.js file to what I have posted above. There are a few things still wrong with it, such as this:

 

onkeyup=\"suggest(this, inival, 'admin');\"

 

You need to break out of the string to write inival correctly.

 

onkeyup=\"suggest(this, '" + inival + "', 'admin');\"

 

I also surrounded it by single quotes. The same thing applies to the onblur next to it.

As for why you can only click the first name, it's something wrong with your PHP I'm assuming. Only the first <li> tag is being placed inside the <ul> tags, the rest are being placed outside the closing </ul> tag. You can see this by using Firebug.

Link to comment
Share on other sites

No problems Billy. I can spot a few things you should fix with your CSS.

 

In .AdminSuggestionsBox remove all margins, so margin is set to 0 and adjust the left and top appropriately so that it is positioned correctly. Also remove the top border as this is pushing the bottom list option down to far.

 

I think that was all, so that it positions correctly.

 

Glad to help Billy and hope its smooth sailing.

 

Good luck.

Link to comment
Share on other sites

Hi again,

 

One final final problem..

 

If you take a look at this link:

 

http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/admin/testing.php

 

And type in the box, if you type something that doesn't exist such as "John Barnes", the blue dropdown doesn't fade out, i have to either choose from the dropdown OR delete all the text..

 

Can i get around this?

 

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

Hi, I have another query about the autosuggest.  I use it with a search, however when the user types in an entry they have to click on one of the matching entries from the autosuggest list and then click on the submit button to perform the search.

 

The search query queries the database for any text in the search field.  I tried using 'document.search.submit' but this only searches for the data already in the textfield, for example if the user types 'a' and then clicks on 'apple' from the suggestions list they are shown results from the database that match 'a' rather than 'apple.'

 

I'm not silly, I know I can't use a JS onclick to call a PHP function.  I'm thinking this is an AJAX query, any ideas on how I would query the result the user clicks on rather than just what they've typed into the database and direct them automatically to the results rather than the need of the submit button?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.