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

asp.net - Procedure or function "Procedure name" expects a parameter "Param name" which was not supplied occurs rarely -

jsp - No mapping found for HTTP request with URI with annotation config Spring MVC and Jetty -

sql server ce - Is there some way to make sqlce3.5 and 4.0 co-exist in the C# project -