javascriptwindow.onunload

on Window.onload form is not loading


on Window.onload form is not loading My code is :

<script language="javascript" type="text/javascript"> 
window.onload=formOnWindowLoad();
function formOnWindowLoad(){
setTimeout(function(){document.getElementById('fileUploadForm');},3000);
}
</script>
</head>
<body >
<br>Select a file to upload: <br />
<form id="fileUploadForm" action="fileLocalUpload.htm?eId=${eId}&tId=${tId}" method="post"enctype="multipart/form-data"> 
<input id="uploadFileOnRemoteServer" type="file" name="uploadingFile" />
<br />
<input type="submit" value="Upload File" />
</form>

I want file select box on window onload


Solution

  • Your function is working, but you are not doing anything with that function. You are just getting the elemant thats it.

    If you want to open the file upload after some interval, this code works for you. I have kept an alert for your understanding.

    window.onload=formOnWindowLoad();
    function formOnWindowLoad(){
     setTimeout(function(){
     document.getElementById('uploadFileOnRemoteServer').click()},500);
    }
    <br>Select a file to upload: <br />
    <form id="fileUploadForm" action="fileLocalUpload.htm?eId=${eId}&tId=${tId}" method="post"enctype="multipart/form-data"> 
    <input id="uploadFileOnRemoteServer" type="file" name="uploadingFile" />
    <br />
    <input type="submit" value="Upload File" />
      
    </form>

    This works for you.If that is your requirement.It will open after 3 seconds.

    Go through this link...