PDA

View Full Version : tex clear and reset IE working on NS


[m]
12-14-2002, 09:06 AM
this is a small java script I made that has the labeling text inside the text box, when u click on the text box it clears out the text that was in it so that u can type in it. if u didn't type anything and click out of it it returns back to the label. if u did type something in it stays. I just wrot it for IE cuz I didn't have NS, but now that I have NS I guess I'l make it so it works:)
my hosting is down so here it is:

<!doctype html public "-//w3c//dtd html 3.2//en">
<!-== Copyright ©2002, mike.==- if you decide to modifiy this script I'd like to know how you changed it my mail is: mike77800@hotmail.com>
<html>
<head>
<title>loginSystem</title>
<script>
function inputMod(nameOfbox, valueOfbox){
if(nameOfbox.value==valueOfbox){
nameOfbox.value='';
}else
if(nameOfbox.value==""){
nameOfbox.value=valueOfbox;
}
return(0);
}
</script>
</head>
<body background="" bgcolor="#ffffff" text="#000000" link="#c0c0c0" vlink="#c0c0c0" alink="#c0c0c0">
<center>Login information, input name and password<br><br>
<input type="text" name="username" size="20" maxlength="16" value="Username" onfocus='inputMod(username, "Username")' onblur='inputMod(username, "Username")'><br>
<input type="text" name="password" size="20" maxlength="16" value="Password" onfocus='inputMod(password, "Password")' onblur='inputMod(password, "Password")'><br>
<INPUT TYPE="submit" VALUE="Login"><br><br>
<br>Copyright ©2002, mike.
</center>
</body>
</html>


the function:
inputMod(nameOfbox, "valueOfbox")
says the name of the textbox and you can modifiy what it will say

Borgtex
12-15-2002, 12:06 AM
if you decide to modifiy this script I'd like to know how you changed it

That sounds like an invitation for me. ;) Well, my version has the following improvements:

-Smaller code
-Works in NS 4 (the old didn't)
-Easier to use: it can be used easily with any input box without need to specify the help message every time. The script gets it from the .value in the first onfocus.



<html>
<head>
<title>loginSystem</title>

<script>
function inputMod(obj)
{
if (!obj.hlptext) obj.hlptext=obj.value
obj.value=(obj.hlptext==obj.value)?'':(obj.value=='')?obj.hlptext:obj.value
}
</script>

</head>
<body background="" bgcolor="#ffffff" text="#000000" link="#c0c0c0" vlink="#c0c0c0" alink="#c0c0c0"><form>
<center>Login information, input name and password<br><br>
<input type="text" name="username" size="20" maxlength="16" value="Username" onfocus='inputMod(this)' onblur='inputMod(this)'><br>
<input type="text" name="password" size="20" maxlength="16" value="Password" onfocus='inputMod(this)' onblur='inputMod(this)'><br>
<INPUT TYPE="submit" VALUE="Login"><br><br>
<br>Copyright ©2002, mike.
</center></form>
</body>
</html>

[m]
12-15-2002, 05:53 AM
ooow I like that thanx for the really cool inprovements. I have never seen it done like that!

I am learning new things here every day woot!

I never woulda thought of putting "this" in the..other thing

glenngv
12-17-2002, 02:03 AM
this is much shorter:


<input type="text" name="username" size="20" maxlength="16" value="Username" onfocus="this.value=''" onblur="if (this.value=='')this.value=this.defaultValue"><br>

<input type="text" name="password" size="20" maxlength="16" value="Password" onfocus="this.value=''" onblur="if (this.value=='')this.value=this.defaultValue"><br>

Borgtex
12-17-2002, 02:31 AM
wow! never seen .defaultvalue before. You really can learn new things everyday :)