I’m using Cognos and I’m trying to catch the enter key so that the user’s input is checked before the prompt is submitted.
Even if you don’t have experience in cognos, I would appreciate it if you looked at my code 🙂 It’s pretty much a drag and drop program for business reports.
I have a Text Box Prompt on my cognos prompt page and I’m trying to set a 3 char minimum for user input. I have surrounded that Text Box Prompt with a div using HTML Items as shown below.
<div onKeyDown="return keyMon(event)"> Cognos Text Box </div>
I then have another HTML Item that contains the function keyMon(), as shown below:
<script>
function keyMon(e3)
{
var key = e3 || window.event;
if(key.keyCode == 13){
var fW = (typeof getFormWarpRequest == "function" ?
getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined) {
fW = ( formWarpRequest_THIS_ ?
formWarpRequest_THIS_ : formWarpRequest_NS_ );
}
var custValue = fW._textEditBoxCustomerPrompt;
if(custValue.value.length > 0){
if(custValue.value.length >= 3){
promptAction('next'); //Submit the user's input
}else{
alert("Please enter a search value that is 3 or more characters long.");
return false;
}
}
}
}
</script>
As I said above, this works fine with IE. When it runs in Firefox, it picks up the Enter key, the alert box pops up as it should, but only for a millisecond and then disappears. But it still proceeds to the next page. So obviously the "return false;" isn’t doing much.
Any help would be appreciated.
I managed to put a band-aid on it… Instead of returning false, I cleared out the Parameter Text Box, thus making the prompt not submit. Then I fired the alert.
If anyone has the solution to my original question, please feel free to add it because it’s really bugging me.