techker Posted June 24, 2012 Share Posted June 24, 2012 Hey guys i looking for a tutorial for forms that have drop downs or check boxes that influences other fields.. like if you select yes a box appears with reason why.. if you select no box stays as is... so i guess IF's in a html form.. Quote Link to comment https://forums.phpfreaks.com/topic/264676-html-form-choices/ Share on other sites More sharing options...
NathanCH Posted June 26, 2012 Share Posted June 26, 2012 This can easily be achieved using jQuery. If someone has a different method I'd also like to know. Here's how I did it: $(document).ready(function() { $(".classOfForm").change(function() { if ($(".classOfForm").val() == "0"){ $(".classYouWannaHide").hide(); } else { $(".classYouWannaHide").show(); } }); }); So basically assign .classOfForm to the check box or form selection you want to change. And give the form you want to appear a class of .classYouWannaHide Let me know if you need further help. Quote Link to comment https://forums.phpfreaks.com/topic/264676-html-form-choices/#findComment-1357114 Share on other sites More sharing options...
techker Posted June 26, 2012 Author Share Posted June 26, 2012 thx for the help!il look it up. what should i be looking for? Quote Link to comment https://forums.phpfreaks.com/topic/264676-html-form-choices/#findComment-1357119 Share on other sites More sharing options...
NathanCH Posted June 27, 2012 Share Posted June 27, 2012 The jQuery event is called "change". Here is a link: http://api.jquery.com/change/ Quote Link to comment https://forums.phpfreaks.com/topic/264676-html-form-choices/#findComment-1357363 Share on other sites More sharing options...
techker Posted June 27, 2012 Author Share Posted June 27, 2012 thx!i will read up about it. Quote Link to comment https://forums.phpfreaks.com/topic/264676-html-form-choices/#findComment-1357364 Share on other sites More sharing options...
mikhl Posted July 19, 2012 Share Posted July 19, 2012 You could write a simple JavaScript function to do this for you. function setState(element, state) { var elem = document.gelElementById(element): elem.style.display(state); In HTML: <input type="checkbox" value="yes" name="name" onchange="setState('elementID', 'block');" /> You would replace none with inline or block to set the element to display. The CSS display attribute of each element will have to be set to none. This code is not tested and may not be 100% complete Quote Link to comment https://forums.phpfreaks.com/topic/264676-html-form-choices/#findComment-1362658 Share on other sites More sharing options...
techker Posted July 19, 2012 Author Share Posted July 19, 2012 thx i will try it out. Quote Link to comment https://forums.phpfreaks.com/topic/264676-html-form-choices/#findComment-1362684 Share on other sites More sharing options...
hakimserwa Posted July 20, 2012 Share Posted July 20, 2012 in php it is archieved with the ifs and get functions. if checks to see if the value isset and the the get posts the value in the url then you set the action acording to the get value Quote Link to comment https://forums.phpfreaks.com/topic/264676-html-form-choices/#findComment-1363150 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.