unable to pass a link variable inside append in jquery - php

I have a fetch the JSON records from the database I need to link a href tag to the code but unable. Whats wrong with me? In a console, I see simple td without a href tag.
htmlData += '<tr><td><a href="base_url + "'order/getWork/'" + ord_id">'
+ord_item_Json_string[i].code+'</a></td>
<td>'+ord_item_Json_string[i].item+'</td>
<td>'+ord_item_Json_string[i].size+'</td>
<td>'+ord_item_Json_string[i].color+'</td>
<td>'+ord_item_Json_string[i].qty+'</td><td>'+"New Order"+'</td>
<td><button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myModal" id="create-jobcard">Create Card</button></td>
</tr>';
$('#OrdItem tbody').empty();
$('#OrdItem tbody').append(htmlData);

you have a problem with quotations marks( "" / '' ) try this out,
htmlData += '<tr><td><a href="'+base_url+'order/getWork/" + ord_id">'
+ord_item_Json_string[i].code+'</a></td>
<td>'+ord_item_Json_string[i].item+'</td>
<td>'+ord_item_Json_string[i].size+'</td>
<td>'+ord_item_Json_string[i].color+'</td>
<td>'+ord_item_Json_string[i].qty+'</td><td>'+"New Order"+'</td>
<td><button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myModal" id="create-jobcard">Create Card</button></td>
</tr>';
hope this helps

Related

Text has space to the right

I have the following code:
<div class="brm-item-name">204 Banane, Milch & Erdbeeren <button type="button" class="btn btn-info btn-xs" id="pop" data-toggle="modal" data-target="#myModal"></button></div>
"204 Banane, Milch & Erdbeeren " is pulling from database but text does not have a space in the database. The space here is giving me trouble when writing css. Do you have any suggestions on this?
You can remove it using jQuery trim().
jQuery(document).ready(function($) {
$('.brm-item-name').trim();
})

Prevent quotation in window.open in PHP

I'm having a problem with my script. The file wont open if the filename has single quote.
Is there a way to prevent single quote in window.open?
<a class="btn btn-primary btn-xs" onclick="window.open('content_files/<?php print($contRow['cont_file']); ?>','<?php print($contRow['cont_file']); ?>','height:auto;width:auto;')">
<i class="glyphicon glyphicon-edit"></i> View
</a>
here's the output
7TATTOOED ON MY MIND CHORDS (ver 2) by D'Sound # Ultimate-Guitar
Sample Output 1.
Sample Output 2.
You should encode your filename I think:
urlencode($contRow['cont_file'])
I tried this code:
<a class="btn btn-primary btn-xs" onclick="window.open('content_files/<?php print(addslashes($contRow['cont_file'])); ?>','<?php print(addslashes($contRow['cont_file'])); ?>','height:auto;width:auto;')">
<i class="glyphicon glyphicon-edit"></i> View
</a>
and It works like a charm. thanks anyway. Credits to the one who deleted he's post but it works.

PHP AJAX button click counter

i want to make a button click counter. When you click the button the text from it changes, when the button is clicked i want to write to the database but i can't manage this.
<button type="button" class="btn btn-info" style="width:90%;" id="textChanger" onclick="counter;"><h4><i class="glyphicon glyphicon-earphone" aria-hidden="true"> </i> XXXX XXX XXX <h6>Show Number</h6></h4></button>
document.getElementById("textChanger").onclick= function(){
document.getElementById("textChanger").innerHTML="<h4><i class=\"glyphicon glyphicon-earphone\" aria-hidden=\"true\"> </i> <?php echo $nrTelefonAnunt ?> </h4>";
}
this is the code that i manage the text change, now what can i do to write to the database, i tried some methods but none worked
Thanks everybody for the answers i manged by adding this:
$('#textChanger').click(function(){
$.ajax({
url : 'rate.php?idanunt="<?php echo $idAnunt ?>"',
type : 'post',
success : function(data){
}
});
});
Try this
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<button type="button" class="btn btn-info" style="width:90%;" id="textChanger" onclick="counter;">1</button>
<script>
document.getElementById("textChanger").onclick= function(){
var count = document.getElementById("textChanger").innerHTML;
count = parseInt(count) + 1;
document.getElementById("textChanger").innerHTML=count;
}
</script>
Try this
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script>
<button type="button" class="btn btn-info" style="width:90%;" id="textChanger" onclick="counter;"><h4><i class="glyphicon glyphicon-earphone" aria-hidden="true"> </i> <span>XXXXX</span> <h6>Show Number</h6></h4></button>
<script>
count=0;
$(document).on("click","button",function(){
count++;
$('span').text(count);
});
</script>

