Reputation: 1143
I would like to add an enter key press after the alert(get_approve_2.innerHTML);
as the code below.
This means that every time the alert runs, the enter key press then starts after the alert's popup.
$(get_status1).change(function(){ // Get value of Status 1
//alert($('option:selected', $(this)).text());
var value = $('option:selected', $(this)).text();
var get_approve_2 = document.getElementById("ctl00_m_g_ee431d81_6c29_4b13_a29e_884f483a4e68_ff171_ctl00_ctl00_UserField_upLevelDiv");
if (value == "Approve"){
var name_approve_2 = "Receptionist";
get_approve_2.innerHTML = name_approve_2;
alert(get_approve_2.innerHTML);
// Enter key press goes here
}
else{
//alert("Reject");
get_approve_2.innerHTML = " ";
}
});
I have tried with this but I don't know how it can be run automatically or be trigged
function runScript(e) {
if (e.keyCode == 13) {
var tb = document.getElementById("scriptBox");
eval(tb.value);
return false;
}
}
Upvotes: 0
Views: 455
Reputation: 6887
If you're using jQuery.You can use which event on key code 13 for the enter key
// Enter key press goes here
$('Your selector').on('keyup', function(e) {
if (e.which == 13) {
e.preventDefault();
}
});
As you said if you want to automatically be trigged
function runScript(e) {
if (e.keyCode == 13) {
var tb = document.getElementById("scriptBox");
eval(tb.value);
return false;
}
}
Add your function there
if (value == "Approve"){
var name_approve_2 = "Receptionist";
get_approve_2.innerHTML = name_approve_2;
alert(get_approve_2.innerHTML);
// Enter key press goes here
runScript(13); //run your function there
}
Upvotes: 1