Results 1 to 2 of 2

Thread: need help! about calling input type="file" by using checkbox.

  1. #1
    Join Date
    Oct 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help! about calling input type="file" by using checkbox.

    i want to make a checkbox, and when we check in a checkbox it will show a dialog. after we choose some image file, we submit.

    my code
    Code:
    <td><div align="center"><font size = 2  face="Arial, Helvetica, sans-serif">
    <div id="Layer1">
    <input type="file" name="idcard_file<? echo $forArrayValue; ?>" 
    style="position:absolute; z-index:1; VISIBILITY: hidden;">
    </div>
    <input type="checkbox" name="idcard<? echo $forArrayValue; ?>" 
    onClick="if (document.forms['frm_visa'].elements['idcard<? echo $forArrayValue; ?>'].checked==true) 
    document.forms['frm_visa'].elements['idcard_file<? echo $forArrayValue; ?>'].click();">
    </font>
    </div>
    </td>
    i wanna make a dynamic array for showing checkbox with PHP, anyway my problem is when i press submit button it's doesn't go on, i have to click twice .. ??? i don't understand so i try to change VISIBILITY: visible;. then i knew that the first press it make <input type="file" name="idcard_file<? echo $forArrayValue; ?>" style=" position:absolute; z-index:1; VISIBILITY: hidden;"> to be empty value and second press go to submit the form.


    i dunno why ? I can't continue my program cause it can't get a file value.

    pls help me
    thk a lot
    kee

  2. #2
    Join Date
    Oct 2006
    Location
    AL
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    instead of this
    Code:
    <div id="Layer1">
    <input type="file" name="idcard_file<? echo $forArrayValue; ?>" 
    style="position:absolute; z-index:1; VISIBILITY: hidden;">
    </div>
    use this:
    Code:
    <div id="Layer1" style="display:none">
    <input type="file" name="idcard_file<? echo $forArrayValue; ?>">
    </div>
    and instead of this:
    Code:
    <input type="checkbox" name="idcard<? echo $forArrayValue; ?>" 
    onClick="if (document.forms['frm_visa'].elements['idcard<? echo $forArrayValue; ?>'].checked==true) 
    document.forms['frm_visa'].elements['idcard_file<? echo $forArrayValue; ?>'].click();">
    try this:
    Code:
    <input type="checkbox" name="idcard<? echo $forArrayValue; ?>" 
    onClick="toggleFileField('idcard_file<? echo $forArrayValue; ?>');">
    and add this above the head tag:
    Code:
    <script type="text/javascript" language="javascript">
        function toggleFileField(id){
    	    if(document.forms['frm_visa'].elements[id].checked == true){
    		    document.getElementById("Layer1").style.display = '';
    	    } else {
    		    document.getElementById("Layer1").style.display = 'none';
    	    }
        }
    </script>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •