Solved

Select only max 5 check boxed from checkbox and enable buttons

Posted on 2009-07-13
9
391 Views
Last Modified: 2012-05-07
Hi

I have a jsp web page that have a datatable with checkboxes, but I only need the user to tick 5 rows from the checkboxes and enable the buttons. When the page load the button must be disabled only when the user tick 5 checkboxed will the buttons be enabled.

Can some assist with this
Here is my checkbox code:
 
<h:column>
                        
                              <f:facet name="header">
                                    <h:outputText value="Select Assets" />
                              </f:facet>
 
                              <h:selectBooleanCheckbox id="mycheckbox"
                                    value="#{viewsearch.selected}"></h:selectBooleanCheckbox>
                                    
                        </h:column>
 
-------------------------------------------------------------------------------------------------------------------
Here is my button code
 
<h:commandButton id="webPageUpdate" value="Update table values"
                        action="#{transferAssetBean.tableUpdate}">
                  </h:commandButton>
                  <h:commandButton id="saveChanges" value="Save latest changes"
                        action="#{transferAssetBean.updateButton}">
                  </h:commandButton>

Open in new window

0
Comment
Question by:ablsysadmin
  • 4
  • 3
9 Comments
 

Author Comment

by:ablsysadmin
ID: 24869143
Hi

I wrote a function that allow me to do certain stuff but I only need to select max 5 selectBooleanCheckbox. Can we maybe work from my function
<script language="javascript">
								<!--
								function ValidateForm(){
									
									var found = false;
									var btnsaveChanges = document.getElementById("form1:saveChanges");
									btnsaveChanges.disabled = true;
									for (var i=0; i<=1; i++){
										if ((document.getElementById("form1:tableData:"+i+":mycheckbox").checked)>= 1){
											found = true;
											btnsaveChanges.disabled = false;
										}else{
											if( i <= 0){
											found = false
											alert ("Select a Asset before Transfer"); 
											}
										}
							
									}
									
								}
								-->
 
</script>

Open in new window

0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 500 total points
ID: 24871088
Please provide the browser version of the source and I can help.  Use Page Source or View Source when the page is in the browser to see this version of the code.  Your JSP code doesn't really help.  It will also help if you provide the names of the checkbox(es) and the button(s) that should be part of this.
bol
0
 

Author Comment

by:ablsysadmin
ID: 24877007
Hi bo1scott


Here is the source view from the page. Hope this helps
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
					<link rel='stylesheet' class='component' type='text/css' href='/AssetManagement/a4j_3_2_0.SR1-SNAPSHOTorg/richfaces/renderkit/html/css/basic_classes.xcss/DATB/eAHblDspFQAFnAIX' /><link rel='stylesheet' class='component' type='text/css' href='/AssetManagement/a4j_3_2_0.SR1-SNAPSHOTorg/richfaces/renderkit/html/css/extended_classes.xcss/DATB/eAHblDspFQAFnAIX' /><link rel='stylesheet' class='component' type='text/css' href='/AssetManagement/a4j_3_2_0.SR1-SNAPSHOTcss/datascroller.xcss/DATB/eAHblDspFQAFnAIX' /><script type='text/javascript' src='/AssetManagement/a4j_3_2_0.SR1-SNAPSHOTorg.ajax4jsf.javascript.PrototypeScript'></script><script type='text/javascript' src='/AssetManagement/a4j_3_2_0.SR1-SNAPSHOTorg.ajax4jsf.javascript.AjaxScript'></script><script language="javascript">
								<!--
								function ValidateForm(){
									
									var found = false;
									var btnsaveChanges = document.getElementById("form1:saveChanges");
									btnsaveChanges.disabled = true;
									for (var i=0; i<=1; i++){
										if ((document.getElementById("form1:tableData:"+i+":mycheckbox").checked)>= 1){
											found = true;
											btnsaveChanges.disabled = false;
										}else{
											if( i <= 0){
											found = false
											alert ("Select a Asset before Transfer"); 
											}
										}
							
									}
									
								}
								-->
 
</script>
	</head>
	
<form id="form1" name="form1" method="post" action="/AssetManagement/ViewAsset.jsf" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="form1" value="form1" />
<table id="form1:tableData" border="1" cellpadding="2" style="background: #FFFFFF url('images/body_bg.gif') no-repeat right top; font-size: 12px;" width="90%">
<thead>
<tr><th colspan="10" scope="colgroup">Select Assets you wish to transfer from the list below</th></tr>
<tr>
<th scope="col">ID</th>
<th scope="col">Select Assets</th>
<th scope="col">Asset Type</th>
 
<th scope="col">Asset Make</th>
<th scope="col">Asset Model</th>
<th scope="col">Serial Number</th>
<th scope="col">Cost Code</th>
<th scope="col">Status</th>
<th scope="col">Branch Code</th>
<th scope="col">Manager Name</th>
</tr>
</thead>
<tbody>
 
<tr>
<td>3</td>
<td><input id="form1:tableData:0:mycheckbox" type="checkbox" name="form1:tableData:0:mycheckbox" /></td>
<td>Desktop</td>
<td>HP Compaq</td>
<td>Deskpro EN</td>
<td>NC3453453635</td>
<td>SDLC123</td>
<td>In Use</td>
<td>1983</td>
 
