I need to change the maxlength attribute of a text box when a button is clicked. I can't figure out why this is not working. Changing the size attribute works fine but I don't know what is wrong with the maxlength code. If someone could provide some insight, it would be appreciated. Thanks!!!
<HTML>
<HEAD>
<TITLE>alert</TITLE>
<script language="javascript">
function numtester1(){
x=document.form5.tb1.value
if(isNaN(x))
{
alert("you did not enter a number")
}
else
{
document.form5.tb2.size=x
}
}
function numtester2(){
x=document.form5.tb1.value
if(isNaN(x))
{
alert("you did not enter a number")
}
else
{
document.form5.tb2.maxlength=x
}
}
function disabler1(){
if(document.form5.r2[0].checked=true)
{
document.form5.tb2.disabled=true
}
}
function enabler1(){
if(document.form5.r2[1].checked=true)
{
document.form5.tb2.disabled=false
}
}
</script>
</HEAD>
<BODY>
<form name="form5">
<p align=center>10 marks</p>
1. The user must enter a numeric value in the box on the left in the second row of the table.<br>
2. The user then selects a button<br>
If what they entered is not numeric alert them please enter a numeric value.<br>
Otherwise change the corresponding attribute of the text box in the first row of the table.<br>
3. The user can choose one of the radio buttons to disable or enable the text box in the first row of the table.<br>
<p>
<table border=1>
<td colspan=3><td align=center><input type="text" name="tb2" maxlength=1 size="1" ></td></tr>
<td align=middle colspan=3>Enter a value<br>
<input type="text" name="tb1"></td>
<td align=center>Choose a button to use the entered value<br>
<input type="button" value="change size attribute of text box" onClick="numtester1()"><br>
<input type="button" value="change maxlength attribute of text box" onClick="numtester2()"></td>
<td align=middle>Choose one<br>
<input type="radio" name="r2" onClick="disabler1()"> Disable text box<br>
<input type="radio" name="r2" onClick="enabler1()"> Enable text box<br>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>alert</TITLE>
<script language="javascript">
function numtester1(){
x=document.form5.tb1.value
if(isNaN(x))
{
alert("you did not enter a number")
}
else
{
document.form5.tb2.size=x
}
}
function numtester2(){
x=document.form5.tb1.value
if(isNaN(x))
{
alert("you did not enter a number")
}
else
{
document.form5.tb2.maxlength=x
}
}
function disabler1(){
if(document.form5.r2[0].checked=true)
{
document.form5.tb2.disabled=true
}
}
function enabler1(){
if(document.form5.r2[1].checked=true)
{
document.form5.tb2.disabled=false
}
}
</script>
</HEAD>
<BODY>
<form name="form5">
<p align=center>10 marks</p>
1. The user must enter a numeric value in the box on the left in the second row of the table.<br>
2. The user then selects a button<br>
If what they entered is not numeric alert them please enter a numeric value.<br>
Otherwise change the corresponding attribute of the text box in the first row of the table.<br>
3. The user can choose one of the radio buttons to disable or enable the text box in the first row of the table.<br>
<p>
<table border=1>
<td colspan=3><td align=center><input type="text" name="tb2" maxlength=1 size="1" ></td></tr>
<td align=middle colspan=3>Enter a value<br>
<input type="text" name="tb1"></td>
<td align=center>Choose a button to use the entered value<br>
<input type="button" value="change size attribute of text box" onClick="numtester1()"><br>
<input type="button" value="change maxlength attribute of text box" onClick="numtester2()"></td>
<td align=middle>Choose one<br>
<input type="radio" name="r2" onClick="disabler1()"> Disable text box<br>
<input type="radio" name="r2" onClick="enabler1()"> Enable text box<br>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
Comment