Aftab Anxari
Aftab Anxari

Reputation: 17

How to pass value from php to jquery function my code is given below

The following is my code. Without passing value working well.

function add(name) {
  alert(name);
}
<button type="button" id="button" class="btn btn-success" onclick="add("Aftab");">
  Send
</button>

Upvotes: 0

Views: 82

Answers (2)

Kamran Jabbar
Kamran Jabbar

Reputation: 878

You have added in this way value to function in this way which is wrong. The issue is due to double quotes.

onclick="add("Aftab");"

Use this

onclick="add('Aftab');"

or

onclick='add("Aftab");'

function add(name) {
  alert(name);
}
<button type="button" id="button" class="btn btn-success" onclick="add('Aftab');">
  Send
</button>

Upvotes: 1

Naqash Malik
Naqash Malik

Reputation: 1816

You can do it like that:

<button type="button" id="button" class="btn btn-success" onclick="add('<?php echo $name; ?>');">
  Send
</button>

function add(name){
  alert(name);
}

Upvotes: 1

Related Questions