UnknownPlayer Posted December 17, 2010 Share Posted December 17, 2010 Need help with function to make "file" textbox read only, onclicl event, when radio("pic") is value "1" or "3". Form: <form id="contacts-form" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="500000" /><input type="hidden" name="aid" value="'.$aid.'" /> <div class="field"><label>Naziv:</label> <input type="text" name="name" value="'.$name.'" /></div> <div class="field"><label>Sastojci:</label> <input type="text" name="info" value="'.$info.'" /></div> <div class="field"><label>Cena:</label> <input type="text" name="price" value="'.$price.'" onKeyUp="checkNumber(this);" />RSD.</div> <div class="field"><label>Promeni sliku:</label> <input name="file" type="file" /></div> <div class="field"><label>Ostavi postojecu sliku</label> <input type="radio" name="pic" value="1" checked ></div> <div class="field"><label>Postavi novu sliku</label> <input type="radio" name="pic" value="2" ></div> <div class="field"><label>Izbrisi sliku</label> <input type="radio" name="pic" value="3" ></div> <br /><br /> <input type="submit" name="edit" value="Izmeni" /> </form>'; Can someone help me? Link to comment https://forums.phpfreaks.com/topic/221965-func-to-readonly-textbox-on-radio-click/ Share on other sites More sharing options...
trq Posted December 17, 2010 Share Posted December 17, 2010 What exactly is the problem? Link to comment https://forums.phpfreaks.com/topic/221965-func-to-readonly-textbox-on-radio-click/#findComment-1148571 Share on other sites More sharing options...
brianlange Posted December 17, 2010 Share Posted December 17, 2010 The readonly attribute is for text input fields and password fields. Use the disabled property instead. In the code below I loop through all the radio buttons with a tag name of 'pic'. If the value is 1 or 3 it is assigned the function that disables the file input. Otherwise the onclick event for the radio button will trigger the function that enables the file input. Here's a working: http://gonavygolf.com/test2.html <script> window.onload = function() { var disableFile = function() { document.getElementById('uploadFile').disabled = "disabled"; } var enableFile = function() { document.getElementById('uploadFile').disabled = false; } var pics = document.getElementsByName('pic'); for (var i = 0; i < pics.length; ++i) { if (pics[i].value == "1" || pics[i].value == "3") { pics[i].onclick = disableFile; } else { pics[i].onclick = enableFile; } } }; </script> Link to comment https://forums.phpfreaks.com/topic/221965-func-to-readonly-textbox-on-radio-click/#findComment-1148761 Share on other sites More sharing options...
UnknownPlayer Posted December 18, 2010 Author Share Posted December 18, 2010 Thanks, it works, now just one more thing. When i go to that page, default is "pic" = "1" radio, now i need to put that when load page to set disabled id "uploadFile" ? Link to comment https://forums.phpfreaks.com/topic/221965-func-to-readonly-textbox-on-radio-click/#findComment-1148848 Share on other sites More sharing options...
trq Posted December 18, 2010 Share Posted December 18, 2010 When i go to that page, default is "pic" = "1" radio, now i need to put that when load page to set disabled id "uploadFile" ? That sentence makes no sense. Link to comment https://forums.phpfreaks.com/topic/221965-func-to-readonly-textbox-on-radio-click/#findComment-1148851 Share on other sites More sharing options...
brianlange Posted December 18, 2010 Share Posted December 18, 2010 Just set the checked attribute for the first radio button and set the disabled attribute for the file input. Here's the code: http://gonavygolf.com/test2.html Link to comment https://forums.phpfreaks.com/topic/221965-func-to-readonly-textbox-on-radio-click/#findComment-1148874 Share on other sites More sharing options...
UnknownPlayer Posted December 21, 2010 Author Share Posted December 21, 2010 When i go to that page, default is "pic" = "1" radio, now i need to put that when load page to set disabled id "uploadFile" ? That sentence makes no sense. It make sanse.. u just need to be more helpfull.. Thank you brianlange.. Link to comment https://forums.phpfreaks.com/topic/221965-func-to-readonly-textbox-on-radio-click/#findComment-1149913 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.