1
$(function () {
  $('#cmd').bind('keydown', function (evt) {
    if (evt.keyCode === 13) {


//* I want to call the function here *//
    }
    });

});

This is the function i want to call wit the parameter.

$(function (String msg) {

var cmdStr = msg;

    $.ajax({
        url: 'exec.php',
        dataType: 'text',
        data: {
            q: cmdStr
        },
        success: function (response) {
            $('#txtOut').append(response);
        }

    });

}
});

});

2 Answers 2

2
$('#cmd').keydown(
    function (event){
        if(event.keyCode == 13){
        event.preventDefault(); 
        /*you can call your function here*/
        $.ajax({
          url: "exec.php",
          method: "get",
          dataType: "text", 
          data: { q: $('#com').val()},
          success: function(data){ 
             $('#txtOut').append(response);
          }
        });
        /*still you can it here*/
      }
    }
);
Sign up to request clarification or add additional context in comments.

Comments

2

Put the function outside the document ready and give it a name.

function MyFunction(msg)
{
var cmdStr = msg;
$.ajax({
    url: 'exec.php',
    dataType: 'text',
    data: {
        q: cmdStr
    },
    success: function (response) {
        $('#txtOut').append(response);
    }

});

}

then call it from your click event

  $(function () {
  $('#cmd').bind('keydown', function (evt) {
    if (evt.keyCode === 13) {    

       MyFunction("message");
    }
    });

});

Comments

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.