Changing the selected value of a select input with jq

Alex Lord
Alex Lord used Ask the Experts™
on
<select required="" class="form-control input-md" name="act_lnk" id="act_lnk">
<option selected="selected" value="0">( Contact) - Level </option><option value="702279 ">( Lead ) -  testing open status</option>
<option value="702266 ">( Lead ) -  alex test dealtime</option>
<option value="702251 ">( Deal ) -  test</option>
</select>

Open in new window


here my select input,

is their a way in jq to change it selected prop?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
$("#act_lnk").val('702251');
Sam JacobsDirector of Technology Development, IPM

Commented:
Minor typo ... should be: $("#act_lnk").val('702251');

Commented:
Thanks Sam, you are right, I missed letter 'a' when copying id of the select element
Analyst Developer
Distinguished Expert 2018
Commented:
You could use the jquery "val()" method as mentioned in the previous comments, just make sure to trim the value of the options in your HTML first else add the space in your jQuery code.

Trim the extrat spaces at the end :

<select required="" class="form-control input-md" name="act_lnk" id="act_lnk">
    <option selected="selected" value="0">( Contact) - Level </option>
    <option value="702279 ">( Lead ) -  testing open status</option>
   ______________________^
    <option value="702266 ">( Lead ) -  alex test dealtime</option>
   ______________________^
    <option value="702251 ">( Deal ) -  test</option>
   ______________________^
</select>

Open in new window


Or add the space in your js like :

$("#act_lnk").val('702251 ');
_________________________^

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial