SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript does not change input field value. Possibly confilct of 2 javascripts.

    Here is sample http://jsfiddle.net/rigaconnect/gLCjy/14/

    Enter something in left top field. Right top field value changes to 1. That is ok.

    Then press and hold ctrl and click in left bottom field. Left bottom field value becomes the same as left top field's value. This is also ok.

    But right bottom field value does not change. This is the problem... Actually no idea. Need advice to which direction to go....

    If type/copy without using ctrl+click, everything is ok. But with ctrl+click does not work...

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,043
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    I simplified your script a little, but this should work:

    HTML Code:
    <!DOCTYPE HTML>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Unbenanntes Dokument</title>
        <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
      </head>
    
      <body>
        <div>
          <input type="text" id="input1" size="1">
          <input type="text" id="input2" size="1">
        </div>
        <div>
          <input type="text" id="input3" size="1">
          <input type="text" id="input4" size="1">
        </div> 
        
        <script>
          $("#input1").on("change", function(){
            $("#input2").val("1");
          });
          
          $("#input3").on("click", function(e){
            if(e.ctrlKey){
              $(this).val($("#input1").val());
              $("#input4").val($("#input2").val());
            }
          });
        </script>
      </body>
    </html>
    Hope that helps.

  3. #3
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! It works!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •