1 Reply Latest reply: Oct 17, 2010 3:26 PM by Ben Pleysier RSS

    Change the default option for a select box

    Phil_W Community Member

      Hi,

       

      I have a select box, with the options built from a Spry Dataset

       

      <select name="AvatarSelect" id="AvatarSelect" spry:region="myAvatars">
          <option spry:repeat="myAvatars">{A_NAME}</option>
        </select>

       

      I wish to change the default selected option (which is usually the first row returned from the dataset) based on a value for A_NAME that I know from another spry dataset.

       

      Tried using Spry.$$('#AvatarSelect') to get to the the array of select options but to no avail.

       

      How can I cycle through the options and then set the selected on, based on a match for A_NAME?

       

      Cheers

       

      Phil

        • 1. Re: Change the default option for a select box
          Ben Pleysier CommunityMVP

          Hi Phil

           

          I think this is the way

          <select name="AvatarSelect" id="AvatarSelect" spry:region="myAvatarsLookup myAvatarsValue">
            <option spry:repeat="myAvatarsLookup" spry:test="'{myAvatarsValue::A_NAME}'=='{myAvatarsLookup::id}'" value="{myAvatarsLookup::id}" selected="selected">{A_NAME}</option>
            <option spry:repeat="myAvatarsLookup" spry:test="'{myAvatarsValue::A_NAME}'!='{myAvatarsLookup::id}'" value="{myAvatarsLookup::id}">{A_NAME}</option>
          </select>

          Cheers