You may use something like this
var input = $('#input_field');
var hidden = $('<input type="text" id="'+input.attr('id')+'"
value="'+input.val()+'" class="'+input.attr('class')+'"
/>').insertBefore(input);
input.remove();
See http://dev.jquery.com/ticket/1957 for more information

newbuntu wrote:
> 
> I have a hidden "old_name" input. When "new_name" is changed, I want the
> "old_name" to appear by changing the type from "hidden" to "text". It
> gives me a script error. I guess I'm not allowed to change the "type"
> attribute. 
> 
> However, I can change "disabled" attribute without problem.
> 
> Can anyone throw some light on this?
> 
> Thx!
> <head>
> <script>
> $(document).ready(function() {
> 
>     $("#new_name").blur(function () {
> 
>       if (this.value != '') {
>                //$('#dis_name').removeAttr('disabled'); // this works too
>                old_name.value += new_name.value;
> 
>                $('#dis_name').attr('disabled', ''); // set disable to ''
>                $('#old_name').attr('type', 'text'); // set type to 'text'
> 
>       }
>     });
> 
>  });
> </script>
> </head>
> 
> <body>
> 
> disabled <input id='dis_name' type='text' disabled='disabled'
> value='Dis/Enable'> <br>
> old name <input id='old_name' type='hidden'  value='old '> <br>
> new name<input id='new_name' value=''>
> 
> </body>
> 

-- 
View this message in context: 
http://www.nabble.com/Can-you-change-the-%22type%22-attribute-of-an-%3Cinput%3E--tp22753958s27240p23104580.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to