PDA

View Full Version : What is wrong? I got an error


ClueLess
12-11-2002, 02:43 PM
I am blind, I cannot see the error. What is wrong with this simple script?

<html>
<head>
<title>Untitled</title>
</head>

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

<script language="javascript">
function ManageAction() {
//if the check is checked then
if (document.SubmitForm.LPadd.checked)
{
//if chkbox value "Add" do this
(document.SubmitForm.Action.value = 'A');
// return false;
}
}
</script>
<table>
<tr>
<td width="40" align="right" class="regularParagraph">
<INPUT type="checkbox" value='add' id='LPadd' name='LPadd' onClick='ManageAction(this);'>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Update" name="UpdateInfo" class="ActionButton">
</td>
</tr>
</table>
</body>
</html>

Borgtex
12-11-2002, 04:17 PM
No problem, I'm a seeing Eye dog :)


(document.SubmitForm.Action.value = 'A');

I think that it must be "ActionButton"
ShowDate() function missing

ClueLess
12-11-2002, 04:26 PM
No, I tried that but it doesn't work. actually I would like the letter "A" assigns to the value of the hidden field
<INPUT type="Hidden" name="Action" id="Action" value="">

beetle
12-11-2002, 04:40 PM
well, here's your errorfunction ManageAction() {
//if the check is checked then
if (document.SubmitForm.LPadd.checked) {
//if chkbox value "Add" do this
(document.SubmitForm.Action.value = 'A');
// return false;
}
}Th parentheses mess it up, making the code interpreter thinking it's a conditional. Besides, you can make your function much simpler. You are already passing a reference to the checkbox with this, so use it!function ManageAction(c) {
if (c.checked) {
c.form.Action.value = 'A';
}
else {
c.form.Action.value = '';
}
} Or, you can shorten it even more if you'd like to use a ternary statement.function ManageAction(c) {
c.form.Action.value = (c.checked) ? 'A' : '';
} :D

ClueLess
12-11-2002, 04:58 PM
beetle

Yes, I saw that. I did remove the ( ), but it’s still giving the same error :’ document.SubmitForm.LPadd.checked’ is null or not an object

below is the whole code that I have:

<html>
<head>
<title>Untitled</title>
</head>

<body>
<script language="javascript">
function ManageAction() {
var result
document.SubmitForm.Action.value = ''
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;
}
}

//if the check is checked then
if (document.SubmitForm.LPadd.checked)
{
//if chkbox value "Add" do this
document.SubmitForm.Action.value = 'A';
// return false;
}
}
</script>
<FORM action="test.asp" method="post" id="SubmitForm" name="SubmitForm" onsubmit="ShowDate()">
<INPUT type="Hidden" name="Action" id="Action" value="">

<table>
<tr>
<td width="40" align="right" class="regularParagraph">
delete &nbsp;<INPUT type="checkbox" value='Delete' id='LPdelete' name='LPdelete' onClick='ManageAction(this);'>
<br>
add &nbsp;<INPUT type="checkbox" value='LPadd' id='LPadd' name='LPadd' onClick='ManageAction(this);'>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Update" name="UpdateInfo" class="ActionButton">
</td>
</tr>
</table>
</body>
</html>

Adam20002
12-11-2002, 05:50 PM
At what point are you recieving the error, when you select the check box or when you hit the update button ? I ask this because i ran your page and it all worked fine.

ClueLess
12-11-2002, 05:54 PM
when I select a checkbox

beetle
12-11-2002, 07:07 PM
Try renaming your input from Action to act or formAction. There may be a reserved word conflict there, since action is a property of a form object.

ClueLess
12-11-2002, 07:12 PM
Thanks for your help all. it doesn't work because it gets confuse, it doesn't know which one that I checked. I put them inside of switch and case, then it works:thumbsup: :)