Hi,
I m new to JavaScript. And I have a webpage where a user can upload 5 images. so I have five input tags, but I want to give him add extra image option,when a user hit add extra image a new input tag appeare.
how can I do that using Javascript?
Thanks in advance.
m.cliter
0
Newbie Poster
Recommended Answers
Jump to PostAbsolutely
function addInput(parentID) { newInput = document.createElement('input'); newInput.type = 'file'; newInput.name = '<put name you want here>'; document.getElementByID(parentID).appendChild(newInput); }
So if you have a form such as
<form action="something.php" method="POST" enctype="multipart/form-data" id='imagesForm'>
You would have something along this lines
<input type="button" …
Jump to Postwhoops, sorry, lowercase d,
document.getElementById(parentID).appendChild(newInput);
Jump to PostIE seems to create a tbody element after <table> so attempting to add the tr to the <table> tag will not work so we have to get the parent element then get the parent of that
function addInput(parentID) { newInput = document.createElement('input'); newInput.type = 'file'; newInput.name = …
Jump to Postvar numInputs = 0; function addInput(){ ... newInput.name = "upload"+parseInt(numInputs); numInputs++; ... }
All 15 Replies
ShawnCplus
456
Code Monkey
Team Colleague
m.cliter
0
Newbie Poster
ShawnCplus
456
Code Monkey
Team Colleague
m.cliter
0
Newbie Poster
ShawnCplus
456
Code Monkey
Team Colleague
m.cliter
0
Newbie Poster
ShawnCplus
456
Code Monkey
Team Colleague
m.cliter
0
Newbie Poster
m.cliter
0
Newbie Poster
ShawnCplus
456
Code Monkey
Team Colleague
peter_budo
commented:
Good job
+7
m.cliter
0
Newbie Poster
m.cliter
0
Newbie Poster
m.cliter
0
Newbie Poster
ShawnCplus
456
Code Monkey
Team Colleague
m.cliter
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.