Skip to content Skip to sidebar Skip to footer

Js Change Select Name Based On Option Selection

I have a dynamic drop down menu where options are loaded from database, Now i need to change the attribute every time different option is selected from the drop down menu. To achi

Solution 1:

You can add "onchange" event and change the name whatever you like:

$('#Forex').change(function(){
    var val = $(this).val(); // you can get the value of selected option//you can process your conditions here

    $(this).attr('name', 'your_choice_name'); // this will change the name attribute
});

or you can do this from javascript

<selectid="Forex"name="abc"onchange="changeAttr(this);"><optionvalue="1">Option 1</option><optionvalue="2">Option 2</option></select><scripttype="text/javascript">functionchangeAttr(ele)
{
    var val = ele.value;
    var n = "";

    if(val == 1){
        n = 'xyz';
    } elseif(val == 2){
        n = 'abc';
    }
    ele.setAttribute('name', n);
}
</script>

Hope this will help you what you want...

Solution 2:

Use jquery, with a "onChange" event that will change the attribute you want with the selected item in the list.

jQuery get value of select onChange

Solution 3:

Hei! Not sure if I understood you, but you can use jQuery to manipulate attributes on change event. For event http://api.jquery.com/change/ To change atribute http://api.jquery.com/attr/

Post a Comment for "Js Change Select Name Based On Option Selection"