If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Javascript - Simple Text Box Prompt Validation

Started by dmburke11, 25 Sep 2013 11:37:18 AM

Previous topic - Next topic

dmburke11

Hi - relatively new to Cognos - appreciate all the help I've gotten so far!  :)

I've written the following javascript in an HTML Item immediately to the right of the Text Box Prompt (Name = TxtNum) and want it to execute whenever the user leaves (onblur ??) the text box. It simply needs to remove any hyphens from the value.

<script>

var fW= getFormWarpRequest();

var str = fW._textEditBoxTxtNum.value;

          if (!(str == null || str =="")) {

               str = str.replace("-", "");  // remove all hyphens
         }
     

</script>


It doesnt' seem to execute. I don't know how to tie the script to an event. I've tried variations that use object.onblur = function.... but no luck.

It also seems like the script executes on launch and that's it (I've tested with alerts and they run only at launch.) What am I doing wrong?   :'(

Thank you!

adik

your str variable is a html item most probably generated as <input type="text" ...> ... </input>
what you actually want to check there is the text within the <input.. >... </input> tags
so you will need to access the text node of the element
to do so you will use in your if: !(str.text == null || str.text =="")
i had some issues accessing the text node in IE8 this way, so you can also do: !(str.innerHTML == null || str.innerHTML =="")
and by the way, unless null is a variable that you declared and passed some values to it, than comparing text with null won't work, as HTML does not know of null as databases do. In this case just stick with ... == ""

dmburke11

Thanks Adik. I'll give that a shot - appreciate the response.

I did figure out a better way to do the 'replace all' (for those, like me, who didn't already know.)

            var str = fW._textEditBoxtxtValuePromptName.value;
            var newStr = str.replace(/-/g,"");