Yohanne Posted June 25, 2014 Share Posted June 25, 2014 Hi What is the wrong with this code? !DOCTYPE html> <head> <script type="text/javascript"> $('#mylist').change(function(){ if( $(this).val() == '3'){ $('body').append('<input id="myInput" type="text" value = "wwwwwwwww"/>'); }else{ $('#myInput').remove(); } }); </script> </head> <body> <select id="mylist"> <option selected></option> <option value="1" >aaaa</option> <option value="2">bbb</option> <option value="3">ccc</option> </select> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/289280-select-not-work-and-why/ Share on other sites More sharing options...
trq Posted June 25, 2014 Share Posted June 25, 2014 How should we know? You need to actually describe your problem. http://www.catb.org/esr/faqs/smart-questions.html Quote Link to comment https://forums.phpfreaks.com/topic/289280-select-not-work-and-why/#findComment-1483190 Share on other sites More sharing options...
Yohanne Posted June 25, 2014 Author Share Posted June 25, 2014 Okay, sorry.. and here is. i have a select box to identify input type. under selection there are 1,2 and 3 values that there are different function, that i need to show upon selecting. the code avobe is not working, i mean is, when i selecting each value in option box, there is nothing happen. i want to show value "wwwwwwwww", after selecting value 3. Quote Link to comment https://forums.phpfreaks.com/topic/289280-select-not-work-and-why/#findComment-1483191 Share on other sites More sharing options...
Jacques1 Posted June 25, 2014 Share Posted June 25, 2014 Your script runs before the element exists. You need $(document).ready(). Quote Link to comment https://forums.phpfreaks.com/topic/289280-select-not-work-and-why/#findComment-1483192 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.