Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to preselect dropdown value from database when dropdown list is loaded from jquery load method
    primarykey
    data
    text
    <p>I'm not entirely sure if this is possible, but I'll ask here. </p> <p>I have a .jsp page that populates the dropdown contents from .txt files and loaded using jquery/javascript. </p> <p>They're loaded like this: </p> <pre><code>$function(){ $(".dropdownA").load("dropdowninfo.txt); }; </code></pre> <p>I also use a servlet to ping the database to fill out the other information for this particular .jsp page. My question is how to select the proper value of what's in the dropdown menu to show that value. </p> <p>For example:<br> if the dropdown contained {a, b, c, d, e} and the servlet returned "d", how can i get the jsp page to show the "d". Currently it will show the list. Below is how I coded the jsp page. </p> <pre><code>&lt;select class=".dropdownA"&gt;&lt;select&gt; </code></pre> <p>This will display a, b, c, d, e in the dropdown. So how would you preselect "d"? Or should i just do it all from the servlet, including populating the dropdown?</p> <p>Thanks!</p> <p><strong>Update:</strong></p> <p>The servlet runs a query, and returns the results to the jsp page. For example:</p> <pre><code>ResultsSet results = record.executeQuery(); Result result = ResultSupport.toResult(results); request.setAttribute("result", result); RequestDispatcher rd = request.getRequestDispacher("/page.jsp"); rd.forward(request, response); </code></pre> <p>So on the jsp page, I get the corresponding value by calling:<br> c:out value="${result[x]}"</p> <p>In essence, somehow i need to put ${result[x]} as the preselected value of the select list. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload