Parameter value `onClick` changed

168 Views Asked by At

I have a problem with javascript.

Let's say I have javascript function like this:

<script>
    function show_popup(id) {
        alert(id);
    }
</script>

EDIT

On the other hand, I have an anchor which call that function:

<?php
    ...
    $rs5 = $db->Execute("SELECT * FROM students");

    foreach ($rs5 as $roww) {
         echo "<tr $clr onMouseOver=this.bgColor='gold'; onMouseOut=this.$clr;  >"
             ."<td>".$roww[name]."&nbsp;</td>"
             ."<td><a href='javascript:void(0);' title='Show' onClick='show_popup(".$roww[id].");'> SHOW </a></td>"
             ."</tr>";
    }
    ...
?>

When I click that anchor, it'll show alert which says whatever in show_popup parameter, right?

Now, I have a problem that sometimes, the alert content and the parameter on onClick did not equal (changed). (Ex.: ... onClick='show_popup(547);' ..., the alert shows: 987)

UPDATED:

Here's a screenshot between alert and the inspect element onClick inline (the function name is detail_popup which is the same as show_popup above):

enter image description here

How can i fixed it?

Thank you so much for any answer.

1

There are 1 best solutions below

2
On BEST ANSWER

As i can see in your console. HTML output is:

<a href='javascript:void(0);' onClick='show_popup(0000003520316);' title='Show'> SHOW </a>

In onclick() function number is started with 00**** which denotes the number will convert to **Octal number thats why you are getting wrong output send number without 00 you will correct answer.