jcrowson
jcrowson

Reputation: 4290

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

Upvotes: 1

Views: 778

Answers (2)

dotty
dotty

Reputation: 41433

$('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

Upvotes: -1

Michael Wright
Michael Wright

Reputation: 591

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

Upvotes: 3

Related Questions