Jump to content

How would I implement this version of a dynamic search?


Recommended Posts

Hi.  One thing that we have in our organization is a bunch of medical terms (the abbreviation and the long winded explanation).  What I'd like to do is put all of them in a MySQL database and then pull them all out, store that data in a hidden field (no, none of this should be kept private, so it's ok if it's like that) and then using a little JavaScript, search over the hidden data and then display it to the user.

 

Now, I can retrieve that stuff from the database, but what I'm having a hard time with is the searching the contents of a hidden field and then displaying it.  Thoughts?

 

If this isn't the right place for this post, please feel free to move it elsewhere.

Link to comment
Share on other sites

1. This doesn't have anything to do with searching.

2. How do you plan to hover over something that is hidden?

 

Are you trying to say you want to display an abbreviation, and when it's hovered over, display the long version?

 

Link to comment
Share on other sites

1. This doesn't have anything to do with searching.

2. How do you plan to hover over something that is hidden?

 

Are you trying to say you want to display an abbreviation, and when it's hovered over, display the long version?

No.  The data is retrieved from the database and is stored on the page in a hidden field.  The user cannot see this info.

 

However, there is a textbox that is displayed -- that -- as you type will display dynamically matching items.

Link to comment
Share on other sites

  • 3 weeks later...

1. This doesn't have anything to do with searching.

2. How do you plan to hover over something that is hidden?

 

Are you trying to say you want to display an abbreviation, and when it's hovered over, display the long version?

Why would I hover with the mouse over the abbreviation?  I'm not sure how you managed to interpret my post this way, I never even used that specific word in my post :) .

 

Basically it's supposed to be like this (I'm just making up random acronyms for the sake of an example):

FBI   Federal Bureau of Investigation
GPS   Global Positioning System
ATF   Bureau of Alcohol Tobacco and Firearms
etc.

 

This example can do the trick, but then I don't want my users to see the password that I'm using to access the database:

http://stackoverflow.com/questions/857670/how-to-connect-to-sql-server-database-from-javascript

 

What I'd like to do is dump this info into a JavaScript array using PHP.  I'm not very strong when it comes to JavaScript, so this part is what is holding me back.  How would I do this?  The table would be made up of 2 columns (the acronym and the explanation).

Link to comment
Share on other sites

What I'd like to do is dump this info into a JavaScript array using PHP.  I'm not very strong when it comes to JavaScript, so this part is what is holding me back.  How would I do this?  The table would be made up of 2 columns (the acronym and the explanation).

 

How would this hold you back? The syntax is simple, and well documented. I'd use a JS object, rather than a set of arrays.

 

<?php

$array = array(
'FBI'=>'Federal Bureau of Investigation',
'GPS'=>'Global Positioning System',
'ATF'=>'Bureau of Alcohol Tobacco and Firearms'
);

echo '<script type="text/javascript">var data=new Object;';
foreach( $array as $key => $value ) {
echo "data['$key']='$value';";
}
echo '
for( var i in data) {
document.write(i+"=>"+data[i]+"<br>");
}
</script>';

?>

 

Output

 

FBI=>Federal Bureau of Investigation
GPS=>Global Positioning System
ATF=>Bureau of Alcohol Tobacco and Firearms

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.