javascript - Passing string into Onchange - Stack Overflow

I am having a hard time passing a string constant into an onchange event. code example which i am tryi

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.

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.

Share Improve this question edited Jun 28, 2012 at 17:08 Joseph Marikle 78.7k18 gold badges113 silver badges130 bronze badges asked Jun 28, 2012 at 17:07 raviravi 711 gold badge3 silver badges11 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 5

Either set rvalue = "'hi'" or quote it in the body: 'onchange="ravi(\''+rvalue+'\');">'

That is because rvalue is a string. You need to wrap strings with quotes. So it should be something like - onchange="ravi(\''+rvalue+'\');">'

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745075993a4609838.html

相关推荐

  • javascript - Passing string into Onchange - Stack Overflow

    I am having a hard time passing a string constant into an onchange event. code example which i am tryi

    19小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信