rugzo Posted April 6, 2009 Share Posted April 6, 2009 Hi all, I have a question about the checkbox. I have an input field in my form. <input type="file" name="box> and i have a checkbox <input type="checkbox" name ="checkbox"> i want that the checkbox is automatically checked when a file for upload is selected. Can anyone help me with that. I tried something like if(isset($_POST['box']);"checkbox value";"1"); but had no success. thanks in advance Link to comment https://forums.phpfreaks.com/topic/152803-checkbox-automatic-check/ Share on other sites More sharing options...
Yesideez Posted April 6, 2009 Share Posted April 6, 2009 <input type="checkbox" name="checkbox" selected> Link to comment https://forums.phpfreaks.com/topic/152803-checkbox-automatic-check/#findComment-802441 Share on other sites More sharing options...
rugzo Posted April 6, 2009 Author Share Posted April 6, 2009 Thanks for the quick reply. I tried it but nothing happens when i click on browse and select a file to be uploaded. The box remains unchecked. Link to comment https://forums.phpfreaks.com/topic/152803-checkbox-automatic-check/#findComment-802451 Share on other sites More sharing options...
premiso Posted April 6, 2009 Share Posted April 6, 2009 I think you need to change "selected" to be "checked" Selected is more for <select> statements. Link to comment https://forums.phpfreaks.com/topic/152803-checkbox-automatic-check/#findComment-802457 Share on other sites More sharing options...
rugzo Posted April 6, 2009 Author Share Posted April 6, 2009 I tried something --> <script language="javascript"> function isaretle() { form2.box.checked=true ; } </script> ------------- <input type="file" name="dosya" onKeyDown="isaretle()"><br /> <input type="checkbox" name="box"> If i type someting into the input field 'dosya', the code works and the box is checked automatically. But if i click on browse to select a file the box remains uncheck and this is what i need. Link to comment https://forums.phpfreaks.com/topic/152803-checkbox-automatic-check/#findComment-802489 Share on other sites More sharing options...
premiso Posted April 6, 2009 Share Posted April 6, 2009 Why are you creating a checkbox for this? $fileUploaded = isset($_FILE['dosya']['name'])?true:false; Would be a more reliable way of testing. Link to comment https://forums.phpfreaks.com/topic/152803-checkbox-automatic-check/#findComment-802496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.