2

I have two text input boxes that will need to be populated from the same selection list but each text box may have different values. What happens is that the code I have written allows you to click and change on value but when you try to do change the second value it changes both values rather than just the second value. I have looked at bind, text with no luck.

Input Boxes: <input type="text" id="lensStyle" size="35" class="orderinput" tabindex="12"/> <input type="text" id="lensStyleLeft" size="35" class="orderinput" tabindex="12"/>

grabs the values in from:

<select class="longbox" size="14" id="lensStyleBox"></select>

using this Jquery

    $("#lensStyle").focus(function(){
        $("#lensStyleBox").click(function(){
            $("#lensStyle").val($("#lensStyleBox").val());
        });

    });


    $("#lensStyleLeft").focus(function(){
        $("#lensStyleBox").click(function(){
            $("#lensStyleLeft").val($("#lensStyleBox").val());
        });
    });
3
  • Id have to see more on this to be sure, but you might want to make a function where you do say $('#lensStyleBox').click and check which element has focus there, using IF, and change it. Commented Apr 9, 2012 at 21:02
  • 1
    This question makes no sense as you've written it. Commented Apr 9, 2012 at 21:02
  • 1
    try to make jsfiddle.net demo with your code. Commented Apr 9, 2012 at 21:05

2 Answers 2

1

You need to unbind the click handlers as the focus changes. This should do the trick - http://jsfiddle.net/WPjgc/

Sign up to request clarification or add additional context in comments.

1 Comment

The unbind did the trick, my solution was was to just put the unbind under the select box.
0

Try below code, If you want the text box to be populated on focus with the selection you had in the drop down.

$("#lensStyle, #lensStyleLeft").focus(function(){
    $(this).val($("#lensStyleBox").val());
});

What you are doing doesn't seems correct. Let us know if this is not something you need.

1 Comment

That was not what I was looking for. I can get the box to populate off a json call. What I had was that I was trying to get two seperate values from the same list. So I had the select list and then two separate text boxes that the value could be any value in the selection box. The problem was that it was binding the event. Unbinding worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.