javascript - Show me if all inputs are empty -
i need build such 4 inputs must specified such if there nothing in name must appear trouble nothing written in name.
i want want out of not have use such can create user or send email must have written in every input form.
i have done this:
<form action="#" method="post" name="kontakt_box"> <span id="myhint" class="info_box_kontakt"></span> <br /> <label>navn<br /><input type="text" name="navn" class="new" placeholder="navn"></label><br /> <label>efternavn<br /><input type="tel" name="efternavn" class="new" placeholder="efternavn"></label><br /> <label>email<br /><input type="email" name="email" class="new" placeholder="email"></label><br /> <label>tekst<br /><textarea name="tekst" cols="35" rows="10" class="new"></textarea></label><br /> <label><input type="submit" name="send" value="send" class="new"></label> </form>
javascript here:
document.kontakt_box.navn.onfocus=function() { document.getelementbyid('myhint').innerhtml = "angive et navn!"; } document.kontakt_box.navn.onblur=function() { document.getelementbyid('myhint').innerhtml = ""; } //efternavn document.kontakt_box.efternavn.onfocus=function() { document.getelementbyid('myhint').innerhtml = "angive et efternavn!"; } document.kontakt_box.efternavn.onblur=function() { document.getelementbyid('myhint').innerhtml = ""; } //email document.kontakt_box.email.onfocus=function() { document.getelementbyid('myhint').innerhtml = "angive en email!"; } document.kontakt_box.email.onblur=function() { document.getelementbyid('myhint').innerhtml = ""; } document.kontakt_box.send = function(){ alert('husk noget tekst!'); return false; }
it's first javasciprt task page, better me there may errors or think it's strange made.
your last function may this:
document.kontakt_box.onsubmit = function(){ var navn = document.kontakt_box.navn.value, efternavn = document.kontakt_box.efternavn.value, email = document.kontakt_box.email.value, tekst = document.kontakt_box.tekst.value; if(!navn || !efternavn || !email || !tekst) { alert('husk noget tekst!'); return false; } };
and add ;
afret each callback function assignment.
working example here http://jsbin.com/enovex/1/edit
Comments
Post a Comment