-1

I am getting syntax error

Uncaught SyntaxError: missing ) after argument list

My code

 <button onclick="alert('document.getElementById('todo.age').value');">onclick</button>
2
  • You can't have a dot in the name of an argument. What are you trying to do ? Commented May 26, 2015 at 6:59
  • Do you really have an input with id="todo.age"? It's not a good idea to put dots in IDs, because CSS uses dots as class prefixes. Commented May 26, 2015 at 7:06

4 Answers 4

2

in controller add

$scope.alert = function(age) {
    alert(age);
}

in html change like this:

<button ng-click="alert(todo.age);">onclick</button>
Sign up to request clarification or add additional context in comments.

4 Comments

its working but i want to return the value from the json ..but it's not getting
embed.plnkr.co/JodNsW/preview try this i want to get element id from the json value
see my new update, this work. plnkr.co/edit/p45VPnqUPzS3MqdbshBw?p=preview
@gjramanaa. In your fiddle I can't see any input with that id. Which's element's value are you trying to display?
1

Try this:

<button onclick="alert(document.getElementById('todo.age').value);">onclick</button>

You shouldn't quote the argument to alert if you want to call the function.

Comments

0

It will start working better if you separate your HTML code and JavaScript. Kind of this. HTML:

<button id="button">onclick</button>

JavaScript:

window.onload = function()
{
  var button = document.getElementById('button');
  button.onclick = function()
  {
    //do some action here
  }
}

This will help you to avoid simple syntax errors.

Comments

0

if u need value of the todo.age id values use the following code. <button onclick="alert(document.getElementById('todo.age').value);">onclick</button>

or else of u want to print the whole text document.getElementById('todo.age').value like this use <button onclick="alert('document.getElementById('todo.age').value');">onclick</button> code/

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.