php - How show checkbox value before submit OR there itself when ticked? -
i have following codes:
<form method="post"> <input type="checkbox" name="fruit[]" value="apple" id="apple" /><label for="apple">apple</label><br /> <input type="checkbox" name="fruit[]" value="pinapple" id="pinapple" /><label for="pinapple">pinapple</label><br /> <input type="checkbox" name="fruit[]" value="grapefruit" id="grapefruit" /><label for="grapefruit">grapefruit</label><br /> <input type="submit" name="go" /> </form> <?php $fruitlist = implode(', ', $_post['fruit']); echo $fruitlist; ?>
it show checked items after submit. possible show ticked items values inside input box before submitting.
the way can think of attach event checkboxes , display clicked ones on area. assuming using jquery
, code should this:
$('input[type=checkbox]').change(function() { // listen change on checkbox var checked = ''; $.each($('input[type=checkbox]:checked'), function(k, v) { // iterate through checked ones checked = checked + v + ' / '; // append value string } $('#display_results').html(v); // replace content of div, span, whatever });
load code on document.ready
, try tweak suit needs.
of course code needs change, basic idea this.
Comments
Post a Comment