2

I'm trying to pass a number with zeroes (cuz is form database) to a javascript function:

<table>

   <tr onClick="View(<?php echo $id; ?>)">
      <td> <?php echo $id; ?> </td>
   </tr>

</table>

Javascript function:

   function View(id){
    alert(id);
   }

For exm.: If my id is 0005, alert 5. If my id is 0006, alert 6.

I need to alert '0005' - '0006' but i can't solve this.

Thank you for answers

1

1 Answer 1

5

Change:

onClick="View(<?php echo $id; ?>)"

to

onClick="View('<?php echo $id; ?>')"

JavaScript is interpreting the value as a number so you need to tell it to use the value as a string by enclosing it in quotes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.