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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

show input field using javascript 1

Status
Not open for further replies.

speedyrudolf

Programmer
Sep 2, 2009
27
RO
Hi. I'm having some trouble showing some tables (originally hidden). I have an input field, and when the user clicks a button another field becomes visible...the user can do this up to 9 times. The problem is that when I click the button, the field stais hidden.
The code is:

function Add_fis_img(i){
document.getElementById('Fis_img').display="";}

<input type="file" id="Fis_img" name="Fis_img" size="100" disabled="true" onchange="Cont_pag3()">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="button" name="Add_img1" value="Adauga fisier" onclick="Add_fis_img(1)"><br/>
<input type="file" id="Fis_img" name="Fis_img" size="100" style="display: none">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="button" name="Add_img2" value="Adauga fisier" onclick="Add_fis_img(2)"><br/>
<input type="file" id="Fis_img" name="Fis_img" size="100" style="display: none">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="button" name="Add_img3" value="Adauga fisier" onclick="Add_fis_img(3)"><br/>

Well...I included just the basics...i don't think anything else has something to do with my problem...and yes, I know that there is another javascript function being called, but it worked (and still works) fine before adding the other input fields, so it's not relevant in this example.

And I tried writing a number at the end of the id and making the function use the field directly (document.form.Fis_img.display=""), tried including the fields in a table (and a few other variations), but that also doesn't work... But submit your ideas anyway...maybe I didn't try it... :D

Thank you in advance.

 
Id's are supposed to be unique, that means that no more than one element can have a single Id.

With that said getElementById returns a single object not an array that you can reference as you are doing.


Perhaps what you want is getElementsByName() which retunrs an array of all elements with the same name, then you could use the array reference: .

and finally the display is part of the style of an object so you need to reference it through style.


Code:
   document.get[red]ElementsByName[/red]('Fis_img')[i].[red]style[/red].display="";



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Yep...I forgot to write "style" :D...now it works perfectly...thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top