<td>Peter Mayer</td>
</tr>
<tr>
<td>63</td>
<td><input id="form1:tableData:1:mycheckbox" type="checkbox" name="form1:tableData:1:mycheckbox" /></td>
<td>Routers</td>
<td>Cisco</td>
<td>3600</td>
<td>SEC9BNX475</td>
<td>SDLC123</td>
 
<td>Not in Use</td>
<td>1983</td>
<td>Peter Mayer</td>
</tr>
<tr>
<td>64</td>
<td><input id="form1:tableData:2:mycheckbox" type="checkbox" name="form1:tableData:2:mycheckbox" /></td>
<td>Routers</td>
<td>Cisco</td>
<td>800</td>
 
<td>NXBTR125PBX47</td>
<td>SDLC123</td>
<td>Not in Use</td>
<td>1983</td>
<td>Peter Mayer</td>
</tr>
<tr>
<td>65</td>
<td><input id="form1:tableData:3:mycheckbox" type="checkbox" name="form1:tableData:3:mycheckbox" /></td>
<td>Routers</td>
 
<td>Cisco</td>
<td>800</td>
<td>NXBTR125PBX47</td>
<td>SDLC123</td>
<td>Not in Use</td>
<td>1983</td>
<td>Peter Mayer</td>
</tr>
<tr>
<td>66</td>
 
<td><input id="form1:tableData:4:mycheckbox" type="checkbox" name="form1:tableData:4:mycheckbox" /></td>
<td>3G Device</td>
<td>3G -HSDPA</td>
<td>Globe Surfer</td>
<td>SEC9BNX471</td>
<td>SDLC123</td>
<td>Not in Use</td>
<td>1983</td>
<td>Peter Mayer</td>
 
</tr>
<tr>
<td>67</td>
<td><input id="form1:tableData:5:mycheckbox" type="checkbox" name="form1:tableData:5:mycheckbox" /></td>
<td>Routers</td>
<td>Cisco</td>
<td>1700</td>
<td>SDLC123</td>
<td>SDLC123</td>
<td>Not in Use</td>
 
<td>1983</td>
<td>Peter Mayer</td>
</tr>
<tr>
<td>68</td>
<td><input id="form1:tableData:6:mycheckbox" type="checkbox" name="form1:tableData:6:mycheckbox" /></td>
<td>Routers</td>
<td>Cisco</td>
<td>2600</td>
<td>1011108210111</td>
 
<td>SDLC123</td>
<td>Not in Use</td>
<td>1983</td>
<td>Peter Mayer</td>
</tr>
</tbody>
</table>
<div class="dr-dscr rich-datascr " id="form1:datascroll" style="width=100%; nowrap=true; cellpadding=2; ; display: none" align="center"><script type="text/javascript">Event.observe('form1:datascroll', 'rich:datascroller:onscroll', function(event){A4J.AJAX.Submit('j_id_jsp_453046294_0','form1',event,{'ignoreDupResponses':true,'parameters':{'ajaxSingle':'form1:datascroll','form1:datascroll':event.memo.page} ,'eventsQueue':'form1:datascroll','actionUrl':'/AssetManagement/ViewAsset.jsf'} ); return false;});</script></div><input id="form1:webPageUpdate" type="submit" name="form1:webPageUpdate" value="Update table values" onclick="return ValidateForm();" /><input id="form1:saveChanges" type="submit" name="form1:saveChanges" value="Save latest changes" /><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id61" />
</form>
	<script language="javascript">
		ValidateForm();
	</script>
 
	</body>
</html>

Open in new window

0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 54

Assisted Solution

by:b0lsc0tt
b0lsc0tt earned 500 total points
ID: 24884625
The function below will do what you need.  Let me know if you have a question.
bol

      		function ValidateForm(){
      			
      			var found = false;
      			var btnsaveChanges = document.getElementById("form1:saveChanges");
      			btnsaveChanges.disabled = true;
			var count = 0;	
      			for (var i=0; i<=6; i++){
      				if ((document.getElementById("form1:tableData:"+i+":mycheckbox").checked)){
      					found = true;
					count++;
      				}
      			}
			if (count === 0) {
				btnsaveChanges.disabled = false;
				alert ("Select a Asset before Transfer");
				return false;
			} else if (count > 5) {
				btnsaveChanges.disabled = false;
				alert ("Select no more than 5 Assets before Transfer");
				return false;
			} else {
				return true;
			}    			
      		}

Open in new window

0
 

Author Comment

by:ablsysadmin
ID: 24893009
Hi

This works 100%
Thanks
0
 

Author Closing Comment

by:ablsysadmin
ID: 31605355
first time excelent work GURU b0lsc0tt:
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24940111
Great!  I am glad I could help.  Thanks for the interesting question, the grade and the points.
bol
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
free scanner TWAIN can be operated with a Web application 9 69
iterator/ListIterator approach 17 39
Fulfillment API php code sample 1 58
Powershell File Sort 8 41
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question