-1

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..

asked Oct 31, 2013 at 7:40

2 Answers 2

0

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>");
answered Oct 31, 2013 at 7:42
Sign up to request clarification or add additional context in comments.

1 Comment

it has no error now, but now it has no cursor pointer and still no newwindow open
-1

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: \\"

answered Oct 31, 2013 at 20:16

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.