I have a string variable called selectText that contains the following text:
<option value="0101" title="xxxx">A</option><option value="0102" title="xxx">B</option> .....
I have a string variable called selectedVal that contains a value that could be either “0101” or “0102” etc
Is there a way using javascript that I can modify selectText to have the words selected=”selected” added if I supply selectedVal. So for example if the value of selectedVal was “0102” then I would return the selectText with selected=”selected” added to it.
<option value="0101" title="xxxx">A</option><option value="0102" selected="selected" title="xxx">B</option>
Try this:
or:
Or you can set the value of the
selectelement by usingval()method after appending the options:DEMO