PDA

View Full Version : Attempt at null value


h8ids
04-05-2006, 10:18 PM
I have two text boxes.
The goal is to control the content of the second based upon the content of the first.

Example: If the content of box one is "No", then JavaScript will automatically remove data from box two.

Here is what I have worked out so far. I know it is incomplete, still learning the basic JS coding.




<script>
function fieldCheck(myfield){
if (myfield.value=="No" || elementid=="NO")
document.getElementById(LabTimes)="";
}
</script>

<!--Will there be a lab-->
<br><b>4.</b> Lab: <input type="Text" size="3" maxlength="3" name="LaboratoryYesNo" onBlur="fieldCheck(this)" value="">
&nbsp;&nbsp;&nbsp;"Yes" or "No"<br>

<!--Lab times-->
&nbsp;&nbsp;&nbsp;&nbsp;<b>Lab times:</b> <input type="Text" size="40" maxlength="40" name="LabTimes" value="">

rm-f
04-05-2006, 11:27 PM
<input type="Text" size="40" maxlength="40" name="LabTimes" value="">

<input type="Text" size="40" maxlength="40" name="LabTimes" value="" id="LabTimes">

h8ids
04-06-2006, 09:28 PM
rm-f

I applied your suggestion. But the data in box two is being retained, instead of being deleted.

The code looks right.

D

thelinuxduck
04-06-2006, 09:50 PM
Make sure that you do have the ID= as rm-f suggested, and then change the fieldCheck function to:

function fieldCheck(myfield) {
if(myfield.value.match(/no/i)) { document.getElementById('LabTimes').value = ''; }
}


The three issues were that the LabTimes was not in quotes in the getElementById function, the LabTimes input was missing the ID tag, and the return value of getElementById was not being accessed via the value key.

h8ids
04-12-2006, 09:15 PM
thanks for your help. It's working