Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want make my textbox REQUIRED FIELD id is BotBootInput what should i put in "document.write" line



XML
<script type="text/javascript">
    var a = Math.ceil(Math.random() * 10);
    var b = Math.ceil(Math.random() * 10);
    var c = a + b
    function DrawBotBoot()
    {
        document.write("What is "+ a + " + " + b +"? ");
        document.write("<input id='BotBootInput' type='text' maxlength='2' size='2'/>");
    }
    function ValidBotBoot(){
        var d = document.getElementById('BotBootInput').value;
        if (d == c) return true;
        return false;

    }
    </script>





PLEASE HELP ME.
Posted

 
Share this answer
 
You can use the HTML Code as :

<form action="">
 Username: <input type="text" name="usrname" required="">
<input type="submit">
</input></input></form> 



You can use the HTML & JavaScript:

<form name="myForm" action=""   önsubmit="return validateForm()" method="post">
 First name: <input type="text" name="fname">
 <input type="submit" value="Submit">
 </form>

<script language="JavaScript">
function validateForm() {
     var x = document.forms["myForm"]["fname"].value;
     if (x == null || x == "") {
         alert("First name must be filled out");
         return false;
     }
 }
</script>
 
Share this answer
 
v3
fiddle for making the textbox required field[^]

You can try out with the above fiddle. In this fiddle, if you focus out of the textbox without giving the value or leaving it empty, it throws an alert that Field cannot be empty and the focus still stays on the same text box, which is vital in this case.
Hope this helps
Thanks
Happy Coding
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900