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
    Master Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    5,326
    Thanks
    26
    Thanked 734 Times in 732 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.

    Soon to not be a resident of Missouri - hitting the road for better pastures.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,600
    Thanks
    11
    Thanked 616 Times in 596 Posts
    use e.ctrlKey to see if the control key was pressed when e.keyCode==86.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com


  •  

    Posting Permissions

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