Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question to change the type of an element form via JS?

    Hi there is there a way to change the type o an element form via JS?

    I have a HIDDEN field and I want it to "convert" into a text type element depending on the selected value of a SELECT elemnet.
    I tried
    Code:
    document.FormName.HiddenName.type="text";
    but obviusly that didn't work.
    Please help.

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    Surrey, UK
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Changing the type of form element is buggy across the browsers. There is no brower AFAIK that can successfully transform each type reliably. Far better at present may be to remove the hidden element and add a text in it's place
    document.forms[0].replaceNode(textElement, hiddenElement)
    You should of course copy values etc beforehand in your function that calls the above line.

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thnx for the qick answer, but i have a cuestion:
    does this replacement needs the tow elemnets already created or can be created from code like an add_element statement?
    any way here it is my code:
    MyForm = registro
    MyHidden field =otro
    My Select element = MODELO_CEL
    ChecaOtro() is called in the onchange event of the select
    Code:
    function PonOtro()
    {
    	document.registro.otro.type="text";
    }
    function QuitaOtro()
    {
    	document.registro.otro.type="hidden";
    }
    function ChecaOtro()
    {
    
    	document.registro.MODELO_CEL.value<0?PonOtro():QuitaOtro();
    }

  • #4
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Start here and read to the next-to-last post on the page.

  • #5
    New Coder
    Join Date
    Apr 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    ok now I can hidde it, thnx I don't care if it post a value in the php vars....
    but how can i show it again
    I tried
    Code:
    document.registro.otro.style.display=true;
    but that does not work, how can I make it apear...
    Thnx for the help

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by yo_era_wert
    ok now I can hidde it, thnx I don't care if it post a value in the php vars....
    but how can i show it again
    I tried
    Code:
    document.registro.otro.style.display=true;
    but that does not work, how can I make it apear...
    Thnx for the help
    Reread ahosang's & Choopernickel's posts again. Noone said anything about changing the visibility of the form element but rather removing the hidden input and replacing it with a text input.

    If you follow Choopernickel's link you will find a working example.

    .....Willy

  • #7
    New Coder
    Join Date
    Apr 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    I don't want to replace them I just want to show, hidde them.
    I know how tu hidd eit, butn no how to show it agan.
    document.registro.otro.style.display="none"; ->it hiddes it
    which one it shows it again?
    thnx for the help

  • #8
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    document.registro.otro.style.display="block";
    I think that's what you're after.

    Sadiq.

  • #9
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by yo_era_wert
    Hi there is there a way to change the type o an element form via JS?

    I have a HIDDEN field and I want it to "convert" into a text type element
    Perhaps I misunderstood.
    Hide/Show, replace hidden with text?????

    .....Willy
    Last edited by Willy Duitt; 04-24-2004 at 04:56 AM.

  • #10
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The type of the input element is read only. You can't change that, but you can replace the element with a new one, which you set the type attribute to text on instead, and which you have copied the value to.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #11
    New Coder
    Join Date
    Apr 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    You are totally rigth Willy Duitt, I first wanted to change the type and or convert the element of a form, but that was cos i tought that It will be the esyest way to do it, but since I read some of the links they put in my post, I change mi mind and I prefer to just Hidde/Unhidde the element.

    Thanx to any one for the help

  • #12
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question I have a question regarding this specfically for Internet Explorer.

    I have a form where users checks off certain checkboxes, one of them is an "Other" box and when that box is checked I have a piece of javascript code to change the input type to TEXT so the user can fill in what the value of "Other" should be.

    This code works fine in both Mozilla and Firefox (my prefered browser support, but you know you have to support poor IE users). Under Internet Explorer when the checkbox is selected, "a command not supported error" is displayed. Does anyone know a workaround for IE? I would really like to keep this type of function if possible as it is clean.

    Code:
    Other:<input type="checkbox" name="fieldname" tabindex="30" onClick='if ( this.checked )document.forms[1].fieldname=document.forms[1].fieldname.type="text"; else;'>
    any help would be appreciated.
    -josh

  • #13
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Did you read the whole thread especially post#2 by ahosang and the link posted by Choopernickel? You dug the thread up from oblivion so I assumed you took time to read the whole discussion.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •