{"id":352,"date":"2013-09-26T05:15:19","date_gmt":"2013-09-26T05:15:19","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=352"},"modified":"2013-09-27T04:43:36","modified_gmt":"2013-09-27T04:43:36","slug":"populating-form-elements-in-jsp","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/populating-form-elements-in-jsp\/","title":{"rendered":"Populating Form elements in JSP"},"content":{"rendered":"<p>Add the JSTL Library as below<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;%@taglib prefix=&quot;c&quot; uri=&quot;http:\/\/java.sun.com\/jsp\/jstl\/core&quot;%&gt;\r\n&lt;%@ taglib uri=&quot;http:\/\/java.sun.com\/jsp\/jstl\/functions&quot; prefix=&quot;fn&quot; %&gt;\r\n<\/pre>\n<p><strong>Populating a Text Box<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n  &lt;input name=&quot;txtUserName&quot; id=&quot;txtUserName&quot; type=&quot;text&quot; value='&lt;c:out value=&quot;${User.userName}&quot;&gt;&lt;\/c:out&gt;'&gt;\r\n<\/pre>\n<p><strong>Populating a Dropdown List<\/strong><br \/>\n<em>Type 1<\/em><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n &lt;select name=&quot;cboAge&quot; id=&quot;cboAge&quot;&gt;\r\n  &lt;c:forEach begin=&quot;20&quot; end=&quot;60&quot; var=&quot;i&quot;&gt;\r\n    &lt;option value=&quot;${i}&quot; &lt;c:if test=&quot;${i == User.age}&quot;&gt;Selected&lt;\/c:if&gt;&gt;${i}&lt;\/option&gt;    \t\t\t\r\n  &lt;\/c:forEach&gt;\r\n &lt;\/select&gt;\r\n<\/pre>\n<p><em>Type 2<\/em><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n &lt;select name=&quot;cboLocation&quot; id=&quot;cboLocation&quot;&gt;\r\n   &lt;option value=&quot;Chennai&quot;&gt;Chennai&lt;\/option&gt;\r\n   &lt;option value=&quot;Bangalore&quot;&gt;Bangalore&lt;\/option&gt;\r\n   &lt;option value=&quot;Mumbai&quot;&gt;Mumbai&lt;\/option&gt;\r\n  &lt;\/select&gt;\r\n<\/pre>\n<p><em>Javascript Code<\/em><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('document').ready(function(){\r\n  $('#cboLocation').val('&lt;c:out value=&quot;${User.location}&quot;&gt;&lt;\/c:out&gt;');\r\n});\r\n<\/pre>\n<p><strong>Populating Radio buttons<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input name=&quot;rdoGender&quot; type=&quot;radio&quot; id=&quot;rdoMale&quot; value=&quot;1&quot; &lt;c:out value=&quot;${User.gender == 1?'checked':''}&quot;&gt;&lt;\/c:out&gt;&gt;&lt;label for=&quot;rdoMale&quot;&gt;Male&lt;\/label&gt;\r\n&lt;input name=&quot;rdoGender&quot; type=&quot;radio&quot; id=&quot;rdoFemale&quot; value=&quot;0&quot; &lt;c:out value=&quot;${User.gender == 0?'checked':''}&quot;&gt;&lt;\/c:out&gt;&gt;&lt;label for=&quot;rdoFemale&quot;&gt;Female&lt;\/label&gt;\r\n<\/pre>\n<p><strong>Populating Check boxes<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n &lt;input name=&quot;chkSkills&quot; type=&quot;checkbox&quot; id=&quot;chkJava&quot; value=&quot;Java&quot; &lt;c:if test=&quot;${fn:contains(User.skills, 'Java')}&quot;&gt;Checked&lt;\/c:if&gt;&gt;&lt;label for=&quot;chkJava&quot;&gt;Java&lt;\/label&gt;    \t\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Add the JSTL Library as below &lt;%@taglib prefix=&quot;c&quot; uri=&quot;http:\/\/java.sun.com\/jsp\/jstl\/core&quot;%&gt; &lt;%@ taglib uri=&quot;http:\/\/java.sun.com\/jsp\/jstl\/functions&quot; prefix=&quot;fn&quot; %&gt; Populating a Text Box &lt;input name=&quot;txtUserName&quot; id=&quot;txtUserName&quot; type=&quot;text&quot; value='&lt;c:out value=&quot;${User.userName}&quot;&gt;&lt;\/c:out&gt;&#8217;&gt; Populating a Dropdown List Type 1 &lt;select name=&quot;cboAge&quot; id=&quot;cboAge&quot;&gt; &lt;c:forEach begin=&quot;20&quot; end=&quot;60&quot; var=&quot;i&quot;&gt; &lt;option value=&quot;${i}&quot; &lt;c:if test=&quot;${i == User.age}&quot;&gt;Selected&lt;\/c:if&gt;&gt;${i}&lt;\/option&gt; &lt;\/c:forEach&gt; &lt;\/select&gt; Type 2 &lt;select name=&quot;cboLocation&quot; id=&quot;cboLocation&quot;&gt; &lt;option value=&quot;Chennai&quot;&gt;Chennai&lt;\/option&gt; &lt;option value=&quot;Bangalore&quot;&gt;Bangalore&lt;\/option&gt; &lt;option&hellip; <a href=\"https:\/\/codethataint.com\/blog\/populating-form-elements-in-jsp\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[],"class_list":["post-352","post","type-post","status-publish","format-standard","hentry","category-jsp"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=352"}],"version-history":[{"count":5,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/352\/revisions"}],"predecessor-version":[{"id":364,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/352\/revisions\/364"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}