html - Update <p> when selection is submitted jquery -


i trying figure out how change p#switch-on-id when user selects option clicks submit.

the jquery switches p#switch-on-id when user clicks option if selects option switches without pressing submit. need switch when user clicks submit.

thanks help!

<p id="switch-on-submit">hello</p>      <select multiple="no">         <option selected="selected">one</option>         <option>two</option>         <option>three</option>         <option>four</option>    </select>    <button id="submit">     add    </button>  $(document).ready(function(){      $(document).on('click', '#submit', function(){         $("select").change(function(){            $("select option:selected").each(function(){            str = $(this).text();        });        $("p#switch-on-submit").text(str);        }).change();         });  }); 

here jsfiddle

try this: https://jsfiddle.net/0x7kg43n/

hope understood correctly. need onclick event button. inside event selected text select box , add text p-element.

$('#submit').click(function(){ $("p#switch-on-submit").text($("select option:selected").text());  }); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -