1

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()?

3 Answers 3

3

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>
Sign up to request clarification or add additional context in comments.

5 Comments

avoiding the double quotes gives an error ReferenceError: PRD8798454 is not defined
Can you please show me the instruction context, 2 or 3 lines before and after it ?
solved the issue onclick='showproduct("variable1","variable2")'
You were passing only one parameter, because of the double quotes. Your call looked like showproduct("100, NYC") whereas it should have been showproduct(100, "NYC")
yeah. that was the reason :)
2

Try this

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

Comments

0

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>

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.