Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 08-01-2005, 03:59 PM   #1 (permalink)
 
Newb Techie

Join Date: Jul 2005

Posts: 11

pierreba

Default Javascipt Help

Iam building a page that contains in it a username and a password...
The username and password fields start as type="text" and of " E-mail or Username" and " Password" values.

When a user clicks on the username(Onfocus), its value changes to "" and the field is focused to be written in. On the other hand, if the user keeps the field empty "" (onblur) the field changes back to " E-mail or Username".. This has worked fine with me as you can see in the script.

When a user clicks on password(Onfocus), it calls a function that changes the innerHTML of a the span containing the password's field... the password field changes type to "Password" and is empty and focused ready to be written at.... NOW... I want that if the value of the password field is left empty "", I want it to change type back to "text" and take the value " Password"... I did it but it is not working with me... I appreciate any help...

The script is:

<script language="javascript">
function changetopassword(){

if(document.signin.password.value==" Password"){

document.getElementById("spanpassword").innerHTML= "<input type=\"password\" name=\"password\" class=\"signin\" id=\"newpasswordfield\" />" ;
document.signin.password.focus()
document.signin.password.focus()
}

}
function changetotext() {
if(document.signin.password.value==""){
document.getElementById("spanpassword").innerHTML= "<input type=\"text\" name=\"password\" class=\"signin\" value=\" Password\"/>"
}
}
</script>

<form name="signin" method="POST" style="padding: 0; margin-top: 0px; ,margin-bottom: 0px">
<input type="text" name="username" value=" E-mail or Username" class="signin" onFocus="if(this.value == ' E-mail or Username') this.value='';" onblur=" if (this.value=='')this.value=' E-mail or Username';">

<br style="line-height: 5px">
<span id="spanpassword"><input type="text" name="password" value=" Password" class="signin" onFocus="changetopassword('spanpassword');" onblur="changetotext('spanpassword')"> </span>
<input type="image" src="images/home/signin.jpg" align="middle" style="margin-left:14px " width="47" height="18">

</form>
pierreba is offline  
Old 08-03-2005, 07:39 PM   #2 (permalink)
 
Junior Techie

Join Date: Jun 2005

Posts: 94

ever_thus

Default

Is the above the exact code you used? Because when you call the changetopassword and changetotext functions you pass them a argument, but when you define them you don't give them a parameter. In such a case Javascript won't recognise them as the same function and simply won't call anything on the onFocus and onBlur events.

In IE if there's an error in Javascript it's indicated in the bar at the bottom left. I don't know if calling an undefined function is considered an error, but i imagine it is. Check it out.
ever_thus is offline  
Old 08-04-2005, 05:17 AM   #3 (permalink)
 
Newb Techie

Join Date: Jul 2005

Posts: 11

pierreba

Default

No this is not an error, as long as the function is defined correctly... any additional parameter given is ignored....
Anyways I removed them and still the problem is the same..

Anyways, in the above script... the "OnFocus=" is working...... its only the onBlur that is not...
pierreba is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On