...

View Full Version : to change the type of an element form via JS?



yo_era_wert
04-23-2004, 08:11 PM
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

document.FormName.HiddenName.type="text";
but obviusly that didn't work.
Please help.

ahosang
04-23-2004, 08:18 PM
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.

yo_era_wert
04-23-2004, 08:26 PM
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

function PonOtro()
{
document.registro.otro.type="text";
}
function QuitaOtro()
{
document.registro.otro.type="hidden";
}
function ChecaOtro()
{

document.registro.MODELO_CEL.value<0?PonOtro():QuitaOtro();
}

Choopernickel
04-23-2004, 09:58 PM
Start here (http://www.codingforums.com/showthread.php?p=194363#post183276) and read to the next-to-last post on the page.

yo_era_wert
04-23-2004, 11:25 PM
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
document.registro.otro.style.display=true; but that does not work, how can I make it apear...
Thnx for the help

Willy Duitt
04-23-2004, 11:48 PM
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
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

yo_era_wert
04-24-2004, 12:19 AM
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

sad69
04-24-2004, 12:29 AM
document.registro.otro.style.display="block";


I think that's what you're after.

Sadiq.

Willy Duitt
04-24-2004, 05:53 AM
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 :eek:

liorean
04-24-2004, 06:02 AM
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.

yo_era_wert
04-26-2004, 04:38 PM
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 :thumbsup:

jsm1th
03-15-2005, 11:05 PM
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.


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

glenngv
03-16-2005, 03:22 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum