Ok, so I have been working on a liveseach checkbox array, got most things to work. However I am struggling with selecting an individual value in the search result and opening this.
I have managed to select the COLUMN and turn it into another href link.
However this href link applies to the WHOLE column rather that a specific record.
The code for the column is below. specific area of code:
$.each(this, function(k , v) {
if(k==="name"){
tbl_row += "<td><a href='http://www.nba.com'target='_blank'>"+v+"</a></td>";
} else {
tbl_row += "<td>"+v+"</td>";
}
});
Specific Script:
</div>
<script src="http://ift.tt/rs8qB8"></script>
<script>
function makeTable(data){
var tbl_body = "";
$.each(data, function() {
var tbl_row = "";
$.each(this, function(k , v) {
if(k==="name"){
tbl_row += "<td><a href='http://www.nba.com'target='_blank'>"+v+"</a></td>";
} else {
tbl_row += "<td>"+v+"</td>";
}
});
tbl_body += "<tr>"+tbl_row+"</tr>";
})
return tbl_body;
}
function getEmployeeFilterOptions(){
var opts = [];
$checkboxes.each(function(){
if(this.checked){
opts.push(this.name);
}
});
return opts;
}
function updateEmployees(opts){
$.ajax({
type: "POST",
url: "search.php",
dataType : 'json',
cache: false,
data: {filterOpts: opts},
success: function(records){
$('#employees tbody').html(makeTable(records));
}
});
}
var $checkboxes = $("input:checkbox");
$checkboxes.on("change", function(){
var opts = getEmployeeFilterOptions();
updateEmployees(opts);
});
updateEmployees();
</script>
<script>
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
if($(this).attr("value")=="apple"){
$("#car3").css("background-color", "yellow");
}
</script>
Previously in another script I wrote I used, however this was PDO/PHP and had no ajax/json/jquery;
while ($results = $query->fetch()) {
echo "<p><strong>Cook:</strong> <a href='".$results['url']."' target='_blank'>".$results['url']."</a>";
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo "<p><strong>Cook:</strong> <a href='".$results['url']."'> ".$results['url']."</a>";
echo "</td></tr>";
}
echo "</table>";
} else {
echo 'Nothing found';
}
?>
If the complete code is needed, feel free to ask
Aucun commentaire:
Enregistrer un commentaire