Current location: Hot Scripts Forums » General Web Coding » JavaScript » change input type


change input type

Reply
  #1 (permalink)  
Old 06-25-09, 03:08 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
change input type

I wrote a little piece of javascript that should change the appearance of an input field:

Code:
function alias_focus2()
{
	if(document.getElementById('sPassword').value == 'password')
	{
		document.getElementById('sWachtwoord').style.color = 'black';		
		document.getElementById('sWachtwoord').value = '';
		document.getElementById('sWachtwoord').type = 'password';
		
	}	
}

function alias_blur2()
{
	if(document.getElementById('sPassword').value == '')
	{
		document.getElementById('sWachtwoord').style.color = 'grey';		
		document.getElementById('sWachtwoord').value = 'password';
		document.getElementById('sWachtwoord').type = 'text';
	}	
}
and this is the HTML for that:

HTML Code:
<input name="sPassword" id="sPassword" type="text" class="zkn" value="password" onfocus="alias_focus2();"  onblur="alias_blur2();" style="color: grey; font-style:italic;" />
on FF and Safari it works.. but on IE it's not working well...
Where did I go wrong?

_j
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-25-09, 05:37 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Changing the type property in IE is forbidden.
You must use two input elements to perform the trick you want.

Example:
PHP Code:

<?php
$pass 
= empty($_POST["sPassword"]) ? "" $_POST["sPassword"];
$wach = empty($_POST["sWachtwoord"]) ? "" $_POST["sWachtwoord"];
echo 
"sPassword = " $pass "<br />sWachtwoord = " $wach "<br />";
?>
<html>
<head>
<script>
function display_password_element(obj,id)
{
 obj.style.display = "none";
 var obj1 = document.getElementById(id);
 obj1.style.display = "inline";
 obj1.focus();
 }
function display_text_element(obj,id)
{
 if(!obj.value)
 {
  obj.style.display = "none";
  document.getElementById(id).style.display = "inline";
  }
 }
</script>
</head>
<body>

<!-- Note: Input elements must be used in pairs. -->

<form action="#" method="POST">
<table>
 <tr>
  <td align="right">Enter Password: </td>
  <td>
   <!-- These two input elements are used for the first password. -->
   <input id="sPassword" type="text" class="zkn" value="password" onfocus="display_password_element(this,'sPassword1');" style="color:grey;font-style:italic;width:100px;" />
   <input name="sPassword" id="sPassword1" type="password" class="zkn" onblur="display_text_element(this,'sPassword');" style="display:none;width:100px;" />
  </td>
 </tr>
 <tr>
  <td align="right">Re-enter password: </td>
  <td>
   <!-- These two input elements are used for the second password. -->
   <input id="sWachtwoord" type="text" class="" onfocus="display_password_element(this,'sWachtwoord1');" style="color:grey;font-style:italic;width:100px;" value="password" />
   <input name="sWachtwoord" id="sWachtwoord1" type="password" class="" onblur="display_text_element(this,'sWachtwoord');" style="display:none;width:100px;" />
  </td>
 </tr>
 <tr>
  <td colspan="2" align="center">
   <br />
   <input type="submit" value="Submit" />
  </td>
 </tr>
</table>
</form>
</body>
</html>
__________________
Jerry Broughton

Last edited by job0107; 06-25-09 at 05:49 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-29-09, 03:07 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
Great!

this is what i was looking for!!


_j
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change background on select text input pms JavaScript 4 06-17-09 12:28 PM
Input type values DJH PHP 1 12-02-08 03:56 PM
[SOLVED] Is there an INPUT TYPE = CREATE FILE? jej1216 PHP 4 09-08-08 05:37 PM
Change default color for selected text on a input text jabaltie CSS 0 09-28-04 02:19 PM
How come Account_Type and Organization cannot accept user input? toezaurus81 C/C++ 1 07-30-04 02:59 PM


All times are GMT -5. The time now is 12:55 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.