/    Sign up×
Community /Pin to ProfileBookmark

Javascript – apply image help

I have a javascript to add additional file fields to my form. It is set to write the word “Remove” next to the added fields. This will remove the added fields from the page and will not send the values. I need to change the text content “Remove” and display and image that uses the same link to remove the field. Any help would be greatly appricated.

My code: ( The area of the “remove” text is in read )

<input name=”attachment” type=”file” id=”attachment” onchange=”document.getElementById(‘moreUploadsLink’).style.display = ‘block’;” />

<div id=”moreUploads”></div>

<div id=”moreUploadsLink” style=”display:none;”><a href=”javascript:addFileInput();”><img src=”images/addfile.jpg” border=”0″ /></a></div>

<script type=”text/javascript”>
var upload_number = 2; function addFileInput() { if(upload_number > 3) { alert(‘Sorry you can only upload 3 files’); exit(0); }

var d = document.createElement(“div”); var l = document.createElement(“a”); var file = document.createElement(“input”); file.setAttribute(“type”, “file”); file.setAttribute(“name”, “attachment”+upload_number); l.setAttribute(“href”, “javascript:removeFileInput(‘f”+upload_number+”‘);”);[COLOR=”Red”]l.className = ‘remove-btn’; l.appendChild(document.createTextNode(“Remove”)); [/COLOR]d.setAttribute(“id”, “f”+upload_number); d.appendChild(file); d.appendChild(l); document.getElementById(“moreUploads”).appendChild(d); upload_number++; var i = document.createElement(“IMG”);
i.setAttribute(“src”,”pics/one.png”);c.appendChild(i);}

function removeFileInput(i) { var elm = document.getElementById(i); document.getElementById(“moreUploads”).removeChild(elm); upload_number = upload_number – 1; }// decrement the max file

</script>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 21.2009 — l.className = 'remove-btn';
[COLOR="Blue"]var remove = document.createElement("img");
remove.setAttribute("src","pics/remove.png");
l.appendChild(remove);
[/COLOR]d.setAttribute("id", "f"+upload_number); d.appendChild(file);
×

Success!

Help @rmorton spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...