PDA

View Full Version : Urgent - How can 1 form handle for DISABLE and Able?


ClueLess
12-13-2002, 03:03 PM
I have an information form; actually, it works great so far as what I want. But, I still need help.

Here is how the form works:

I have 1 form, it handles for 2 situations: DELETE and ADD.

1- If the form has values (information), it shows a DELETE checkbox and the form (has values). It works great.

2- If it is new (no information), it shows an ADD checkbox and a blank form - it works fine too. But, I need your help for this new form. We would like to DISABLE all the textboxes, if the add checkbox has not checked/selected. The question is: Can 1 form handle for both DISABLE and ABLE? If it is, how can we do it?

below is the code:

<html>
<head>
<title>Information</title>
</head>

<body>
<script language="JavaScript">
function ManageAction(doit) {
var result
var Name
document.SubmitForm.Action.value = ''
Name = doit.name
switch (Name)
{
case "LPdelete":

if (document.SubmitForm.LPdelete.checked) {
result=(confirm('Are you sure you want to delete this record?'));
//you assign value to your hidden filed
if (result == true)
{
document.SubmitForm.Action.value = 'D';
}
else
{
document.SubmitForm.LPdelete.checked = 0;
}
}
break;

case "LPadd":
if (document.SubmitForm.LPadd.checked)
{
//if chkbox value "Add" do this
document.SubmitForm.Action.value = 'A';
//return false;
}
break;
}
}
</script>


<FORM action="information.asp" method="post" id="SubmitForm" name="SubmitForm" onsubmit="ShowDate()">
<INPUT type="Hidden" name="Action" id="Action" value="">

<table>
<tr>
<%if request.form ("Action") = "A" then%>
<td width="40" align="right" class="regularParagraph">
DELETE <INPUT type="checkbox" value='Delete' id='LPdelete' name='LPdelete' onClick='ManageAction(this);'>
</td>
<%else%>
<td width="40" align="right" class="regularParagraph">
ADD <INPUT type="checkbox" value='LPadd' id='LPadd' name='LPadd' onClick='ManageAction(this);'>
</td>
<%end if %>
</tr>

<tr>
<td class="SmallHeadingBurg" width="180"> Name:&nbsp;</td>
<td class="regularParagraph" align="left">
<INPUT style="border:1 solid #000000" type="text" id="LPName" name="LPName" value="<%= (LPName) %>" maxlength="30" size="38">
</td>
</tr>
<tr>
<td class="SmallHeadingBurg" width="180">Address:&nbsp;</td>
<td class="regularParagraph" align="left">
<INPUT style="border:1 solid #000000" type="text" id="LPaddress" name="LPaddress" value="<%= (LPAddress) %>" maxlength="30" size="38">
</td>
</tr>
<tr>
<td class="SmallHeadingBurg" width="180">City:&nbsp;</td>
<td class="regularParagraph" align="left">
<INPUT style="border:1 solid #000000" type="text" id="LPCity" name="LPCity" value="<%= (LPCity) %>" maxlength="30" size="38">
</td>
</tr>
<tr>
<td>
<input type="submit" value="Update" name="UpdateInfo" class="ActionButton">
</td>
</tr>
</table>

</body>
</html>

whammy
12-14-2002, 01:00 AM
I'm really not understanding what you're trying to accomplish - since you already stated that if the user has "no information" then it's an "ADD" form, and otherwise it's a "DELETE" form, and it's working fine, right? If that's the case, in what circumstance would you want to disable all of the checkboxes? You didn't explain that at all.

Are you wishing to "UPDATE" a current user's information that already has a record? I have no idea what you're trying to do. :(

:confused:

ClueLess
12-14-2002, 04:16 PM
>
- since you already stated that if the user has "no information" then it's an "ADD" form, and otherwise it's a "DELETE" form, and it's working fine, right?

YES,
IF THE FORM IS BLANK THEN USER CAN SELECT THE "ADD" CHECKBOX AND ENTER NEW INFORMATION.
IF THE FORM ALREADY HAS INFORMATION THEN USER CAN DELETE IF THEY WISH BY SELECTING THE "DELETE" CHECKBOX.

>If that's the case, in what circumstance would you want to disable all of the checkboxes?

NO,
I WOULD LIKE TO DISABLE THE TEXTBOXES....IF IT IS A BLANK FORM AND WITH THE "ADD" CHECKBOX.

>Are you wishing to "UPDATE" a current user's information that already has a record?

YES, IF THE FORM ALREADY HAS INFORMATION (IT HAS A "DELETE" CHECKBOX). IF THEY WANT TO UPDATE IT, SIMPLY ENTERING NEW INFORMATION THEN HIT AN UPDATE BUTTON....WITHOUT SELECT A "DELETE" BUTTON.

well, update/delete/add new information are working fine. But, I just want to DISABLE the all the textboxes (name, address, and city) when it is blank.

Hope, you understand it ...and can help me to solve this problem soon. Thanks so much for your help

whammy
12-15-2002, 05:11 AM
Since you're apparently using ASP, why not just display different fields depending on whether a record exists, etc.?

That's a lot easier to do behind the scenes than to use a bunch of javascript to disable/enable fields, and what if the user has javascript disabled? In that case, your form won't work as intended at all. :)

What I would do to make this REALLY easy if I was making the form, would be to load each form as an ASP Sub() (subroutine), and then depending on the condition, only display the appropriate form, i.e.

<%
Select Case FormType
Case "ADD"
Call AddForm()
Case "UPDATE"
Call UpdateForm()
Case "DELETE"
Call DeleteForm()
End Select
%>

<% Sub Addform() %>
<!-- Your Addform() HTML to create your ADD form would go here -->
<% End Sub %>


etc... this may not have been the solution you were looking for, but it's the way I would do it, since you don't want to depend on javascript for validation when you can use server-side scripting.

Hope this helps! :)

ClueLess
12-15-2002, 01:44 PM
whammy,
That is exactly what I have in my ASP code. Becuase, we have 3 conditions, therefore, we need to have the checkboxes in there.

But, when it is in CASE ADD, it won't add any records into the DB, if user doesn't select the ADD checkbox.

Instead of Disabling all the textboxes....I tried to have to an Alert message in CASE A when user hits Update button without select the checkbox, but it's false.

still don't know :( :confused:

>
What I would do to make this REALLY easy if I was making the form, would be to load each form as an ASP Sub() (subroutine), and then depending on the condition, only display the appropriate form, i.e.

THat is what I did before too. But people here don't want it. they want to have 1 form but it loads differ. condition. ..don't know why they want to make my life harder.

Do you have any other idea? Thanks.