开发者

Auto filling --Dropbox

i have two text type forms(id,name) and another f开发者_如何转开发orm dropbox type(school name)(select option type).

when user enters the id form, the remaining form (name) and the drop box(school name) needs to be filled based on the values in mysql.

filling form text type (name) is not a problem which i am able to do using json and jquery ,but i do not know how to auto select the dropbox.

any tutorials or code snippets suggestions are appreciated.


if your drop box is in xhtml, you can use the "selected" param.

with jquery, you could write semething like :

$("#optiontoSelect").attr("selected","selected");

More info in the jquery doc


I may have misunderstood the question. If you wish the focus to move from the input field to the select you would use .focus(). I would imagine you want to call focus on successful population of the select.

$('#select').focus();

or

$(this).focus();

jQuery Docs : focus()


This'll get you started:

<?php
$options = Array('red', 'green', 'blue');
$opt_from_db = 'green'; // for example

echo '<select name="fieldName">';
foreach ($options as $opt) {
   $selected = ($opt_from_db == $opt) ? ' selected' : '';
   echo "<option{$selected}>{$opt}</option>";
}
echo '</select>';
?>

The key is to write the selected attribute (in some form or another) into the programmatically-rendered HTML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