Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
103 views
in Technique[技术] by (71.8m points)

javascript - set predefined value of select dropdown

I have a dropdown menu in html where the users categories are put as options, for them to select. I want them to be able to edit the option, so I am show which category is already selected in there. this works, I have query to my db and then im passing the original value of the category to the front end, where I display it, however, I cannot get it so that if the user does not change the value of the category, to resubmit the change without changing the value. right now, it goes to undefined.

front end:

 <label for="divisionCategory">CATEGORY (OPTIONAL):</label>
    <select name="category" id="">
      //here I need this to store the value of the original image, if they don't select a new one
<option selected disabled value="<%= ogCategory %>"><%= ogCategory %></option>
        <% if(divisions.length){ 
          for(var i = 0;i < divisions.length;i++) { %>
           
              <option value="<%= divisions[i].CATEGORIES %>"><%= divisions[i].CATEGORIES %></option>
              
        <% }
      }else{ %>
      <% } %>
</select>
question from:https://stackoverflow.com/questions/65832418/set-predefined-value-of-select-dropdown

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...