Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Submit enabled only when form is completed

 
Lynn Noda
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi-
I have a JSP page that dynamically generates x number of questions and responses from a database broken into six different categories, also determined by the database. The ability to save the form at any time and come back to it is available, but Submit can only be selected when all of the questions have been answered. How would I go about this. Below is the JSP code for the questions and responses.
Thank you in advance very much!!

<%
String categoryLetter;
for (int i=2; i <= 7; i++){
%>
<div id="page<%=i%>" class="page">

<%

switch(i){
case 2:
categoryLetter = "J";
break;
case 3:
categoryLetter = "G";
break;
case 4:
categoryLetter = "S";
break;
case 5:
categoryLetter = "C";
break;
case 6:
categoryLetter = "D";
break;
case 7:
categoryLetter = "L";
break;
default:
categoryLetter = "";

}
String categoryTitle = "";
String nextBtn = "";
if (categoryLetter == "J"){
categoryTitle = "Jurisdiction / Community";
nextBtn = "page3";
}
if (categoryLetter == "G"){
categoryTitle = "Presence / Membership";
nextBtn = "page4";
}
if (categoryLetter == "S"){
categoryTitle = "Activity in the Schools";
nextBtn = "page5";
}
if (categoryLetter == "C"){
categoryTitle = "Activity in the Community";
nextBtn = "page6";
}
if (categoryLetter == "D"){
categoryTitle = "Gangs and Drugs";
nextBtn = "page7";
}
if (categoryLetter == "L"){
categoryTitle = "Gangs in the Legal System";
nextBtn = "page1";
}
%>

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" height="38" class="pageName"><strong><%=categoryTitle%></strong></td>
</tr>
</table>
<table width="600">
<tr>
<td style="padding-left:0px;">
<ol>
<%
questionArrayList = CGAAsmntController.getAllQuestions(categoryLetter);
String isChecked = "";

for(Question curQ : questionArrayList){
responseArrayList=curQ.getResponses();
%>

<li><%=curQ.getQuestionText()%><br />

<% for(ResponseChoice curResponse : responseArrayList){
if(responseHashMap.containsKey(curResponse.getResponseChoiceId())){
isChecked = "checked=\"checked\"";
if(curQ.getQuestionType().getCode()=='R'){
isChecked = "checked";
}
}
else isChecked = "";

if(curQ.getQuestionType().getCode()=='C'){
%>
<input type="checkbox" <%=isChecked %> name="<%=curQ.getQuestionId() + curResponse.getResponseChoiceLetter()%>" value="<%=curQ.getQuestionId() + curResponse.getResponseChoiceLetter()%>" />
<%
}
else if(curQ.getQuestionType().getCode()=='R'){
%>
<input type="radio" <%=isChecked %> name="<%=curQ.getQuestionId()%>" value="<%=curResponse.getResponseChoiceLetter()%>" />
<%
}
out.println(curResponse.getResponseChoiceText() + "<br />");
}
}
%>
</li>

</ol>
</td>
</tr>
<tr>
<td align="right" style="background-color:#cccccc; padding:6px;">
<input type="submit" value="Save" class="asmntButton" />
  
<input type="button" class="asmntButton" value="Next »" onKlick="showLayer('<%=nextBtn%>');self.location.hash='top';" />
</td>
</tr>
</table>
</div>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Smilynn", please check your private messages for an important administrative matter.

Also, please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
[ September 04, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Disable the button initially, and then use JavaScript event handling to keep track of when all questions have been answered. Only then do you enabled the button.
 
Lynn Noda
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear--
But as I am really not any good at this coding stuff yet (I didn't write most of what I posted). That all sounds great, but I have no idea how to do it.

Thanks again!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The topic of event handling was recently discussed in this topic. You might it find it helpful to read through it.
[ September 04, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quick start hints:

1) Add the disabled attribute to the submit button. This will cause it to be disabled until enabled under script control.

2) Add an event handler to each control that checks to see if all the questions have been answered. If so, enable the button. Otherwise, leave it disabled.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic