Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing field types by reference 1

Status
Not open for further replies.

snakeeyes1978

Programmer
Jan 11, 2005
70
AU
Hi there. Got a bit of a problem with Javascript. I have a series of ten fields which are of type 'hidden' when the page loads. When a user clicks on a checkbox, it executes the script below and passes in the name of the hidden field which I want displayed, but it doesn't seem to work. All I need to do is tell Javascript to change the field passed into the function from type 'hidden' to type 'text' thus making it visible - any ideas?

function Other(field) {
document.getElementById(field).type = 'text';
}
 

Not all (if any) browsers will let you change the type of an input field once it is created.

You could try using CSS to hide standard text fields instead.

Hope this helps,
Dan

 
Yeah that's what I ended up doing. You can actually hide the field using javascript. But when the page loads you still see the text box before it gets hidden by the pageload event .. bit annoying.
 
Sorry, my skills with CSS syntax is not that great - could you please give me an example.
 

Add a style attribute to the input element like this:

Code:
<input type="text" style="display:none;" />

Hope this helps,
Dan

 
Terrific, thanks for that, but now I need to know how to unhide the field when necessary. The existing code:

if(document.styleSheets)field.style.visibility = 'visible';

(where 'field' is the field name) doesn't seem to work anymore.
 

This should work:

Code:
document.forms['yourFormName'].elements['yourElementName'].style.display = '';

If it doesn't work, replace the last '' with 'inline'.

Hope this helps,
Dan

 
I used this approach but it seems that some vertical space is being retained. Is there something else that could be taking up some vertical space?
 
Hiya Windycity1,

I didn't have any problems at all, no vertical space was being retained for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top