javascript - get the value of <select> without submitting on the same page using php -


hope can me.. made program more simpler understand.. want program value of without submitting, know can done javascript or jquery use onchange, want when select option value should passed on same page using php..

<select id="id_select" name="name" onchange="name_click()"> <option value="1">one</option> <option value="2">two</option> </select>  <script> function name_click(){ value_select = document.getelementbyid("id_select").value; } </script> 

and should pass value_select php in post method.. dont know how it.. please me..

you cannot using php without submitting page. php code executes on server before page rendered in browser. when user performs action on page (e.g. selects item in dropdown list), there no php more. way can code php submitting page.

what can use javascript value - , fire off ajax request php script passing selected value , deal results, e.g.

$(document).ready(function() {     $('#my_select').on('change', do_something); });  function do_something() {     var selected = $('#my_select').val();     $.ajax({         url:        '/you/php/script.php',         type:       'post',         datatype:   'json',         data:       { value: selected },         success:    function(data) {             $('#some_div').html(data);         }     }); } 

with code, whenever selected option changes in dropdown, post request fired off php script, passing selected value it. returned html set div id some_div.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -