0
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(
1
  • 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. Commented Feb 24 at 21:01

4 Answers 4

5

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

Same answer as me but I have posted before you
@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".
2

Try this

var hdata = '<select id="drpTransProvider" style="width:150px;" 
onchange="return SetValueofDropdown(\'transprovider\',this.value);"><option value=""> </option>';

Comments

0

You're using " characters inside your onclick attribute that is declared using " characters too. Try this:

onchange="return SetValueofDropdown(\'transprovider\',this.value);"

Comments

0

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>

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.