Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

change a textfield into a password field by a button press

hello is it possibe to change a input text field into a input password field with a button click?

Thanks,
Ferry
0
ferryl
Asked:
ferryl
  • 5
  • 2
  • 2
  • +1
1 Solution
 
NushiCommented:
change the type to:

type='password'

Nushi.
0
 
ferrylAuthor Commented:
I have try this: document.form.field.type='password'
but it don't work i get this error: Could not get the type property. This command is not supported.

Is there a other solution?
0
 
NushiCommented:
<script>
function changeType( objId ){
      var src =  document.getElementById( objId );
      var type = 'password' ;
      
      //create the new object as a password field
      var input ='';
      input += '<input type=' + type + ' ';
      input += ' name=' + src.name + ' ';
      input += ' id=' + src.id + ' ';
      input += ' value=' + src.value + ' ';
      input += '><br>';
      
      document.getElementById('myField').innerHTML = input;
      }
</script>

<span id='myField'>
<input type='text' id='textField' value='password'><br>
</span>
<input type="button" onclick="changeType( 'textField' )">


Nushi
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
devicCommented:
try this:
==================================
<form name=myform>
<input name=textfield type=text value=devic>
</form>
<script>
function runit()
{
      document.myform.textfield.outerHTML="<input type=password name=textfieldsasa value="+document.myform.textfield.value+">"
}
</script>
<button onclick=runit()>runit()</button>
0
 
NushiCommented:
devic

its the same code i wrote for him.

Nushi.
0
 
NushiCommented:
the concept is to create new element.
0
 
Michel PlungjanIT ExpertCommented:
Except Nushis code would work in Mozilla too which does not have support for outerHTML...
However would the form submit the content???
0
 
NushiCommented:
mplungjan
my guru see all as always

 :-))
0
 
ferrylAuthor Commented:
thank, but is it not possbile without the innerHTML?
0
 
devicCommented:
@ Nushi,

you think that my code is same with your? ;)

@mplungjan, including mozilla, opera
ok here is another version:
=======================
<form name=myform>
<input name=textfield type=text value=devic>
<input name=other type=text value=devic>
</form>
<script>
function runit()
{
    formHTML =document.myform.innerHTML.split("<");
      for(var i=0;i<formHTML.length;i++)
      {
            if(formHTML[i].match(/textfield/))
            {
                  formHTML[i]="input name=textfield type=password value=devic>";
            }
      }
      document.myform.innerHTML=formHTML.join("<")
}
</script>
<button onclick=runit()>runit()</button>
======================================
@ferryl,
yes it possbile:
write manual new form ;)


0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now