Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Checkbox comparisons

Participant ,
Jul 17, 2008 Jul 17, 2008
I solved my previous post, but this post is somewhat related, so I need to post again, for help.

My form displays mulitple line items and I add a checkbox next to each. If checked, that line is deleted. Here is my checkbox : <cfinput type="checkbox" name="del/#urdn_number#/#urdn_line_item#" value="Yes">

I then have to add the exact information rigth underneath, but this time, the checkbox will be used to edit. So if checked, that line is edited. (I know you do not need a checkbox for this, but for consistency, they wanted one for edit to match the delete, since they are the same items). Here is the checkbox for edit <cfinput type="checkbox" name="edit/#urdn_number#/#urdn_line_item#" value="Yes">

Here is my question : If there are two line items (same) for the delete and edit, how do I check/compare so that if line item 1 is checked for delete and line item 1 is checked for edit, this is now allowed, since you cannot delete and edit the same line item.

I do not know how to validate this, so that is why I am posting.
335
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 17, 2008 Jul 17, 2008
Use javascript to determine if both are checked, if they are, then throw an alert and dont submit the form.

On the server side, check to see if both fields have been checked prior to running any actions.

And no, I wont write the code for you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 20, 2008 Jul 20, 2008
The checkboxes are dynamically generated and there can be multiple checkboxes for the edit and delete functions. The checkboxes for the edit all have the same name, and they all have the same name for the delete.

With javascript, how do I determine that delete 1 is checked and edit 1 is checked, etc. ?

If the checkboxes have different names, I can validate after submit by using cfif isDefined("delete_1")> and isDefined("edit_1")> to determine that both checkboxes for item 1 have been checked. But with the same name, I do not know how to determine which checkbox number was checked.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 25, 2008 Jul 25, 2008
LATEST
quote:

The checkboxes for the edit all have the same name, and they all have the same name for the delete.


Do you mean that the edit and delete checkboxes share the same name?
For example:
edit: <cfinput type="checkbox" name="box_1" value="edit">
delete: <cfinput type="checkbox" name="box_1" value="delete">

If that is the case, you will have to validate against the value of box_1, not the name itself.. if the value is equal to "edit,delete" for box_1, then obviously both options have been selected. Checkboxes return their value as a list.

<cfif isDefined('form.box_1') AND form.box_1 EQ 'edit,delete'>
logic here.
</cfif>

Ideally, you should be using radio buttons in this situation since a user shouldn't be able to select both edit and delete to begin with.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources