...

View Full Version : Trouble with event handling



h8ids
07-10-2006, 11:14 PM
Need to have a disabled submit button automatically become active if a certain value is passed from a DB.

Trying to utilize the JS "onload" event command to call a function. The function should activate the submit button, "EditRecord", even if one checkbox is checked.

Anyone see what I'm missing, aside from tylenol.


<script src="javascript.js"></script>
<form name="form2">
<TABLE>
<TR><TD>Record number 7</TD>
<TD>Reviewed<br><input disabled type='checkbox' name='Reviewed' checked></TD>
<TD>Accepted<br><input disabled type='checkbox' name='AcceptDenyChrYES' checked></TD>
<TD>Denied<br><input onload='EditON()' id='NO' disabled type='checkbox' name='AcceptDenyChrNO' value='YES'></TD>
<TD>Department Chair<br>
<textarea>Accepted</textarea>
</TD></TR>

<TR><TD width='230'></TD>
<TD>Reviewed<br><input disabled type='checkbox' name='Reviewed' checked></TD>
<TD>Accepted<br><input disabled type='checkbox' name='AcceptDenyRegYES' checked></TD>
<TD>Denied<br><input onload='EditON()' id='NO' disabled type='checkbox' name='AcceptDenyRegNO' value='YES'></TD>
<TD>Department Chair<br>
<textarea>Accepted</textarea>
</TD></TR>

<TR><TD width='230'></TD>
<TD>Reviewed<br><input disabled type='checkbox' name='Reviewed' checked></TD>
<TD>Accepted<br><input disabled type='checkbox' name='AcceptDenyCCYES' checked></TD>
<TD>Denied<br><input onload='EditON()' id='NO' disabled type='checkbox' name='AcceptDenyCCNO' value='YES'></TD>
<TD>Department Chair<br>
<textarea>Accepted</textarea>
</TD></TR>

<TFOOT><TR>
<TD><a href='http://localhost/addedit.php?Records=101'>
<input disabled type='submit' name='EditRecord' id='EditRecord' value='Edit Record' title='Edit record'></a></TD>
</TR></TFOOT>
</form>


JavaScript inc file


function EditON(){
if ((name='AcceptDenyChrNO') == 'checked')
document.form2.EditRecord.disabled=false;
else if ((name='AcceptDenyRegNO') == 'checked')
document.form2.EditRecord.disabled=false;
else if ((name='AcceptDenyCCNO') == 'checked')
document.form2.EditRecord.disabled=false;}

Fumigator
07-10-2006, 11:24 PM
Seems ok, unless there is a syntax error in there somewhere-- are you getting any javascript errors?

Also you didn't include your <body> tag so I can't tell if your onload= statement is correct.

Beagle
07-10-2006, 11:35 PM
(name='AcceptDenyChrNO')

I think this is the probelm. It seems that you copied and pasted this from your html, I think you mean:

if (document.form2.AcceptDenyChrNO.checked)
{
document.form2.EditRecord.disabled=false;
}

h8ids
07-11-2006, 10:04 PM
BEAGLE,

Adjusted my function to the following:


function EditON(){
if (document.form2.AcceptDenyChrNO.checked)
document.form2.EditRecord.disabled=false;
else if (document.form2.AcceptDenyRegNO.checked)
document.form2.EditRecord.disabled=false;
else if (document.form2.AcceptDenyCCNO.checked)
document.form2.EditRecord.disabled=false;
}

Although the submit button is remaining disabled; the logic makes sense. JavaScript alerts have proven that the Javascript.js file is not being accessed; but everything looks correct.

Adjusted the checkbox code too. Example of checkbox code:


<html>
<head>
</head>
<body>
<script src="javascript.js"></script>
<form name="form2">
<TABLE>
<TR><TD>Record number 7</TD>
<TD>Reviewed<br><input disabled type='checkbox' name='Reviewed' checked></TD>
<TD>Accepted<br><input id='AcceptDenyChrYES' disabled type='checkbox' name='AcceptDenyChrYES' checked></TD>
<TD>Denied<br><input onload='EditON()' id='AcceptDenyChrNO' disabled type='checkbox' name='AcceptDenyChrNO' value='YES'></TD>
<TD>Department Chair<br>
<textarea>Accepted</textarea>
</TD></TR>

<TFOOT><TR>
<TD><a href='http://localhost/addedit.php?Records=101'>
<input disabled type='submit' name='EditRecord' id='EditRecord' value='Edit Record' title='Edit record'></a></TD>
</TR></TFOOT>
</form></body></html>

Beagle
07-11-2006, 10:22 PM
attach the onload to your body tag, not you elements.

do you want the button to disable/enable every time you click checkboxes? then you want to put the function in the onclick attribute of the checkbox.

h8ids
07-12-2006, 04:04 PM
Adjusted the code. Now onload is only located in the opening body tag.

Weird thing occurred.
Originally, I had several DIV tags between the Body and Form tags. I moved the FORM tag, positioning it immediately after the BODY tag. The only difference: all objects positioned by the DIV tags moved.
So I placed the FORM tag back to its original position. Refreshed the page and voila! All page objects repositioned themselves and the button began functioning correctly.

Why would this happen if there was nothing wrong with the code in the beginning?
It's not a browser specific issue; both Firefox and IE have reacted the same way.
I keep finding that the FORM tag must follow the DIV tags in order for the TOPMARGIN to equal "0".
This doesn't seem normal to me.

Beagle
07-12-2006, 04:16 PM
Each structural element has it's own default style attributes. For example, divs display as block elements, span as inline.

The structure of your page definitely has an effect on the layout. It doesn't seem strange to me at all that moving your form tag up the DOM tree would position everything else differently, because now the divs have a new parent document with margins, padding, etc.

I think you should definitely pursue the issue through experimentation and ask the people in the HTML/CSS forum how to get the layout you want and why specific things look specific ways.

h8ids
07-12-2006, 05:01 PM
I will pursue the differences between inline versus block.

Do you know why there would be such a strange occurance to get a page working?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum