0

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>

2
  • 4
    Closing as a typo. You're mixing your quotes. Use onclick="add('Aftab');" - or better yet, an unobtrusive event handler instead of the 90s relic that is the on* event attributes. Commented Jul 14, 2017 at 14:57
  • Thanks sir ...Problem solved..... Commented Jul 15, 2017 at 5:37

2 Answers 2

1

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

Comments

1

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>

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.