here is my php code
echo ("<td><img src='edit.jpg' width='20' alt='Edit' title='EDIT DATA' onClick=\"swipe2('" + . mysql_result($result, $i, 'no'). + '');'style='cursor:pointer;'" ></td>");
my function
function swipe2(no) { window.open ( 'edit.php?no='+no,'newwindow') }
the problem are syntax and also when i click the link the new window by (function) wont open thanks in advance..
2 Answers 2
Replace
onClick=\"swipe2('" + . mysql_result($result, $i, 'no'). + '');
with
onClick=\"swipe2('" . mysql_result($result, $i, 'no'). "');
---------------------------------^--
also replace
style='cursor: pointer;'" ></td>");
with
style='cursor: pointer;'></td>");
----------------------^^^-----
you have extra " in above code
So your complete code would be.
echo ("<td>
<img src='edit.jpg' width='20' alt='Edit' title='EDIT DATA'
onClick=\"swipe2('". mysql_result($result, $i, 'no') ."');
style='cursor:pointer;'>
</td>");
1 Comment
this worked for me:
<?php
//replace 0 with your mysql_result call
$result = 0;
echo ("<td><img src=\"edit.jpg\" width=\"20\" alt=\"Edit\" title=\"EDIT DATA\" onClick=\"swipe2(".$result.");\" style=\"cursor:pointer;\" ></td>");
?>
<script>
function swipe2(no) { window.open ( 'edit.php?no='+no,'newwindow') }
</script>
some tips:
use double quotes for attributes (not required, but more "standard"). So you have to escape them using \"
try not to put mix function calls with string concatenation. Put the call in a variable, and use the variable in the string. It's easier to read and maintain.
I removed the quotes in the swipe2(something) called, assuming your result is always a number. If it isn't then you'll have to add quotes ( single might work here better, or escaped double quotes, in which case you might need to escape them and escape the backslash too: \\"