开发者

Show a text value after making a selection in a drop down box

I'm building a web-app that allows people to select their US state from a drop-down box, displaying a telephone numbe开发者_如何学JAVAr for that area, however I'm having some difficulty doing so.

I've built the rest of the site in PHP and realise that this is a client side action, so I'd need to use JavaScript or Jquery.

Each state has a different number, so for example when Columbia is select I want to show the number for Columbia in a div next to the text box.

The values can be stored in a MySQL database if needed.

Any help would be greatly appreciated.


When you pull the data out to put into the drop down box store the telephone number as the 'value' of each option.

Then you can just set the div text to be $('getCheckBox').val().


$('dropdown').change(function(){
    id = $(this).val();
    myFucntionDoToWhateverIwantItToDo(id);
});

function myFucntionDoToWhateverIwantItToDo(id){
    // Do stuff in the div, baby. The ID is stored in id.
    $("div").empty().append(id);
}

Obviously replace dropdown and div with their real ids or classes

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