|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
passing checkbox values to the action page
Hi All, I need to solve this issue..
I'm getting the values for my checkbox in a loop and if the user checks the "select all"checkbox all the data should be deleted from the table and if the user checks only one checkbox I need to delete only the particular selected value from the table.. my problem really is when I passing the values to the action page only the first value(chk_box_1) is being passed and I'm getting an error "chk_box_2".... is not defined. Any clue? |
|
#2
|
||||
|
||||
|
checkboxes that aren't checked aren't even passed over from the browser when the form is submitted
that's the way they work therefore you must check to see if the checkbox is present, i.e. exists, before you use it some people like to use IsDefined but i use CFPARAM |
|
#3
|
|||
|
|||
|
If there is a chance that one of the checkboxes won't be checked you have to test for it's existence on the action page. Remember that HTML forms don't pass in any unchecked check boxes.
You can check for it's existence like this: <cfif structKeyExists( form, 'myCheckboxField' )> ...the field is there... </cfif> Or if you prefer you can automatically create it and set it to a default value if it doesn't exist with <cfparam>.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#4
|
|||
|
|||
|
please check the code
Hi All
thanks for the response.Please review the code given below which I'm using and give me a solution to solve the issue. This is what I'm trying to do in the form page. <---javascript to select check all check box---> function selectedList(src) { if(document.frm_workorder.deleteall.checked) set(1); else set(0); } function set(setOrUnset) { for (var i = 1; i <= document.frm_workorder.Total_check_boxes.value; i++) { var object = eval("document.frm_workorder.chk_proj_" + i); if(setOrUnset == 1) object.checked = true; else object.checked = false; } } function deleteapprover() { if (deleteapprover.arguments.length == 0) { var objectchecked = false; for (var i = 1; i <= document.frm_workorder.Total_check_boxes.value; i++) { var object = eval("document.frm_workorder.chk_proj_" + i); if(object.checked) { objectchecked = true; break; } } if(!(objectchecked)) { alert("Please select the checkbox first to delete a record"); return; } else //submit document.frm_workorder.action = "add_approveraction1.cfm?mode=delete"; document.frm_workorder.submit(); } else { if(confirm("This Approver will be deleted")) { document.frm_workorder.deleteall.checked = true; set('1'); document.frm_workorder.action = "add_approveraction1.cfm?mode=delete"; document.frm_workorder.submit(); } } } <--end of java script> <--to select all the check boxes to delete all the records in one time--> <a href="javascript:deleteapprover();" class="sm_text_small"> Delete </a> <form name="frm_workorder" action="post"> <TD align="left" valign="middle" class="sm_text_small" nowrap width="50">Select All<BR><a href="" class="small_helpers"><input type="checkbox" name="deleteall" value="" align="middle" onclick="selectedList(this);"></a></TD> <--I could able to select and deselect the check boxes at his point--> <cfset chk_box_counter = 0> <cfset currentrow =""> <cfloop query = "getmgrntfy"> <cfset chk_box_counter = chk_box_counter + 1> <TD align="left" valign="middle" class="Text"> <input type="checkbox" value="#ntfy_em_id#" name="chk_proj_#chk_box_counter#" align="middle"></TD> </cfloop> </form> Action page...(add_approveraction1.cfm) <cfif isdefined("form.mode")> <cfif mode eq "delete"> <cfloop index="count" from=1 to="#Form.Total_check_boxes#"> <cfset chkproj = "form.chk_proj_#Evaluate(count)#"> <cfset chkproj = "#Evaluate(chkproj)#"> <cfquery name="deleteusernotify" datasource="#DBName#"> delete from un where un.NTFY_EM_ID = '#chkproj#' </cfquery> </cfloop> </cfif> </cfif> <--I'm getting an error while submitting after checking only one check box Variable form.chk_proj_2 is undefined. --> Any clue. But I can able to delete all the records If I checked select all check box... Thanks.. |
|
#5
|
|||
|
|||
|
It sounds like there is a problem in your Javascript somewhere. That's probably where you need to debug. However you do it you should still provide server-side validation for missing fields becuase it is simple to turn off Javascript.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > passing checkbox values to the action page |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|