Data table column with if else condition

I want to make my one column with if else condition when data table render.
I am using laravel 4.2
my current code is
$result = DB::table('flowers')
->select('flowers.id as id', 'flowers.name as name',
'flowers.price as price',
'flowers.description as description','flowers.quality as quality',
'flowers.picture as picture','flowers.visibility_status as visibility_status');
return Datatables::of($result)
->edit_column('visibility_status', '<button type="button" onclick="activeFunction({{ $id }})" class="btn btn-primary bpad">Make Featured</button>')
->edit_column('picture', '<img src="{{ $picture }}" alt="flower Image" height="150">')
->add_column('edit', '<i class="icon-list-alt"></i>Edit')
->add_column('delete', '<i class="icon-trash"></i>Delete')
->make();
i want visibility_status column implement with if else condition like
if($visibility_status==1)
{
<div id="active454">
<button type="button" onclick="activeFunction(454)" class="btn btn-primary bpad">Make Featured</button></div>
<div id="block454" style="display:none"><button type="button" onclick="blockFunction(454)" class="btn btn-danger bpad">Make Unfeatured</button></div>
}
else
{
<div id="active454" style="display:none">
<button type="button" onclick="activeFunction(454)" class="btn btn-primary bpad">Make Featured</button></div>
<div id="block454" ><button type="button" onclick="blockFunction(454)" class="btn btn-danger bpad">Make Unfeatured</button></div>
}
Is it possible
I am not familiar with laravel but will risk it.
CSS
.hide{display:none;}
PHP Init
$class1 = array('class="hide" ','');
$class2 = array('','class="hide" ');
In PHP HTML generation
<div id="active454" $class1[$visibility_status]>
<div id="block454" $class2[$visibility_status]>
If $visibility_status is ambiguous as far as data type or null use:
$classX[intval($visibility_status)]

CodeIgniter ajax post only working once

Hello I'm trying to delete a row in the database using ajax post but the problem is that the row gets deleted only once per page load. The row get detach from the HTML DOM everything I press the delete button, but the database only deletes one record. I want to delete therecord in the database every time I press the delete button. How can I achieve this ?
My view
<tbody id="tbody"><?php
$count = 1;
foreach($rows as $row):?>
<tr>
<td><?=$count?></td>
<td><a href="basic_table.html#">
<?=$row->FirstName." ".$row->LastName?></a>
</td>
<td class="hidden-phone"><?=$row->Email?></td>
<td><?=$row->Password?></td>
<td><span class="label label-warning label-mini">
<?=date("m/d/Y", strtotime($row->Created))?></span>
</td>
<td>
<button class="btn btn-success btn-xs">
<i class="fa fa-check"></i></button>
<button class="btn btn-primary btn-xs">
<i class="fa fa-pencil"></i>
</button>
<button id="delete" data-id="<?=$row->id?>"
data-url="<?=base_url()?>" class="btn btn-danger
btn-xs"><i class="fa fa-trash-o "></i>
</button>
</td>
</tr><?php
$count++;
endforeach?>
</tbody>
script
$(document).ready(function()
{
$("#tbody").on('click','#delete', function()
{
var id = $("#delete").data("id");
var url = $("#delete").data("url");
$.post(url + "users/delete", { id : id, cache: false } , function()
{
},"json");
$(this).closest('tr').detach();
});
});
Please give the codeigniter controller script
You must change to anchor tag and add preventDefault() to prevent reloading page
$(document).ready(function(){
$("#tbody").on('click','#delete', function(e){
//You must add e.preventDefault() to avoid reloading page
e.preventDefault();
var id = $("#delete").data("id");
var url = $("#delete").data("url");
$.post(url + "users/delete", { id : id, cache: false } , function(){
},"json");
$(this).closest('tr').detach();
});
});

Categories