how to populate text field when a drop down list item from another field is selected?

Today, We want to share with you populate textbox based on dropdown selection javascript.In this post we will show you change textbox value based on dropdown value selected javascript, hear for how to populate text field when a drop down list item from another field is selected? we will give you demo and example for implement.In this post, we will learn about jquery autocomplete multiple fields using jquery ajax php and mysql with an example.

How to auto populate textbox value from database based on selecting related value from dropdown list?

HTML code


Email:

Counties:

jQuery Code

function updateSetEmailAddress(){
    var ddl = document.getElementById("somemembers");
    var selectedOption = ddl.options[ddl.selectedIndex];
    var liveMemberData = selectedOption.getAttribute("data-livemember");
    var textBox = document.getElementById("customer_email_address");
    if(liveMemberData=="1"){
    	textBox.value = "first@customer_email_address.com";
    }
    else if(liveMemberData=="2"){
    	textBox.value = "second@customer_email_address.com";
    }   
}

Example

index.html









Email:

Counties:

I hope you get an idea about auto populate textbox based on a dropdown value.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment