Reputation: 71
I am having a hard time passing a string constant into an onchange event. code example which i am trying:
var rvalue = "hi";
var r1 = '<label style="vertical-align:2px;">Group by: </label>' +
'<select id="pwx_documents_range_groupby" onchange="ravi('+rvalue+');">' +
'<option value="listview" selected="selected">List View</option><option value="notetype">Note Type</option><option value="author">Author View</option>'+
'<option value="cat">Cat</option></select>'
This is just sample code.. But the question is once drop down change it will call ravi function and throw me the error 'hi' is undefined. If i am passing 0 instead of hi it works great. I am totally surprise why it will not accept the string.
Anybody have any idea that would be great help.
Upvotes: 1
Views: 6049
Reputation: 9578
Either set rvalue = "'hi'"
or quote it in the body: 'onchange="ravi(\''+rvalue+'\');">'
Upvotes: 5
Reputation: 895
That is because rvalue is a string. You need to wrap strings with quotes. So it should be something like - onchange="ravi(\''+rvalue+'\');">'
Upvotes: 0