Why is it that my onClick won't work?
When I click I get an error message like this:
syntax error : identifier starts immediately after numeric literal
It will not determine the ID from the database, the database ID is varchar(50).
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].")'></a>
<script type="text/javascript">
function delete_Affiliate(id){
alert(id);
}
</script>
Try this:
delete_Affiliate(" <?php echo $row['affiliateid']; ?>")
That is, you need to echo the value from PHP.
Try this
<script type="text/javascript">
function delete_Affiliate(id){
alert(id);
}
Can you please post your PHP script ?
You should have something like :
<?php
echo "<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(\"".$row['affiliateid']."\");return false;'></a>
<script type='text/javascript'>
function delete_Affiliate(id){
alert(id);
}
</script>";
?>
try this :
<?php
echo "<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].");'></a>";
?>
or this :
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid'] ?>");'></a>
you have to add php tag and echo statement between your anchor tag like this
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid']; ?>")'></a>
you didn't add this
<?php echo $row['affiliateid']; ?>
in your anchor tag so just add it and check it out.
I hope it will help you
Try this
delete_Affiliate(<?php echo $row['affiliateid']; ?>);
there may be issue on this line
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].")'></a>
it should be
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid']; ?>")'></a>
Use this code, hope it will work
Related
Problem
When i click this link its alert won't open what should I do ?
My Code
echo "<td><a href='#' onClick='alert('Not an Enumerator!')'>Location</a></td>";
You have to escape quotes \' when necessary, try this:
echo '<td>Location</td>';
Try By Following Example.
<a href="#" onClick='alert("Not an Enumerator!")'>Location</a>
Don't Use Single quote inside alert
Try below example you can do both alert and onclick or either based on return type of function called on click.
<?php
echo "<td><a href='test.php' onclick='return test_click();'>Location</a></td>";
?>
<script type="text/javascript">
function test_click(event){
alert("Inside this function");
return true;
}
</script>
I have A VERY OLD SCRIPT that I need to modify. You will notice from the code it is using mysql_query() which is outdataed however that is not my issue.
I have a text link in a file named surveycommentslist.php. The link opens a jquery model window that I need to capture a user inputed text in and then save it to a mysql along with the value of the links data-id which tells me which unique user ID to connect the comment to. My issue is I am not able to get the value of data-id using the code I have below.
Here is my code
<html>
<head>
<!-- common scripts -->
<!-- jQuery library -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.js"></script>
<!-- jQuery migrate -->
<script src="js/jquery-migrate-1.2.1.min.js"></script>
<!-- bootstrap framework plugins -->
<script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<script>
$(document).on('click', '.reply', function()
{
//get acommentuid
var val = $(this).attr('data-id');
$.post('surveycommentslist.php', {acommentuid: val}, function(data)
{
console.log(data);
});
});
</script>
<?php
//lets list comments
$scommentsql = mysql_query("SELECT * FROM survey_comments
WHERE surveyid=$surveyid ORDER BY commentdate asc");
while($scrows = mysql_fetch_array($scommentsql))
{
extract($scrows);
$the_comment = stripslashes($the_comment);
$commentdate = date("m/d/Y h:ia", strtotime($commentdate));
if($touid > 0) { $indent = "margin-left:35px"; }
//get name of person making the comment
$nsql = mysql_query("SELECT fname, lname, userlevel, id AS scommentid FROM users WHERE id=$uid LIMIT 1");
$namerow = mysql_fetch_array($nsql);
$commenters_fname = stripslashes($namerow['fname']);
$commenters_lname = stripslashes($namerow['lname']);
if($namerow['userlevel'] > 19)
{
$adminicon = "<img src='./img/admin_smicon.png' alt='admin'>";
}
echo "<div class='ch-message-item clearfix' style='$indent'>
<div class='ch-content'>
$the_comment
</div>
<p class='ch-name'>
<strong>$adminicon $commenters_fname $commenters_lname</strong>
<span class='muted'>$commentdate</span>";
if($touid == 0)
{
echo " <a href='#switch_modal' class='reply btn btn-default id='$scommentid' btn-small' data-toggle='modal' data-id='$scommentid'>REPLY</a>";
}
echo "</p>
</div>";
}
$(document).on('click', '.reply', function(e)
{
e.preventDefault();
//get acommentuid
var val = $(this).data('id');
$.post('surveycommentslist.php', {acommentuid: val}, function(data)
{
console.log(data);
});
});
Class attribute is not closed properly. Quotes issue.
Change this
echo " <a href='#switch_modal' class='reply btn btn-default id='$scommentid' btn-small' data-toggle='modal' data-id='$scommentid'>REPLY</a>";
to
echo "<a href='#switch_modal' class='reply btn btn-default' id='$scommentid' btn-small' data-toggle='modal' data-id='$scommentid'>REPLY</a>";
Maybe there's just an issue with the single and double quote in the REPLY. You said $scommentid has a value, so I assume there's just an echo problem. Try these:
//codes
.
.
//RE-POSITION class values from id value
echo "<a href='#switch_modal' class='reply btn btn-default btn-small' id='$scommentid' data-toggle='modal' data-id='$scommentid'>REPLY</a>";
//or by concatenation if I am wrong with the above solution
echo "<a href='#switch_modal' class='reply btn btn-default id=".'"$scommentid"'." btn-small' data-toggle='modal' data-id='$scommentid'>REPLY</a>";
//or by using the " if I am wrong with the above solutions
echo "<a href='#switch_modal' class='reply btn btn-default id="$scommentid" btn-small' data-toggle='modal' data-id='$scommentid'>REPLY</a>";
.
.
//codes
When I copy-paste your code in a file & execute that in a browser, it shows the "data-id" attribute as blank: http://screencast.com/t/pasXI14dp0x . That is due to the incorrect HTML pointed out in earlier messages.
Even after the corrections, there is still the 'btn-small' text which is not in any attribute.
The incorrect HTML is:
echo " <a href='#switch_modal' class='reply btn btn-default id='$scommentid' btn-small' data-toggle='modal' data-id='$scommentid'>REPLY</a>";
The correct HTML should be:
echo " <a href='#switch_modal' class='reply btn btn-default btn-small' id='$scommentid' data-toggle='modal' data-id='$scommentid'>REPLY</a>";
Another alternative you could try is hardcode some value in the "data-id" attribute & find out if it's being passed. If that works, then the issue is with the HTML & should be fixed with above corrected HTML code.
Your HTML markup is wrong
You can check that by doing a view source
Change the following code
echo " <a href='#switch_modal' class='reply btn btn-default id='$scommentid' btn-small' data-toggle='modal' data-id='$scommentid'>REPLY</a>";
with
echo "<a href='#switch_modal' class='reply btn btn-default btn-small' id='$scommentid' data-toggle='modal' data-id='$scommentid'>REPLY</a>";
I would suggest to you to return the data from MySQL as JSON using return json_encode($data) which $data is an array of key-value pairs and when you get the data in your script tag / JavaScript, just build the HTML there and add it to a div instead of returning HTML from the server.
When you build your HTML in your script tag / JavaScript, you add the data from the JSON response and loop over the comments.
Maybe that's just me but I like clean code :)
this is my html table part.. popup will open when i click on my update button.
<?php
{
include("config/dbconfig.php");
$res = mysql_query("SELECT * FROM tbl_company");
echo"<table>";
while($row=mysql_fetch_array($res))
{
$s= $row['company_id'];
$r= $row['company_name'];
$a= $row['head_office_city'];
echo"<tr><td>".$r."</td><td>".$a."</td>
<td><img title='update details' alt=\"Delete\" class='del' src='images/update.png'/> </td>
<td><img title='make company inactive' alt=\"Delete\" class='del' src='images/delete.png'/> </td></tr>";
}
echo"</table>";
}
?>
<div id="toPopup">
<div class="close"></div>
<span class="ecs_tooltip">Press Esc to close <span class="arrow"></span></span>
<div id="popup_content"> <!--your content start-->
this is the kind of popup that i'm using
in this popup rest part of editing company details should be done. for that I need to get company_id.
How I get this $company_id value to popup page?
You can write it like you PHP code like this
<td>
<a href=\"#\" class=\"topopup\" id=\"update_comp\" onclick=\"return openPoup('".$row['company_id']."')\" \">
<img title='update details' alt=\"Delete\" class='del' src='images/update.png'/>
</a>
</td>
and in JavaScript you can write
<script type="text/javascript">
function openPoup(companyId){
window.open('/editcomapny.php?comapnyId='+companyId);
}
</script>
<td><a href=\"#\" class=\"topopup\" id=\"update_comp\" onClick=\"return callYourPopup(".$row['company_id'].");\">
<script type="text/javascript">
function callYourPopup(id) {
alert("Do something with " + id);
return false;
}
</script>
I have this php code to populate with links:
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $result)
{
if($result['tip']=='1')
{
$camere=" - ".$result['camere'];
}
else
{
$camere="";
}
$view[]="
<tr>
<td>".$result['id_anunt']."</td>
<td>".$result['den_tranzactie']."</td>
<td>".$result['den_prop'].$camere."</td>
<td>".$result['judet']." ".$result['oras']." ".$result['zona']."</td>
<td><a href='#' id='".$result['id_anunt']."' onclick='view();'>View</a> <a href='#' id='".$result['id_anunt']."'>Edit</a> <a href='#' id='".$result['id_anunt']."'>Arhivare</a> <a href='#' id='".$result['id_anunt']."'>special</a></td>
</tr>";
}
I need to get the id attribute for "View" link on click it with this function:
function view()
{
alert ($(this).prop('id'));
}
but I receive this: "object HTMLinputelemnt".
How can I get the id?
Thanks a lot.
Put a Class on your link.
Eg:
<a href="#" class="viewLink" id="....
Then in jquery:
$(".viewLink").click(function() {
var id = $(this).attr('id');
alert(id);
});
Modify your
onclick='view();'
to
onclick='view(this);'
And the view function as
function view(link)
{
alert ($(link).attr('id'));
}
use
$view[]="
<tr>
<td>".$result['id_anunt']."</td>
<td>".$result['den_tranzactie']."</td>
<td>".$result['den_prop'].$camere."</td>
<td>".$result['judet']." ".$result['oras']." ".$result['zona']."</td>
<td><a href='#' id='".$result['id_anunt']."' onclick='return view(this);'>View</a> <a href='#' id='".$result['id_anunt']."'>Edit</a> <a href='#' id='".$result['id_anunt']."'>Arhivare</a> <a href='#' id='".$result['id_anunt']."'>special</a></td>
</tr>";
Javascript
function view(element){
alert (element.id);
return false;
}
OR
alert ($(link).attr('id'));
Make sure you pass the link object as a parameter to view(), like this: onclick='view(this);'
Then in pure javascript:
function view(el)
{
alert(el.id);
}
"Don't use a canon to kill a mosquito". -- Confucius
I'm trying to put popup message in this code before user delete data. Here is my code.
while ($test = mysql_fetch_array($result))
{
$id = $test['FailID'];
echo "<tr align='center'>";
echo"<td><font color='black'>" .$test['FailID']."</font></td>";
echo"<td><font color='black'>" .$test['TajukFail']."</font></td>";
echo"<td><font color='black'>". $test['JilidFail']. "</font></td>";
echo"<td><font color='black'>". $test['StatusFail']. "</font></td>";
echo"<td> <a href ='daftarkemaskini.php?FailID=$id'>Edit</a>";
echo"<td> <a href ='padamfail.php?FailID=$id'><center>Delete</center></a>";
echo "</tr>";
}
but when I put it in there it doesnt work at all.
echo"<td> <a href ='padamfail.php?FailID=$id' onClick="return confirm('are you sure you want to delete??');"><center>Delete</center></";>"
Can anyone help me on this?
You need to escape the double quotes. Your code also had another syntax error at the end.
echo "<td> <a href='padamfail.php?FailID=$id' onClick=\"return
confirm('are you sure you want to delete??');\"><center>Delete</center></a>";
You are putting javascript onclick code inside a double quote, which is being used to terminate the echo. Escape the double quotes:
echo"<td> <center>Delete</center>"
You can try this--
echo "<td> <a href ='padamfail.php?FailID=$id' onClick=return confirm('are you sure you want to delete??');><center>Delete</center></;>";
Try to escape the string:
echo "<td> <a href ='padamfail.php?FailID=$id' onClick=\"return confirm('are you sure you want to delete??');\"><center>Delete</center></";>"
<div class="third">
<input type="button" value="Remove" class="remve" name="<?php echo $row['choice_id']; ?>" onClick="deleteImage(<?php echo $row['choice_id']; ?>)"style="cursor:pointer;">
</div>
<script type="text/javascript">
function deleteImage(x){
var conf = confirm("Are you sure you want to delete this choice?");
if(conf == true){
window.location = "addnewentry/choiceRemove.php?id="+x;
}
}
</script>
Please the change the line
echo"<td> <a href ='padamfail.php?FailID=$id' onClick="return confirm('are you sure you want to delete??');"><center>Delete</center></";>"
to
echo "<td> <a href ='padamfail.php?FailID=$id' onClick='return confirm('are you sure you want to delete??');' ><center>Delete</center></a>";
echo"<td><a href='delete.php?id={$row['id']}' onclick='return confirm_alert(this);' >Delete</a></td>";
**you should try this code ,it will definitely work **
=
<script>
//alert on delete
function confirm_alert(node) {
return confirm("You are about to permanently delete a product. Click OK to continue or CANCEL to quit.");
}
</script>
<script>
//alert on delete
function confirm_alert(node) {
return confirm("You are about to permanently delete a product. Click OK to continue or CANCEL to quit.");
}
</script>
hoping this will help you