air
air

Reputation: 6264

Jquery Add Values to Select

I want to add Options to Select Box using jquery, but my options comes from a MYSQL database 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 added to select id="test" as options.

Upvotes: 2

Views: 1803

Answers (2)

clinton3141
clinton3141

Reputation: 4841

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 :)

Upvotes: 0

brianreavis
brianreavis

Reputation: 11546

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.)

Upvotes: 4

Related Questions