jquery - Check which dynamic buttons (input type button) the user has click on server side php -
first of want of guys helping every day , answering questions. have save me lot of time , have learn lot.
i have let's buttons on form.
<button type="button" value="adventurous" name="adv" id="adv">adventurous</button> <button type="button" value="discovery" name="disc" id="disc">discovery</button> <button type="button" calue="easy-going" name="easy" id="easy">easy-going</button>
when user clicks on button specify how feels in our example have follow code on jquery change state of button checked , change class (to shown different colors etc)
$(".tailor_field .tailor_mood_btn button").click(function() { var checked = $(this).attr('checked'); $the_image = $(this).find("img"); if(checked){ $(this).removeclass("mood_on"); $(this).attr('checked', false); $the_image.attr("src", templatedir+"/images/btn_on.png"); } else{ $(this).addclass("mood_on"); $(this).attr('checked', true); $the_image.attr("src", templatedir+"/images/btn_off.png"); } });
so when user press submit want check on server side (php) buttons user clicked ?
second insert buttons dynamically. ie have string on db, explode array , loop each element create buttons etc. how know check if don't know how many buttons , names beginning ? maybe sessions (i avoid if there solution)?
thanks lot!
i way:
var checkedbuttons = $(".tailor_field .tailor_mood_btn button[checked=true]"); $("form").submit(function() { var data = []; checkedbuttons.each(function(index, element) { var name = element.attr('name'); var value = element.val(); data[name] = value; }); $.post('file.php', data); });
the data variable array keys names of clicked buttons, values of values of buttons. later ajax request made file needs data (file.php) data array available in superglobal $_post (ex. $_post['adv'] = "adventurous"
)
Comments
Post a Comment