0

i created a button that will be created dynamically, so the html content of the button is written on javascript string. this is my code:

<tr>
    <td><input type='button' value='Apply Now' 
        onclick='pageRedirect('" + entity.ServiceID + "', '" + 
            entity.RecordID + "');'>
    </td>
</tr>

this code does not work, particularly on the part where i assigned the parameter. i also tried this code with escape sequence but still the same error.

<tr>
    <td>
        <input type='button' value='Apply Now' 
            onclick='pageRedirect(\'" + entity.ServiceID +"\', \'" + 
                entity.RecordID + "\');'>
    </td>
</tr>

I don't know what I'm missing. Some help please?

7
  • Your quoting is just wrong in onclick = 'pageRedirect('" + entity.ServiceID +"', '" + entity.RecordID + "');' Assuming pageRedirect and entity are global symbols, I'm not sure why you don't just use onclick='pageRedirect(entity.ServiceID,entity.RecordID);' Commented Mar 17, 2014 at 5:09
  • what should be right ? Commented Mar 17, 2014 at 5:10
  • See what I added to my previous comment. Commented Mar 17, 2014 at 5:12
  • if i remove the single quotes on the assigning of parameters, the console returns this error: Uncaught SyntaxError: Unexpected token ILLEGAL Commented Mar 17, 2014 at 5:14
  • @DustineTolete you can get your error from the code highlighting itself on SO. Commented Mar 17, 2014 at 5:16

1 Answer 1

2

You're escaping/closing the wrong quotes. In your code snippet you're actually ending the onclick attribute. IE: onclick='pageRedirect(' ...everything after is now a new attribute

Try something like the following:

"<tr><td><input type = 'button' value = 'Apply Now' onclick = 'pageRedirect(\"" + entity.ServiceID +"\", \"" + entity.RecordID + "\");'></td></tr>"
Sign up to request clarification or add additional context in comments.

3 Comments

Why not just onclick='pageRedirect(entity.ServiceID, entity.RecordID);'?
@jfriend00 even i don't know why. i tried it even before asking this question here.
@DustineTolete - The simpler version works here: jsfiddle.net/jfriend00/EZ8HX so there must be something about your page that you aren't showing us.

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.