PDA

View Full Version : need help! about calling input type="file" by using checkbox.



kee149
10-12-2006, 05:43 AM
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


<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

bdichiara
10-12-2006, 02:28 PM
instead of this

<div id="Layer1">
<input type="file" name="idcard_file<? echo $forArrayValue; ?>"
style="position:absolute; z-index:1; VISIBILITY: hidden;">
</div>

use this:

<div id="Layer1" style="display:none">
<input type="file" name="idcard_file<? echo $forArrayValue; ?>">
</div>

and instead of this:

<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:

<input type="checkbox" name="idcard<? echo $forArrayValue; ?>"
onClick="toggleFileField('idcard_file<? echo $forArrayValue; ?>');">

and add this above the head tag:


<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>