JavaScript change input type="text" to type="file" -


Then I have a code like this:

   Script type = "text / javascript" & gt; Function fund () {var input = document.getElementById ("id"); Var input2 = input.cloneNode (wrong); If (document.getElementById ("butid") value == 'upload') {input2.type = 'text'; Input.parentNode.replaceChild (input 2, input); Document.getElementById ("butid"). Value = 'URL'; } And {input2.type = 'file'; Input.parentNode.replaceChild (input 2, input); Document.getElementById ("butid") value = 'Upload'; }} & Lt; / Script & gt; & Lt; Input id = "id" type = "text" name = "id" value = "upload" / & gt; & Lt; Input type = "button" id = "butid" value = "upload" onclick = "fundx ()" />  

This text field is to be converted in the file upload field and vice versa.

What should I do to fix the current code is not working?

The problem with cloning is that you can not change the type of an existing element, Once) can set the type for.

Try it

  function fundx (var input) = Document.getElementById ("id"); Var input2 = document.createElement ('input'); Input2.id = input.id; Input2.name = input.name; Input2.value = input.value; If (document.getElementById ("butid") value == 'upload') {input2.type = 'text'; Input.parentNode.replaceChild (input 2, input); Document.getElementById ("butid"). Value = 'URL'; } And {input2.type = 'file'; Input.parentNode.replaceChild (input 2, input); Document.getElementById ("butid") value = 'Upload'; }}  


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -