Web Analytics Made Easy -
StatCounter change maxlength attribute of text box onclick - CodingForum

Announcement

Collapse
No announcement yet.

change maxlength attribute of text box onclick

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • change maxlength attribute of text box onclick

    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.&nbspThe user must enter a numeric value in the box on the left in the second row of the table.<br>

    2.&nbspThe 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.&nbspThe 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()">&nbspDisable text box<br>

    <input type="radio" name="r2" onClick="enabler1()">&nbspEnable text box<br>
    </td>
    </tr>
    </table>
    </form>

    </BODY>

    </HTML>

  • #2
    I think the property is called by "maxLength", with a capital "L", not "maxlength". If you change that, does your script work then?
    De gustibus non est disputandum.

    Comment


    • #3
      Thank you! Something so small. Your help is appreciated. Have a great day!!

      Comment

      Working...
      X