Solved

change a textfield into a password field by a button press

Posted on 2003-11-26
10
429 Views
Last Modified: 2012-08-14
hello is it possibe to change a input text field into a input password field with a button click?

Thanks,
Ferry
0
Comment
Question by:ferryl
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 10

Expert Comment

by:Nushi
ID: 9824140
change the type to:

type='password'

Nushi.
0
 
LVL 1

Author Comment

by:ferryl
ID: 9824159
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
 
LVL 10

Expert Comment

by:Nushi
ID: 9824179
<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
 
LVL 25

Accepted Solution

by:
devic earned 20 total points
ID: 9824203
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
 
LVL 10

Expert Comment

by:Nushi
ID: 9824207
devic

its the same code i wrote for him.

Nushi.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 10

Expert Comment

by:Nushi
ID: 9824209
the concept is to create new element.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9824220
Except Nushis code would work in Mozilla too which does not have support for outerHTML...
However would the form submit the content???
0
 
LVL 10

Expert Comment

by:Nushi
ID: 9824248
mplungjan
my guru see all as always

 :-))
0
 
LVL 1

Author Comment

by:ferryl
ID: 9824255
thank, but is it not possbile without the innerHTML?
0
 
LVL 25

Expert Comment

by:devic
ID: 9824607
@ 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now