Using jscript to click type=file button

Discussion in 'JavaScript' started by Snarf, Jun 27, 2006.

  1. #1
    Hi, I'm trying to make a page with HTML, PHP and JS wich should realise a file upload. The code i'm using is shown below :

    <code>
    <script type="text/javascript">
    function getfile(){
    document.getElementById('hiddenfile').click();
    document.getElementById('selectedfile').value=document.getElementById('hiddenfile').value
    }
    </script>

    <FORM ACTION="<?php echo(BASENAME($_SERVER['PHP_SELF']))?>" METHOD=POST enctype=multipart/form-data NAME=general>
    <TR><TD>
    <input type="file" id="hiddenfile" name="hiddenfile" value="<?echo $_POST['hiddenfile'];?>"/>
    <input type="text" id="selectedfile" value="<?echo $_POST['selectedfile'];?>"/>
    <input type="button" value="Select a file" onclick="getfile()" />
    <input type="submit" value="Verstuur"/>
    </TR</TD>
    </code>

    The problem is that the submit clears the field with name="hiddenfile" on the moment (before, i believe) the upload must be realised, so there is no upload no filled $_FILES. Who can tell me what i'm doing wrong ?

    Greets Frans
     
    Snarf, Jun 27, 2006 IP