lynsey93 Posted August 6, 2011 Share Posted August 6, 2011 Hello! I have never done Javascript, but I am creating a form on my site that I believe will need it. I'd like to have a drop down box at the top of the form that has the options of text or image, and then if text is selected a text box appears next or if image is selected then an upload box appears next, without having to submit the form. Can this be done? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/244018-form-changes-based-on-dropdown-selection/ Share on other sites More sharing options...
zavaboy Posted August 6, 2011 Share Posted August 6, 2011 It can be done. Here's an example: JavaScript: ddChange = function(val){ if (val=='text'){ document.getElementById('mytext').style.display='inline'; document.getElementById('myimage').style.display='none'; }else if (val=='image'){ document.getElementById('mytext').style.display='none'; document.getElementById('myimage').style.display='inline'; }else{ document.getElementById('mytext').style.display='none'; document.getElementById('myimage').style.display='none'; } } HTML: <select name="myselect" onchange="ddChange(this.value)"> <option value="">Please Select</option> <option value="text">Text</option> <option value="image">Image</option> </select> <input type="text" id="mytext" name="mytext" style="display:none" /> <input type="file" id="myimage" name="myimage" style="display:none" /> jsFiddle: http://jsfiddle.net/xbRh8/ Quote Link to comment https://forums.phpfreaks.com/topic/244018-form-changes-based-on-dropdown-selection/#findComment-1253166 Share on other sites More sharing options...
lynsey93 Posted August 16, 2011 Author Share Posted August 16, 2011 Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/244018-form-changes-based-on-dropdown-selection/#findComment-1258026 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.