Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Javascript code help

    I have a problem on my jquery with php code.

    Code:
    <?php
    if($_GET["f"]==1){
    echo $_GET["id_number"];
    }
    else{
    ?>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script>
    $(document).ready(function () {
    var isCtrl = false;
    $(document).keyup(function (e) {
     if(e.which == 17) isCtrl=false;
    }).keydown(function (e) {
        if(e.which == 17) isCtrl=true;
        if(e.which == 86 && isCtrl == true) {
            document.getElementById('id_number').focus();
            document.getElementById('Button').click();
     }
    });
    });
    </script>
    
    <script type="text/javascript">
    $(document).ready(function() {
    $("#Button").click(function(){   
        var id_number = document.getElementById('id_number');
        $("#Content").html('<img src="http://tinyurl.com/7al6hv5">').load('1.php?f=1&id_number='+id_number.value+'');
    });
    });
    </script>
    
    <input type="text" onkeydown="this.select();" value="" id="id_number">
    <input type="submit" value="Load" id="Button">
    <div id="Content"></div>
    
    <?php } ?>
    Function: Users must pressed CTRL+V to proceed. Then when user pressed CTRL+V, automatically the text in the clipboard will be in the input fields then i want to automatic submit the form..
    On my code its working but on first it doesnt work, it needs to pressed 2x the CTRL+V.

    PLEASE HELP ME GUYS, im new here Thanks!
    More power!

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,303
    Thanks
    23
    Thanked 612 Times in 611 Posts
    Probably your biggest problem is that you have TWO $(document).ready() functions
    Use this and see what you get:
    Code:
    <script>
    $(document).ready(function () {
    	var isCtrl = false;
    	$(document).keyup(function (e) {
    		if(e.which == 17) isCtrl=false;
    	}).keydown(function (e) {
    		if(e.which == 17) isCtrl=true;
    		if(e.which == 86 && isCtrl == true) {
    		document.getElementById('id_number').focus();
    		document.getElementById('Button').click();
    	 }
    	});
    
    	$("#Button").click(function(){
    	    var id_number = document.getElementById('id_number');
    	    $("#Content").html('<img src="http://tinyurl.com/7al6hv5">').load('ajax.php?f=1&id_number='+id_number.value+'');
    	});
    });
    </script>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,373
    Thanks
    11
    Thanked 592 Times in 572 Posts
    use e.ctrlKey to see if the control key was pressed when e.keyCode==86.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

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