Telen Stanley
Telen Stanley

Reputation: 330

How to pass two PHP variables in HTML button onClick function?

I need to pass these two variables in my HTML button.

$value['_id']
$sellerInfo[0]['City']

The HTML is:

<button id='myBtn' onclick='showproduct()'>Pending</button>

I have tried with this code:

<button id='myBtn' onclick='showproduct("<?php echo $value['_id'];?> , <?php echo $sellerInfo[0]['City']; ?>  ")'>Pending</button>

I'm getting an error the second parameter is undefined.

How can I pass the two variables in showproduct()?

Upvotes: 1

Views: 11343

Answers (3)

Yeasin Arafat
Yeasin Arafat

Reputation: 19

You can try these tricks in your onClick function from this example

<i class="fa fa-times pl-5 in_time_late_approve" onclick='in_time_late_approve("<?php echo $key ?>", "<?php echo $employee_attendance_item->attendance_in_time ?>")' style="color:green; cursor:pointer" aria-hidden="true"></i>

Upvotes: 0

Max
Max

Reputation: 891

The quotes are messed.

Change your code to this:

<button id='myBtn' onclick='showproduct("<?php echo $value['_id'];?>" , "<?php echo $sellerInfo[0]['City']; ?>")'>Pending</button>

Upvotes: 3

Nazmul Hasan
Nazmul Hasan

Reputation: 1977

Try this

<button id='myBtn' onclick='showproduct("<?php echo $value['_id'];?>" , "<?php echo $sellerInfo[0]['City']; ?>")'>Pending</button>

Upvotes: 2

Related Questions