Jump to content
Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Sign in to follow this  
Anastasis

Automatically Clear Default Form Values

Recommended Posts

free-html5-frameworks.png

 

Στο head:

κώδικας:
<script>
function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}
</script>



Στο κάθε στοιχείο της φόρμας:

κώδικας:
ONFOCUS="clearDefault(this)"


πχ:

κώδικας:
<input type="text" name="name" value="το όνομα σας" ONFOCUS="clearDefault(this)">



EDIT:
Ο 3dots μου έδωσε έναν καλύτερο τρόπο που όταν ξαναπατήσεις έξω από τη φόρμα εμφανίζεται το αρχικό value:

κώδικας:
onblur="if(this.value=='') this.value='otinanai';" onfocus="if(this.value=='otinanai') this.value='';"


πχ:

κώδικας:
<input type="text" name="name" value="otinanai" onblur="if(this.value=='') this.value='otinanai';" onfocus="if(this.value=='otinanai') this.value='';">

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×