FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Simple js help

 


imagefree
I dont know js at all. So, can someone please help me giving a script that does the following work.



When someone clicks the form field ( say INPUT ) the initial value in it is removed and when person clicks somewhere outside the field, the value is reset to its original state.

I mean initially the form has value "ANONYMOUS" , when clicked inside the field, the value is removed, when again clicked outside the field, again "ANOMYNOUS" comes in the field.


How to do this? Give me simple example

Thanks
alalex
Ok you can create a function to do that:
To make this function work for other initial values, the first parameter is the initial value

In the head paste the following snippet:
Code:
<script type="text/javascript" language="javascript">
function initVal(val,id){
   if(val==document.getElementById(id).value){
      document.getElementById(id).value = '';
   }else if(document.getElementById(id).value == ''){
      document.getElementById(id).value = val;
   }
}
</script>


And here is a sample text field with it working:
Code:
<input name="whatever" type="text" id="whatever" value="ANONYMOUS" size="40" maxlength="40" onfocus="initVal('ANONYMOUS',this.id)" onblur="initVal('ANONYMOUS',this.id)" />


I didn't have time to run the script but it should work fine on all browsers
imagefree
thanks, its working.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.