I was trying to adapt this example to do what I'm needing. I have a table of information where I'm wanting to implement the option of having an entire column set to the same value on a button click. Is this possible to do? I'd love a point in the right direction.
Just for the sake of giving an example. Say I have a 4 day gaming party I'm planning where the page looks like this. The drop down holds 3 options on attendance (Yes, No, Maybe). Every drop down is named dynamically depending on the day and person. So it would look sort of like my crude excel mockup. Ideally I'd like a button in the same area as the day marker that would mark everyone in a given day to "Yes" from the dropdown.
Yes, it's totaly posible. If you have access to the html, you could do something like this:
<script type="text/javascript"> $(document).ready(function() { $(".your-button-class").click(function() { var day_reference = $(this).attr("id"); $("." + day_reference + " select").val(day_reference); return false; }); }); </script>
I'm assuming 2 things:
If you're not using jQuery or a similar js library, then let us know what you're working on and we can help you.
click
method is for - Deleteman 2012-04-04 14:30
return false;
should stop your button's default action, and thus, work as you expect.. - Deleteman 2012-04-04 16:03
Well. I'd recommend to use JQuery to do these kind of things - like setting a lot of dropdowns to a given value.
<script type='javascript'>
$(document).ready(function() {
$('select#setall').change(function() {
$('.attendance').val($(this).val());
});
});
</script>
<select id="setall">
<option>Yes</option>
<option>No</option>
<option>Maybe</option>
</select>
Day 1:
<select class="attendace">
<option>Yes</option>
<option>No</option>
<option>Maybe</option>
</select>
Day 2:
<select class="attendace">
<option>Yes</option>
<option>No</option>
<option>Maybe</option>
</select>
Day 3:
<select class="attendace">
<option>Yes</option>
<option>No</option>
<option>Maybe</option>
</select>