0

I would like to know that how I can change the function in the KeyCode condition? i trying to do something but I cant get inside the keyCode.

my code:

$("body").keydown(function (e) {
    // left arrow
    if ((e.keyCode || e.which) == 37) {
        prevpage('{!! !empty($data["previous"]) ? $data["previous"] : "4" !!}', '0');
    }
    // right arrow
    if ((e.keyCode || e.which) == 39) {
        nextpage('{!! $data["next"] !!}', '2');
    }
});

thanks for all the help!.

UPDATE

this its my code for the functions nextpage and prev

       function nextpage(nextpage,pagenumber) {
        getCotent(nextpage,pagenumber);
        var number = Number(nextpage)+1;
        var numberprev = Number(nextpage)-1;
        var numberpagePluss = Number(pagenumber)+1;
        var numberpageMinus = Number(pagenumber)-1;

        if(number == null || '{!! Request::segment(6) !!}' == '1' && numberpagePluss == '24' || '{!! Request::segment(6) !!}' == '2' && numberpagePluss == '27') {

            $('.next').hide();
            $('#next').hide();

        } else if(numberpagePluss == '10') {

            // $('#menu ul li:lt(5)').fadeOut('slow').hide();
            // $('#menu ul li:gt(23)').fadeIn('slow').show();
            $('#menu ul li.privie').show();
            $('#menu ul li.next').show();

        } else {

            $('.privie').attr('onclick','prevpage('+ numberprev +',' + numberpageMinus + ')');
            $('.next').attr('onclick','nextpage('+ nextpage+1 +',' + numberpagePluss + ')');

            $('#privie').attr('onclick','prevpage('+ numberprev +',' + numberpageMinus + ')');
            $('#next').attr('onclick','nextpage('+ nextpage+1 +',' + numberpagePluss + ')');

            $('.privie').show();
            $('#privie').show();


        }

    }

    function prevpage(previd,pagenumber) {

        getCotent(previd,pagenumber);
        var number = Number(previd)+1;
        var numberprev = Number(previd)-1;
        var numberpagePluss = Number(pagenumber)+1;
        var numberpageMinus = Number(pagenumber)-1;

        if(numberprev == null || numberpageMinus == '0') {

            $('.privie').hide();
            $('#privie').hide();

        } else if(numberpageMinus == '9') {

            // $('#menu ul li:lt(4)').fadeIn('slow').show();
            // $('#menu ul li:gt(23)').fadeOut('slow').hide();
            $('#menu ul li.privie').show();
            $('#menu ul li.next').show();

        } else {

            $('.privie').attr('onclick','prevpage('+ numberprev +')');
            $('.next').attr('onclick','nextpage('+ number +')');

            $('#privie').attr('onclick','prevpage('+ numberprev +')');
            $('#next').attr('onclick','nextpage('+ previd+1 +')');

            $('.next').show();
            $('#next').show();

        }

what i need its after i press left key the page its over to the next and i need the function in the keyCode will change to the next page.

2
  • it's working fine........ Commented Mar 15, 2016 at 10:27
  • yes sure the keyCode working good. but i need to change the functions parameters inside the keyCodes Commented Mar 15, 2016 at 10:57

2 Answers 2

1

Try this:

$("document").ready(function(){
  $("body").keydown(function(e){
    // left arrow
    if ((e.keyCode || e.which) == 37)
    {   
        console.log("condition 1");
        myfun1();
    }
    // right arrow
    if ((e.keyCode || e.which) == 39)
    {
        console.log("condition 2");
        myfun2();
    }   
  });
})

function myfun1(){
     alert("inside myfun1");
 //write your code of execution here
 }

function myfun2(){
     alert("inside myfun2");
 //write your code of execution here
 }

If it works then the keycode is running fine

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

4 Comments

i need to change adter i press the keyCode the function parameters, the keyCode working fine
If this worked fine then you can better call functions after entering the condition and execute from there and carry on.
i see but how i can do after every klick the parameters in the function will change? i need the parameters will be changes for the nextpage every klick
You can use javascript polymorphism if you want. After every click you can send the current parameters to the function to execute. It is really unclear what you want to achieve but as the question that you have asked, the answer is complete enough, if I know what is it that you exactly want to achieve then I can help you properly and provide you with a complete answer for your particular situation.
0

try this one

var test=function(){
    //your code
    }

    var test2=function(){
    //your code
    }

    $("document").ready(function(){
      $("body").keydown(function(e){

        if ((e.keyCode || e.which) == 37)
        {   
           test();
        }

        if ((e.keyCode || e.which) == 39)
        {
            test2();
        }   
      });
    })

1 Comment

i need to change the functions parameters inside the keyCodes. for the nextpage

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.