html - JavaScript - Outputting a line with Document Write -
i trying output line javascript document.write function, however, on submitting form, line flashes , disappears
any thoughts?
<!doctype html> <html> <head> <title>form validation</title> </head> <body> <script type="text/javascript"> function checkage() { var x = document.forms['myform']['age'].value; if(x < 18) { document.write("<p>you young. form not submitted</p>"); } else { document.write("form sent successfully"); } } function tips() { alert("please enter name in name box, \nand age in age box.\nyou have on 18 submit form"); } </script> <form id="myform" action="formvalidation.html" onsubmit="checkage();"> name: <input type="text" name="text" id="name"> age: <input type="text" name="age" id="age"> <input type="submit" value="submit"> <input type="button" value="help" id="hbtn" onclick="tips();"> </form> </body> </html>
you can't use document.write()
print on current page.
calling document.write()
automatically call document.open()
clears current document , present content cleared.
alternatively can use html <div id="result"></div>
, change it's value this,
document.getelementbyid("result").innerhtml = "some text";
Comments
Post a Comment