dsonesuk Posted December 12, 2016 Share Posted December 12, 2016 Well i guess you did it wrong then, shame. Link to comment Share on other sites More sharing options...
farbods0 Posted December 13, 2016 Author Share Posted December 13, 2016 Well i guess you did it wrong then, shame. Lol well that was a different response than expected Link to comment Share on other sites More sharing options...
dsonesuk Posted December 13, 2016 Share Posted December 13, 2016 What did you expect, you say it delets what you type? Which I don't understand how? since it only supposed to show an alert message with every character you type with keypress, you don't supply ANY code to explain how, why its doing this, and it seems like you expect me to do it ALL for you, which is not going to happen, YOU are supposed to be learning to do this, at least make some attempt to LEARN if you still have problems with the code, then show code and i will attempt to help you further. Link to comment Share on other sites More sharing options...
farbods0 Posted December 13, 2016 Author Share Posted December 13, 2016 (edited) What did you expect, you say it delets what you type? Which I don't understand how? since it only supposed to show an alert message with every character you type with keypress, you don't supply ANY code to explain how, why its doing this, and it seems like you expect me to do it ALL for you, which is not going to happen, YOU are supposed to be learning to do this, at least make some attempt to LEARN if you still have problems with the code, then show code and i will attempt to help you further. Sorry this is what it's like <script type="text/javascript"> $(document).ready(function() { var dropDown = [" ","Run1", "Run2", "Testplan", "Rails", "Europa"]; var dropDownID = [" ","111111", "222222", "333333", "444444", "555555"]; $("#dropDown").select2({ data: dropDown }); //Adding ID to dropdown menu $("#dropDown").change(function() { $("#dropdownID").val(dropDownID[$("#dropDown option:selected").index()]); }); $(document).ready(function(){ $("#dropdownID").keypress(function(){ $("#dropdownID").val(dropDownID[$("#dropDown option:selected").index()]); }); }); }); </script> <!--ID REF--> <br><br> Testrail Plan ID:<input type="text" id="dropdownID"><br><br> Edited December 13, 2016 by farbods0 Link to comment Share on other sites More sharing options...
dsonesuk Posted December 13, 2016 Share Posted December 13, 2016 You do not place a $(document).ready within a $(document).ready, and why on earth would you target the exact same selector of element input you are inputting in, I thought the idea was to target the customized dropdown wasn't it? That was a miserable attempt to just put anything in there, so you decided to copy the previous and insert that, hoping that would be enough so I will give you a solution, FAILED! Someone else's problem now, you can't put the effort in, so I won't bother to help now bye! Link to comment Share on other sites More sharing options...
thescientist Posted December 15, 2016 Share Posted December 15, 2016 Sorry this is what it's like <script type="text/javascript"> $(document).ready(function() { var dropDown = [" ","Run1", "Run2", "Testplan", "Rails", "Europa"]; var dropDownID = [" ","111111", "222222", "333333", "444444", "555555"]; $("#dropDown").select2({ data: dropDown }); //Adding ID to dropdown menu $("#dropDown").change(function() { $("#dropdownID").val(dropDownID[$("#dropDown option:selected").index()]); }); $(document).ready(function(){ $("#dropdownID").keypress(function(){ $("#dropdownID").val(dropDownID[$("#dropDown option:selected").index()]); }); }); }); </script> <!--ID REF--> <br><br> Testrail Plan ID:<input type="text" id="dropdownID"><br><br> I think you would find a lot of value in properly indenting and formatting your code, which a good IDE or text editor would do for you. Aside from that, yes, you only need one $(document).ready function. This is jQuery's recommended way of initializing your javascript to be sure that the DOM has loaded and that all the elements that you would expect to be there are there and so it only needs to be done once. https://learn.jquery.com/using-jquery-core/document-ready/ Clean up your code again and try another pass at this, and make sure to think about what is happening, line by line. Write it out in psuedo-code if it helps first (I find it can) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now