Jump to content

Html dropdown menu insert into text box?


farbods0

Recommended Posts

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

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 by farbods0
Link to comment
Share on other sites

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

 

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...