views:

313

answers:

2

I Want to add Options to Select Box using jquery, but my options comes from MYSQL databse table

here is method what i want:

function add_inst(va) {
  alert(va);
}


<select id="test">

</select>

I want to select values from MySQL table with match value of va, then add these result as options to select id="test".

For example if i pass '12' to function add_inst like add_inst('12'), my SQL statement will be:

SELECT * 
  FROM tbl1 
 WHERE col1='12'

after all the values return from mysql will be add to select id="test" as options.

+2  A: 

The jQuery part of it?:

$('#test').append('<option value="'+va+'">'+va+'</option>');

(your question is pretty murky, by the way... you might want to clarify and reword a few things.)

brianreavis
A: 

A very vague question - but here is my attempt at an answer:

You're probably better off getting PHP to write these OPTIONS into the HTML itself. Unless it's content which needs to be loaded on the fly, in which case, you probably want to request the data using one of jQuery's easy to use AJAX functions, and use PHP to return either JSON or XML.

Sorry for the rather vague reply - but without knowing more about the question, it's difficult to reply in detail. If you post some more details, I'm sure the community could be of more help :)

slightlymore
what i want is:when i call function add_inst() and pass any value for example 2a php code run to select all records from mysql match with critaria 2and add selected records to test select box.Regards
air