html - JavaScript after Form Handling spit content on page -
hello i'm trying make website enter name , gets spit out on page. want using javascript.
html:
<div id='errormsg'></div> <form action='' method='post' onsubmit="formsubmit();"> <input id='name' type='text' placeholder='slogan here...'> <input id='submit' type='submit' value='generate'> </form> <div id="namecontent"></div>
js:
function formsubmit() { var formname, formerror, namesentence; formerror = document.getelementbyid("errormsg"); formname = document.getelementbyid("name"); namesentence = document.getelementbyid("namecontent"); if (formname == "") { formerror.innerhtml = "put name in!"; } else if (formname > 20) { formname.innerhtml = "max. 20 characters"; } else { namesentence.innerhtml = formname ; } }
the first problem doesn't give me result. i'm in learning process of javascript please tell me wrong. divs errormsg
, namecontent
on page. not problem. i want happen without jquery plain javascript
i have noticed few variables not needed.
value of widget accessed id formname removed.
function formsubmit() { var formerror = document.getelementbyid("errormsg"); var namecontent = document.getelementbyid("namecontent"); var formslogan = document.getelementbyid("name").value; if (formslogan == "") { formerror.innerhtml = "put name in!"; } else if (formslogan.length > 20) { formerror.innerhtml = "max. 20 characters"; } else { formerror.innerhtml = ""; namecontent.innerhtml = formslogan; return true; } return false; }
<div id='errormsg'></div> <form action='' method='post' onsubmit="formsubmit();"> <input id='name' type='text' placeholder='slogan here...'> <input id='submit' type='submit' value='generate'> </form> <div id="namecontent"></div>
Comments
Post a Comment