var hdata = '<select id="drpTransProvider" style="width:150px;" onchange="return SetValueofDropdown(\"transprovider\",this.value);"><option value=""></option>';
why there is an syntax error in browser ?
it is like
SyntaxError: syntax error
return SetValueofDropdown(
Grijesh Chauhan
58.6k20 gold badges145 silver badges214 bronze badges
-
This question is similar to: How do I properly escape quotes inside HTML attributes?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.dumbass– dumbass2025年02月24日 21:01:52 +00:00Commented Feb 24, 2025 at 21:01
4 Answers 4
You need to escape ' not ", so :
var hdata = '<select id="drpTransProvider" style="width:150px;"
onchange="return SetValueofDropdown(\'transprovider\',this.value);"><option value=""></option>';
Sign up to request clarification or add additional context in comments.
2 Comments
Amit
Same answer as me but I have posted before you
Anthony Grist
@AmitAgrawal So what? You were 13 seconds faster, and this has marginally more explanation as to what has been changed. If you want upvotes, consider slightly more supporting text than "Try this".
Try this
var hdata = '<select id="drpTransProvider" style="width:150px;"
onchange="return SetValueofDropdown(\'transprovider\',this.value);"><option value=""> </option>';
answered Dec 19, 2013 at 11:26
Amit
15.4k8 gold badges50 silver badges69 bronze badges
Comments
You're using " characters inside your onclick attribute that is declared using " characters too. Try this:
onchange="return SetValueofDropdown(\'transprovider\',this.value);"
Comments
I used your code but I didn't get any error.I added extra code that is at last. I used in this manner.
My Html Code:<span id="test"></span>
My script code:
<script type="text/javascript">
$(document).ready(function(){
var hdata = '<select id="drpTransProvider" style="width:150px;" onchange="return SetValueofDropdown(\"transprovider\",this.value);"><option value=""></option></select>';
$('#test').html(hdata);
});
</script>
answered Dec 19, 2013 at 11:36
Rahul Sahu
2841 gold badge4 silver badges15 bronze badges
Comments
default