Click to See Complete Forum and Search --> : <input type="file" /> .. click() method


maikki
04-28-2007, 09:47 AM
hi guys

how can I recall 'click()' method of the <input type="file" /> by clickin on another <input type="button" />

i have code:

<script ... >
function browse() {
document.getElementById('upFile').click();
}

function setPath(path) {
document.getElementById('newPath').value = f;
}
</script>

<form ... >
<input type="file" id="upFile" onChange="setPath(this.value);" />
<input type="text" id="newPath" />
<input type="button" id="myButton" onClick="browse();" />
</form>

-------------
problem is:
under IE it opens the file browse dialog, but under mozilla and opera not

please help me solve it cause i go mad of it

Fang
04-28-2007, 12:13 PM
The way to do obj.click() in Fx/Opera is with createEvent-dispatchEvent (http://developer.mozilla.org/samples/domref/dispatchEvent.html), but it will not work with file input.
The reason is either security is or that the file 'button' is not part of the DOM tree.