...

View Full Version : Applying CSS class to a file type input element using JavaScript



ArunKumarS
05-06-2009, 10:10 AM
Hi all,

I am trying to create an input element of type file using the javascript. I am able to create it but the problem i am facing is, i need to apply a CSS class to the control. Can some one let me know how to do the same.

I am pasting the code that i am using to create a control.

function AddUploadFile()
{
var newrow = document.getElementById("files_tbl").insertRow(document.getElementById("files_tbl").rows.length);
var td1 = newrow.insertCell(0);
var hiddenFile = document.createElement("input");

hiddenFile.id = "File" + document.getElementById("files_tbl").rows.length;
hiddenFile.name = "File" + document.getElementById("files_tbl").rows.length;
hiddenFile.type = "file";
hiddenFile.className = "uploadtool";
hiddenFile.runat = "server";
td1.appendChild(hiddenFile);
}

Thanks & Regards,
Arun :)

Maddi
05-06-2009, 01:15 PM
use the below logic, it may help you :thumbsup:

var x = document.getElementsByTagName('input');
for (var i=0;i<x.length;i++)
{
x[i].className = 'file hidden';
}

Regards, MSS

_Aerospace_Eng_
05-06-2009, 01:17 PM
Look into this
http://www.quirksmode.org/dom/inputfile.html

and this

http://www.emblematiq.com/projects/niceforms/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum