[Javascript] Adding more HTML to DIV with form

Nick Fitzsimons nick at nickfitz.co.uk
Tue Jun 13 12:46:31 CDT 2006


Peter Lauri wrote:
> Thank you for such a great answer. Can I create 10 different divs that
> contain the fields I need, and then just use the "style" to make is visible
> or not? I would limit to maximum 10 files, but that is well enough in my
> case.
> 

Yes, that would be a good way to go. In addition, remember that 
uploading large files can take a while, so it's a good idea to limit the 
number a user can choose in one go.

For a quick and simple way to show and hide stuff, have a look at Dustin 
Diaz's toggle() function at:
<http://www.dustindiaz.com/top-ten-javascript/>
- scroll down to number 6. You'd call it with something like:

// show or hide the third input
toggle("myFileInput" + 3);

where your HTML would have a file input with id="myFileInput3".

Alternatively, you can split the toggle function into show() and hide() 
functions - just break out the two parts of the if...else..., setting 
display to "none" to hide and to "" (an empty string) to show. 
(Depending on any CSS you have applying to the inputs, you can replace 
the empty string with "block" or "inline" to match what's in the CSS.)

Cheers,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/





More information about the Javascript mailing list