mercredi 28 janvier 2015

Show or Hide HTML Table based on Checkboxes Data, Laravel 4

I have an HTML table with the days of a week



|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday|
|data |data |---- |---- |---- |---- |--- |


And have a Relation, Route-Client, and I whant to show(or not show) the columns days respect the value 1 from among a checkboxes from the Table Route. I save the checkboxes data with 0 and 1, working day 1, free day 0, and I'm extracting those 0 and 1 with this method:


Inside a Form::open()



<td>Route:</td>
<select id="day" name="day" onchange="showDays()">
@foreach($route as $ro)
<option value="{{ $ro['id'] .','. $ro['monday'] .','. $ro['tuesday'] .','. $ro['wednesday'] .','. $ro['thursday'] .','. $ro['friday'] .','. $ro['saturday'] .','. $ro['sunday'] }}">
{{ $ro['name'] }}
</option>
@endforeach
</select>
<input id="id_route" type=hidden name="id_route">


Javascript Method



function showDays() {

var day = $("#day").val();
alert(day);

var days= day.slice(-13);
alert(days);

//I pass the respective binary number to the respective day

var monday= document.getElementById("monday");
monday= day.slice(-13,-12);
$("#monday").val(monday); //don't know if this can help me in other javascript function
alert(monday);

var tuesday= document.getElementById("tuesday");
tuesday= day.slice(-11,-10);
$("#tuesday").val(tuesday);
alert(tuesday);

var wednesday= document.getElementById("wednesday");
wednesday= day.slice(-9,-8);
$("#wednesday").val(wednesday);
alert(wednesday);

var thursday= document.getElementById("thursday");
thursday= day.slice(-7,-6);
$("#thursday").val(thursday);
alert(thursday);

var friday= document.getElementById("friday");
friday= day.slice(-5,-4);
$("#friday").val(friday);
alert(friday);

var saturday= document.getElementById("saturday");
saturday= day.slice(-3,-2);
$("#saturday").val(saturday);
alert(saturday);

var sunday= document.getElementById("sunday");
sunday= day.slice(-1);
$("#sunday").val(sunday);
alert(sunday);

}


Inside my HTML table:



<tr><!--I been thinking on doing something like this -->
<th <a id="monday" onchange="showDays()" value="{{$route['monday']}}">MONDAY</th>
<th <a id="tuesday" onchange="showDays()" value="{{$route['tuesday']}}">TUESDAY</th>
<th <a id="wednesday" onchange="showDays()" value="{{$route['wednesday']}}">WEDNESDAY</th>
<th <a id="thursday" onchange="showDays()"value="{{$route['thursday']}}">THURSDAY</th>
<th <a id="friday" onchange="showDays()" value="{{$route['friday']}}">FRIDAY</th>
<th <a id="saturday" onchange="showDays()" value="{{$route['saturday']}}">SATURDAY</th>
<th <a id="sunday" onchange="showDays()" value="{{$route['sunday']}}">SUNDAY</th>
</tr>


If i do it like this i get on the Headers of the table the numbers 1,1,1,1,1,1,1 which are the binary values of the last Route created on my DB(for the moment don't know how to make change those values, just show the last created).


I need respect the values 1 or 0 received on my th to decide if show the column or not show it, but I don't know how to do that, if someone can help me I will be really grateful! Thanks!





Aucun commentaire:

Enregistrer un commentaire