Problems w javascript function return true/false

Hi all,
I have a javascript function that return true or false.
It's called by a link in a report (URL-target):
javascript:return showForr(&APP_ID.,&SESSION.,#PERSON_ID#,'#STARTDATUM#','#SLUTDATUM#');
With the return it does NOT work. If I remove return it works with no problem but then I can't "end" the function where I want.
Any pointers how I can achive what I want here?
BR Daniel

The solution is the to put a span around and make the on-click there:<br><br>
select 'Daniel' namn, <br>'>span onclick="return test();"><br>>a href="javascript:test2();"><br>Calling func return true/false<br>>/a><br>>/span>'  id3
from dualSee http://apex.oracle.com/pls/otn/f?p=22968:5:1350065385503137::::: for details.
/D

Similar Messages

  • Problem using javascript function?

    Hallo,
    i integrate a file for javascript functions with this code
    <afh:head title="#{res['pob.login']}">
    <meta http-equiv="Content-Type"
    content="text/html; charset=ISO-8859-15"/>
    <script type="text/javascript" src="../Javascript/Funktionen.js"></script>
    </afh:head>
    in the file Funktionen.js i have the following functions
    function deleteWarning()
    return confirm("Wollen Sie den ausgew" + String.fromCharCode(228) + "hlten Datensatz wirklich l" + String.fromCharCode(246) + "schen ?");
    function testFall()
    return confirm("Wollen Sie den ausgew" + String.fromCharCode(228) + "hlten Datensatz wirklich l" + String.fromCharCode(246) + "schen ?");
    the first function i can use, the second not. Why?

    Thank you for checking the code Frank. So i can look what is the problem.
    The reason is i/we using firefox and changes in the javascript definition only checked when the cache has been cleared!

  • Functions returning TRUE or FALSE

    Morning chaps,
    Wrote a function that converts a date in the format "01 Jan 2010" to a Unix timestamp. It also returns FALSE if it cannot convert the date it is being passed, which is great because I can use:
    <cfif convertDateToUTS(FORM.date)>
         <cfset #date# = #convertDateToUTS(FORM.date)# />
         <p>Your date: <cfoutput>#date#</cfoutput></p>
    <cfelse>
         <p>Could not convert date.</p>
    </cfif>
    Here is the function:
    <cffunction name="convertDateToUTS" output="no">
        <cfargument name="date" required="Yes" />
        <cfargument name="time" default="00:00"/>
    <cftry>
        <cfset #date# = trim(left(trim(date), 11)) />
        <cfset #time# = trim(left(trim(time), 5)) />
        <cfset #dateArr# = #listToArray(date, " ")# />
        <cfset #dateArr[2]# = #replace(dateArr[2], "Jan", 1)# />
        <cfset #dateArr[2]# = #replace(dateArr[2], "Feb", 2)# />
        ...etc...
        <cfset #dateArr[2]# = #replace(dateArr[2], "Dec", 12)# />
        <cfset #dateTime# = ArrayToList(dateArr, " ")&" "&time />
        <cfset #dateTimeBits# = listToArray(dateTime, " :") />
        <cfset #ODBCdateTime# = CreateODBCDateTime(CreateDateTime(dateTimeBits[3], dateTimeBits[2], dateTimeBits[1], dateTimeBits[4], dateTimeBits[5], 0)) />
        <cfset #unixDateTime# = #DateDiff("s", CreateDate(1970,1,1), ODBCdateTime)# />
        <cfreturn #unixDateTime# />
    <cfcatch>
        <cfreturn FALSE />
    </cfcatch>
    </cftry>
    </cffunction>
    However, now I want to write a similar one which converts a timestamp to a date in that format:
    <cffunction name="convertUTStoDate" output="no">
         <cfargument name="uts" required="Yes" />
    <cftry>
         <cfset #date# = #DateFormat(DateAdd("s",uts,"1970/01/01 00:00:00"),"DD MMM YYYY")# />
         <cfset #time# = #TimeFormat(DateAdd("s",uts,"1970/01/01 00:00:00"), "HH:mm")# />
         <cfreturn #date#&" "&#time# />
    <cfcatch>
         <cfreturn FALSE />
    </cfcatch>
    </cftry>
    </cffunction>
    This does the conversion correctly but it it won't let me use it as the condition in a CFIF like the first function does eg <cfif convertUTStoDate(uts)> but, it does work exactly as I want if I do this: <cfif convertUTStoDate(uts) NEQ FALSE>
    What am I doing wrong? I really want it to behave like the first function when used in a condition. Massive thanks to anyone who can help!
    T

    What dou you think of the following version of your code? It is the same as your original code but, in my opinion, a bit simpler.  For example, your test now becomes something like
    <!--- remember returntype is now a struct --->
    <cfif convertDateToUTS(FORM.date).isConverted>
         <cfset date = convertDateToUTS(FORM.date).unixDateTime/>
         <p>Your date: <cfoutput>#date#</cfoutput></p>
    <cfelse>
         <p>Could not convert date.</p>
          Reason: <cfoutput>#convertDateToUTS(FORM.date).message#</cfoutput>
    </cfif>
    <cffunction name="convertDateToUTS" output="no" returntype="struct">
        <cfargument name="date" required="Yes" />
        <cfargument name="time" default="00:00"/>
        <cfset var returnStruct = structNew()>
        <cfset returnStruct.datetime = "">
        <cfset returnStruct.isConverted= false>
    <cftry>
        <cfset date = trim(left(trim(date), 11)) />
        <cfset time = trim(left(trim(time), 5)) />
        <cfset dateArr = listToArray(date, " ") />
        <cfset dateArr[2] = replace(dateArr[2], "Jan", 1) />
        <cfset dateArr[2] = replace(dateArr[2], "Feb", 2) />
        ...etc...
        <cfset dateArr[2] = replace(dateArr[2], "Dec", 12) />
        <cfset dateTime = ArrayToList(dateArr, " ")&" "&time />
        <cfset dateTimeBits = listToArray(dateTime, " :") />
        <cfset ODBCdateTime = CreateODBCDateTime(CreateDateTime(dateTimeBits[3], dateTimeBits[2], dateTimeBits[1], dateTimeBits[4], dateTimeBits[5], 0)) />
        <cfset returnStruct.unixDateTime = DateDiff("s", CreateDate(1970,1,1), ODBCdateTime) />
        <cfset returnStruct.message = "Conversion succeeded.">
        <cfset returnStruct.isConverted= true>
        <cfreturn  returnStruct>
    <cfcatch>
        <cfset returnStruct.message = cfcatch.message>
        <cfreturn  returnStruct>
    </cfcatch>
    </cftry>
    </cffunction>
    <cffunction name="convertUTStoDate" output="no" returntype="struct">
         <cfargument name="uts" required="Yes" />
         <cfset var returnStruct = structNew()>
         <cfset returnStruct.datetime = "">
         <cfset returnStruct.isConverted= false>
    <cftry>
         <cfset date = DateFormat(DateAdd("s",uts,"1970/01/01 00:00:00"),"DD MMM YYYY") />
         <cfset time = TimeFormat(DateAdd("s",uts,"1970/01/01 00:00:00"), "HH:mm") />
         <cfset returnStruct.datetime = date&" "&time />
         <cfset returnStruct.message = "Conversion succeeded.">
         <cfset returnStruct.isConverted= true>
         <cfreturn  returnStruct>
    <cfcatch>
          <cfset returnStruct.message = cfcatch.message>
          <cfreturn  returnStruct>
    </cfcatch>
    </cftry>
    </cffunction>

  • Help. Strange problem with a function returning VARCHAR2

    Hi.
    i have a function that returns VARCHAR2, the following happens:
    IS
    v_retorno VARCHAR2(1000);
    v_stm2 VARCHAR2(500);
    v_stm1 VARCHAR2(500);
    BEGIN
    v_retorno :='INSERT INTO '||p_nome_tabela||'('||v_stm1||') VALUES('||v_stm2||')';
    -- it raises an exception OTHERS here
    v_stm1 has the value :
    PERFIL,TIPDOC,GRPIMP,DES,IMPDES,GRPAGI,TOTAGI,TOTPOSRVP,TOTNEGRVP,TOTALIZA,TEMMSG,ORDEM,CODFORCAB,SINAL,ORDEM,CODEMP,USER_CRI,DT_CRI
    v_stm2 has the value:
    'BASE','03','999999','teste','N','0701','N','111111','222222','S','N',TO_NUMBER('111'),'X',TO_NUMBER('1'),TO_NUMBER('222'),TO_NUMBER('10'),'427195',TO_DATE('19-05-2008 04:32:49','DD-MM-YYYY HH:MI:SS')
    p_nome_tabela is a table name, for example my_table.
    This is to produce a varchar2 string to execute dynamic sql.
    Can you help? I don't understand what's wrong.
    If i do this :
    v_retorno :='INSERT INTO '||p_nome_tabela||'('||v_stm1||') VALUES(';
    it works, doesn't raise the OTHERS exception, but if i had the other variable, the OTHER is raised.

    No idea if this is relevant here or not, but:
    v_retorno VARCHAR2(1000);
    v_stm2 VARCHAR2(500);
    v_stm1 VARCHAR2(500);What happens if your v_stm1 and v_stm2 variables are both 500 characters long?
    I think you should think about increasing the length of v_retorno...

  • SQL Query problem (PL/SQL function returning SQl query)

    I am using 3.1.2 Apex. When I create the region source with the following code.
    DECLARE
    l_sql VARCHAR2(32767);
    X1 VARCHAR2(9);
    X2 VARCHAR2(9);
    X3 VARCHAR2(9);
    X4 VARCHAR2(9);
    X5 VARCHAR2(9);
    X6 VARCHAR2(9);
    X7 VARCHAR2(9);
    X8 VARCHAR2(9);
    BEGIN
    SELECT decode(:P3_FAILED_CDD,'0','0','1','1', '2','2' ) INTO X2
    FROM DUAL;
    SELECT decode(:P3_Order_status,'J','J','1','1','2') INTO X3
    FROM DUAL;
    SELECT decode(:P3_FAILED_STAGE,'0','0','1','1','2') INTO X4
    FROM DUAL;
    SELECT decode(:P3_ORDER_TYPE,'TYPE1','TYPE1','TYPE2','TYPE2','2') INTO X5
    FROM DUAL;
    SELECT decode(:P3_INCLUDE_SFIN,'NO','NO','YES','YES') INTO X6
    FROM DUAL;
    SELECT decode(:P3_CDD_MATCH,'0','0','1','1', '2','2' ) INTO X7
    FROM DUAL;
    SELECT decode(:P3_FIELD,'0','0','1','1', '2','2' ) INTO X8
    FROM DUAL;
    l_sql := 'SELECT
    ORDER_NR,
    FNN,
    ST,
    SOT,
    STAGE,
    CUST_NAME,
    STG_DAYS,
    ZONE,
    P1.OWNER,
    QUEUE_A,
    STG_LFD,
    LFD_LEFT,
    CIJ_FLAG,
    FST_FLAG,
    CCD_COUNT,
    TCD_COUNT,
    LATEST_RET_CODE,
    CRD,
    CDD_DATE,
    CRD_LEFT CDD_LEFT,
    TCD_DATE RTCD_DATE,
    PROP_TCD_DATE TCD_DATE,
    PROJECT_ID,
    APPLN_TBO,
    CO_ORD_ID,
    CON_WSTN,
    P1.STATE,
    A_DTB,
    B_DTB,
    DESIGN_NO,
    CREATE_DATE,
    DATE_APPLN,
    CUSTOMER_ID,
    SALES_QUEUE,
    TRACKING_NR,
    WORK_REQUIRED,
    SFIN_STAGE_ENTERED_DATE,
    APPLN_CONTACT_OFFICER,
    A_LOCATION_ADDRESS,
    B_LOCATION_ADDRESS,
    SO_CREATE_USERID,
    OP_SEP,
    WMC_CODE
    FROM RASS_TICKET_VIEW P1
    WHERE WMC_CODE like :p3_wmc_code
    AND ST in (SELECT SYSTEM_ID from PRDRF where PRODUCT_CATEGORY like :p3_product_cat)';
    IF X2 = '0' then
    l_sql := l_sql || ' and CRD_LEFT < 0';
    END IF;
    IF X2 = '1' then
    l_sql := l_sql || ' and CRD_LEFT >= 0';
    END IF;
    IF X3 = 'J' then
    l_sql := l_sql || ' and CIJ_FLAG = ''J''';
    END IF;
    IF X3 = '1' then
    l_sql := l_sql || ' and CIJ_FLAG is null';
    END IF;
    IF X4 = '0' then
    l_sql := l_sql || ' and LFD_LEFT < 0';
    END IF;
    IF X4 = '1' then
    l_sql := l_sql || ' and LFD_LEFT >= 0';
    END IF;
    IF X5 = 'TYPE1' then
    l_sql := l_sql || ' and SOT in (''NEW'',''NET'',''ERT'',''UGP'')';
    END IF;
    IF X5 = 'TYPE2' then
    l_sql := l_sql || ' and SOT not in (''NEW'',''NET'',''ERT'',''UGP'')';
    END IF;
    IF X6 = 'NO' then
    l_sql := l_sql || ' and STAGE in (''DSAL'',''DPLO'',''OISS'',''TRPB'',''OTST'',''TEQP'',''DSPS'')';
    END IF;
    IF X7 = '0' then
    l_sql := l_sql || ' and PROP_TCD_DATE <= CDD_DATE';
    END IF;
    IF     X7 = '1' then
    l_sql := l_sql || ' and PROP_TCD_DATE > CDD_DATE';
    END IF;
    RETURN l_sql;
    END;
    The query returns data.
    If I add some more code just after the where clause.
    AND decode(CUST_CODE,'TW','TW','RET') like (select decode(OPS_SEP,'TS','%',OPS_SEP) from T_U_CDW_BU_OP_SEP where upper(USER_ID) = upper(:APP_USER))
    The query just stops working and no error message is returned.
    I thought there was an issue prior to version 3.1.2 that was fixed in version 3.1.2
    Othwerwise is there a better way to write the code? As I have 7 radio btn's that control the condition within the where clause.
    Thanks
    Ron

    >
    bug in APEX 3.0
    >
    Are you sure?
    Do as Paul has suggested and post the code that doesn't work (including your extra line) using the {noformat}{noformat} tags +exactly+ as you had it in the region source.
    Cheers
    Ben                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • CP6 - True/False Question Type SCORM Problem

    We discovered a problem with CP6 and the True/False question type.  The screen shot below is the log file of what is passed to the LMS.  The question was a True/False question type.  The correct answer was False.  I selected False and the assessment showed that I got the answer correct.  However, the data that is being passed to the LMS is incorrect.  CP6 is sending a 't' when you select False and an 'f' when you select True.
    Yes, you can get around this by using a Multiple Choice question type and limit the answers to 2 with True and False as the options, but we should not have to do that.
    Any suggestions?

    There is a long discussion on Jim Leichliter's blog (captivatedev) about this. The team considered this to be correct, Jim disagrees.
    http://captivatedev.com/2012/12/04/captivate-true-false-question-bug/
    Cannot help you further,
    Lilybiri

  • Creating an expression to return a yes/no or True/False statement in Ms SQL Server Report Builder

    I am attempting to create a field that returns a True/False value instead of a numeric value. I have a field with the expression =Fields!CreditLimit.Value*.95 this returns a value that is equal to 95% of the value in my Balance field. The issue is I
    don't remember how to turn =IIF (Fields!CreditLimit.Value > *.95, true, false) into an expression that compares the 2 fields and then returns True/False. Can you please help me out?
    Thanks,
    -John

    Hi,
    Try below one:
    =IIF (Fields!CreditLimit.Value *.95>95, true, false) 
    Here you have to define a limit. For Example; When output of Fields!CreditLimit.Value
    *.95 is greater than 95 then True else False. So specify the value according to your requirement. 
    Thanks Shiven:) If Answer is Helpful, Please Vote

  • Problem with onBlur=validate_int_range javascript function

    Hi i have a java script function which is use to check for the range of the integer i enter.
    The function works fine but the problem is once i click ok on the validation boxes that come up when i enter a wrong value it allows me to click the submit box.But if i click back on the text box then the validation box appears again.
    The report code is
    to_clob(HTMLDB_ITEM.text(5, pref_val,15,30,'onBlur="validate_int_range('||pref_name||','''||pref_expr||''');"style="width: 220px;"',pref_name)),
    and the javascript function is
    <script language="JavaScript1.1" type="text/javascript">
    function validate_int_range(pref_name, range) {
    var pos = range.indexOf('-');
    var start_val, end_val;
    var actual_val = pref_name.value;
    var non_digits = /\D/;
    if ( non_digits.test(actual_val) ) {
    alert('Validation Fail: only digits allowed. ' + range);
    if ( pos > 0 ) {
    start_val = range.substr(0,pos);
    end_val = range.substr(pos+1, range.length-pos+1);
    if ( eval(actual_val) < eval(start_val) ) {
    alert('Validation Fail: smaller value than ' + start_val );
    if ( eval(actual_val) > eval(end_val) ) {
    alert('Validation Fail: larger value than ' + end_val);
    function validate_rule(pref_name, exp) {       
    var actual_val = pref_name.value;
    expression = new RegExp(exp);
    if ( ! expression.test(actual_val) ) {
    alert('Validation Fail: Rule ' + exp);
    </script>

    >thanks you so much for the code, I'll test it out and
    reply with >the
    >results.
    Shouldn't that be "Thanks so much for the Cod"?
    "Dave Bar" <[email protected]> wrote in message
    news:e28c7t$hk1$[email protected]..
    > ahh yes, you are right..
    > I should have said OR instead of AND.
    > If Field is blank OR range is not between 1900 &
    2006. Thanks for catching
    > and pointing that out.
    >
    > thanks you so much for the code, I'll test it out and
    reply with the
    > results.
    > Thanks
    > -Dave
    >
    >
    >
    >
    > "Lionstone" <[email protected]> wrote
    in message
    > news:e28b1a$fu5$[email protected]..
    >> That's probably because you asked for a fish to help
    you out
    >>
    >>> Can some kind sole help with a modified version
    to also check for an
    >>> entered
    >>> number range?
    >>
    >> and fish can't type.
    >>
    >> You're off on the logic though, since something is
    not likely to be both
    >> blank and outside a certain number range. If it's
    blank or outside the
    >> range, either condition is sufficient for an error,
    right?
    >> You also want to make sure that no letters, etc, are
    entered, because
    >> that will mess up your comparisons to the other
    numbers. Keeping in mind
    >> that javascript validation can be defeated by
    sneezing and you'll need to
    >> re-validate on the server, this will be closer to
    right (not tested).
    >>
    >> var ThisYear = ThisForm_Right.DOB_Year.value;
    >> ThisYear = ThisYear.replace(/[^/d]/g,"");
    >> if(ThisYear.length == 0)
    >> {
    >> alert("Please enter the year of your DOB.");
    >> ThisForm_Right.DOB_Year.focus();
    >> return false;
    >> }
    >> else
    >> {
    >> ThisYear = parseInt(ThisYear);
    >> if((ThisYear < 1900) || (ThisYear > 2006))
    >> {
    >> alert ("The year of your DOB must be between 1900
    and 2006.");
    >> ThisForm_Right.DOB_Year.focus();
    >> return false;
    >> }
    >> }
    >>
    >>
    >
    >

  • Problem when calling more than 1 Javascript function

    Hello everybody,
    I am trying to disable fields based on the value in a Select List. There is a table in which values are stored to tell if a field should be disabled for the selected value. I have created an Application Process and a JavaScript function for each field.
    The problem is that only the first function is executed, and the second not.
    I have tried the following:
    onchange="Disable_Dagen(this);Disable_Kg(pThis);"and I have put them together in a parent JavaScript function
    function Disable_Fields(pThis){
    Disable_Kg(pThis);
    Disable_Dagen(pThis);
    }In either case only the first works, so when I change the order then the other one is executed properly.
    Can anyone give me a clue on how to solve this?
    My complete JavaScript definition in the header is as follows:
    (the code in html_DisableOnValue is taken from the example site from Carl Beckstrom)
    <script language="JavaScript" type="text/javascript">
    <!--
    function html_DisableOnValue(pThis,pValue,pThat){
         var lTest;
      if(pThis.nodeName == 'SELECT'){
                   lTest = html_SelectValue(pThis) == pValue;
         }else{
                   lTest = $x(pThis).value == pValue;
         if(pThat){
               for (var i=2;i <= arguments.length; i++){
                          html_disableItem(arguments,lTest)
         return;
    function Disable_Dagen(pThis){
    var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=AP_RETURN_DISABLE_VAL_DGN',0);
    get.add('AI_AFW_CODE',pThis.value);
    gReturn = get.get();
    get = null;
    //alert('Return waarde is '+ gReturn );
    html_DisableOnValue(pThis,gReturn,'P43_AANTAL_DAGEN');
    function Disable_Kg(pThis){
    var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=AP_RETURN_DISABLE_VAL_KG',0);
    get.add('AI_AFW_CODE',pThis.value);
    gReturn = get.get();
    get = null;
    //alert('Return waarde is '+ gReturn );
    html_DisableOnValue(pThis,gReturn,'P43_AANTAL_KG');
    function Disable_Fields(pThis){
    Disable_Kg(pThis);
    Disable_Dagen(pThis);
    //-->
    </script>
    In this case the Form Element property is set toonchange="Disable_Fields(this)"
    Thanks, Wouter                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi Roel,
    Thanks again for your response.
    There is a lot more to Firebug then I had seen before. Now I have turned on the Console and the Script. Initially I saw the following in the Console:
    C is undefined
    $x_disableItem(undefined, true)apex_3_1.js (regel 1)
    html_DisableOnValue(select#P43_AFWIJKING_CODE, "101", "P43_AANTAL_DAGEN")f?p=104:...2606::::: (regel 38)
    Disable_Dagen(select#P43_AFWIJKING_CODE)f?p=104:...2606::::: (regel 51)
    onchange(change )f?p=104:...FPQ%3D%3D (regel 2)
    [Break on this error] var gDebug=true;var gkeyPressTime;var gL...Options;html_SelectValue=$f_SelectValue;When I removed the comments before the 2 Alerts, I only got one alert when I tested it.
    Then I replaced the function call to html_DisableOnValue to $f_DisableOnValue as you suggested, and that did the trick. Now it Works!
    I still don't know why the html_DisableOnValue function doesn't work. I just copied it from the demo site of Carl Beckstrom. Anyway my problem is solved.
    Have a nice weekend, Wouter

  • Problem with return true and if statement

    I'm making a
    ship shooter
    game and I have a problem with the collision detection for the
    corners of the stage. When you hold down two of the arrows to move
    the ship into the corners of the screen, the ship will go past it.
    The function bellow is what I'm using to detect this collision. The
    reason I'm using a function is because it's used for the ship and
    for all the balls from the cannons (as shown in the last two lines
    of the attached code). This is the reason I need the return true,
    so the if statement can be evaluated to true and then unload the
    movieclip of the cannon ball. When I remove the return true, the
    collision works fine, but obviously my cannon balls all get stuck
    on the edges.
    Any ideas?

    Well the function is called every frame, for the ship and for
    every cannon ball that's on the screen. So it could be called about
    4 times or so per frame. The problem is that ship goes through the
    corners of the stage (btw, the green background is the stage area)
    when you go in a diagonal direction.
    Just curious...what's the unnecessary code you're talking
    about?

  • Regex: how can Matcher.matches return true, but Matcher.find return false?

    Consider the class below:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class RegexBugDemo {
         private static final Pattern numberPattern;
         static {
                   // The BigDecimal grammar below was adapted from the BigDecimal(String) constructor.
                   // See also p. 46 of http://www.javaregex.com/RegexRecipesV1.pdf for a regex that matches Java floating point literals; uses similar techniques as below.
              String Sign = "[+-]";
              String Sign_opt = "(?:" + Sign + ")" + "?";     // Note: the "(?:" causes this to be a non-capturing group
              String Digits = "\\p{Digit}+";
              String IntegerPart = Digits;
              String FractionPart = Digits;
              String FractionPart_opt = "(?:" + FractionPart + ")" + "?";
              String Significand = "(?:" + IntegerPart + "\\." + FractionPart_opt + ")|(?:" + "\\." + FractionPart + ")|(?:" + IntegerPart + ")";
              String ExponentIndicator = "[eE]";
              String SignedInteger = Sign_opt + Digits;
              String Exponent = ExponentIndicator + SignedInteger;
              String Exponent_opt = "(?:" +Exponent + ")" + "?";
              numberPattern = Pattern.compile(Sign_opt + Significand + Exponent_opt);
    //     private static final Pattern numberPattern = Pattern.compile("\\p{Digit}+");
         public static void main(String[] args) throws Exception {
              String s = "0";
    //          String s = "01";
              Matcher m1 = numberPattern.matcher(s);
              System.out.println("m1.matches() = " + m1.matches());
              Matcher m2 = numberPattern.matcher(s);
              if (m2.find()) {
                   int i0 = m2.start();
                   int i1 = m2.end();
                   System.out.println("m2 found this substring: \"" + s.substring(i0, i1) + "\"");
              else {
                   System.out.println("m2 NOT find");
              System.exit(0);
    }Look at the main method: it constructs Matchers from numberPattern for the String "0" (a single zero). It then reports whether or not Matcher.matches works as well as Matcher.find works. When I ran this code on my box just now, I get:
    m1.matches() = true
    m2 NOT findHow the heck can matches work and find NOT work? matches has to match the entire input sequence, whereas find can back off if need be! I am really pulling my hair out over this one--is it a bug with the JDK regex engine? Did not seem to turn up anything in the bug database...
    There are at least 2 things that you can do to get Matcher.find to work.
    First, you can change s to more than 1 digit, for example, using the (originaly commented out) line
              String s = "01";yields
    m1.matches() = true
    m2 found this substring: "01"Second, I found that this simpler regex for numberPattern
         private static final Pattern numberPattern = Pattern.compile("\\p{Digit}+");yields
    m1.matches() = true
    m2 found this substring: "0"So, the problem seems to be triggered by a short source String and a complicated regex. But I need the complicated regex for my actual application, and cannot see why it is a problem.
    Here is a version of main which has a lot more diagnostic printouts:
         public static void main(String[] args) throws Exception {
              String s = "0";
              Matcher m1 = numberPattern.matcher(s);
              System.out.println("m1.regionStart() = " + m1.regionStart());
              System.out.println("m1.regionEnd() = " + m1.regionEnd());
              System.out.println("m1.matches() = " + m1.matches());
              System.out.println("m1.hitEnd() = " + m1.hitEnd());
              m1.reset();
              System.out.println("m1.regionStart() = " + m1.regionStart());
              System.out.println("m1.regionEnd() = " + m1.regionEnd());
              System.out.println("m1.lookingAt() = " + m1.lookingAt());
              System.out.println("m1.hitEnd() = " + m1.hitEnd());
              Matcher m2 = numberPattern.matcher(s);
              System.out.println("m2.regionStart() = " + m2.regionStart());
              System.out.println("m2.regionEnd() = " + m2.regionEnd());
              if (m2.find()) {
                   int i0 = m2.start();
                   int i1 = m2.end();
                   System.out.println("m2 found this substring: \"" + s.substring(i0, i1) + "\"");
              else {
                   System.out.println("m2 NOT find");
                   System.out.println("m2.hitEnd() = " + m2.hitEnd());
              System.out.println("m2.regionStart() = " + m2.regionStart());
              System.out.println("m2.regionEnd() = " + m2.regionEnd());
              System.out.println("m1 == m2: " + (m1 == m2));
              System.out.println("m1.equals(m2): " + m1.equals(m2));
              System.exit(0);
         }Unfortunately, the output gave me no insights into what is wrong.
    I looked at the source code of Matcher. find ends up calling
    boolean search(int from)and it executes with NOANCHOR. In contrast, matches ends up calling
    boolean match(int from, int anchor)and executes almost the exact same code but with ENDANCHOR. Unfortunately, this too makes sense to me, and gives me no insight into solving my problem.

    bbatman wrote:
    I -think- that my originally posted regex is correct, albeit possibly a bit verbose, No, there's a (small) mistake. The optional sign is always part of the first OR-ed part (A) and the exponent is always part of the last part (C). Let me explain.
    This is your regex:
    (?:[+-])?(?:\p{Digit}+\.(?:\p{Digit}+)?)|(?:\.\p{Digit}+)|(?:\p{Digit}+)(?:[eE](?:[+-])?\p{Digit}+)?which can be read as:
    (?:[+-])?(?:\p{Digit}+\.(?:\p{Digit}+)?)        # A
    |                                               # or
    (?:\.\p{Digit}+)                                # B
    |                                               # or
    (?:\p{Digit}+)(?:[eE](?:[+-])?\p{Digit}+)?      # COnly one of A, B or C is matched of course. So B can never have a exponent or sign (and A cannot have an exponent and C cannot have a sign).
    What you probably meant is this:
    (?:[+-])?                                   # sign       
        (?:\p{Digit}+\.(?:\p{Digit}+)?)         #   A
        |                                       #   or
        (?:\.\p{Digit}+)                        #   B
        |                                       #   or
        (?:\p{Digit}+)                          #   C
    (?:[eE](?:[+-])?\p{Digit}+)?                # exponent
    and that this must be a sun regex engine bug, but would love to be educated otherwise. Yes, it looks like a bug to me too.
    A simplified version of this behavior (in case you want to file a bug report) would look like this:
    When `test` is a single digit, m.find() returns _false_ but matches() returns true.
    When `test` is two or more digits, both return true, as expected.
    public class Test {
        public static void main(String[] args) {
            String test = "0";
            String regex = "(?:[+-])?(?:\\p{Digit}+\\.(?:\\p{Digit}+)?)|(?:\\.\\p{Digit}+)|(?:\\p{Digit}+)(?:[eE](?:[+-])?\\p{Digit}+)?";
            java.util.regex.Matcher m = java.util.regex.Pattern.compile(regex).matcher(test);
            System.out.println("matches() -> "+test.matches(regex));
            if(m.find()) {
                System.out.println("find()    -> true");
            } else {
                System.out.println("find()    -> false");
    }

  • How can I send an email when a function returns false?

    Im trying to make this code work, but i still receive an email when the function is equal to false. Can anyone assist me in finding the issue? What the program does is look for servers that has a set limit (in GB) on specific drives.
    #This Program goes through all the servers and informs any level below the limit
    $ErrorActionPreference = "SilentlyContinue";
    $scriptpath = $MyInvocation.MyCommand.Definition
    $dir = Split-Path $scriptpath
    #=================Function============
    Function isLow($server, $drive, $limit)
    $disk = Get-WmiObject -ComputerName $server -Class Win32_LogicalDisk -Filter "DriveType = 3 and DeviceID = '$drive'";
    [float]$size = $disk.Capacity;
    [float]$freespace = $disk.FreeSpace;
    $sizeGB = [Math]::Round($size / 1073741824, 2);
    $freeSpaceGB = [Math]::Round($freespace / 1073741824, 2);
    if($freeSpaceGB -lt $limit){
    return $true;
    else{
    return $false;
    #================Servers==============
    #------------------###server1--------------
    $server = "###server1";
    $drive = "C:";
    $lim = 25;
    if(isLow $server $drive $lim)
    $Alert += $server + " || " + $drive + " is low<br>"
    $server = "###server1";
    $drive = "D:";
    $lim = 35;
    if(isLow $server $drive $lim)
    $Alert += $server + " || " + $drive + " is low<br>"
    #-----------------###(more servers ect.)--------------
    #================EMAIL===============
    $smtpServer = "192.168.x.x"
    $ReportSender = "[email protected]"
    $users = "[email protected]"
    $MailSubject = "ALERT!!! Low DiskSpace"
    foreach($user in $users){
    if($true){
    Write-Host "Sending Email notification to $user"
    $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
    $msg = New-Object Net.Mail.MailMessage
    $msg.To.Add($user)
    $msg.From = $ReportSender
    $msg.Subject = $MailSubject
    $msg.IsBodyHTML = $True
    $msg.Body = $Alert
    $smtp.Send($msg)
    else($false){
    Write-Host "No one is pass the limit"

    Using a CSV is good.  Just load the "$servers" hash array from a CSV and the rest will work the same. The overall structure would work better if it was more like this.
    Function isLow($server, $drive, $limit){
    $disk = Get-WmiObject -ComputerName $server -Class Win32_LogicalDisk -Filter "DriveType = 3 and DeviceID = '$drive'"
    if($disk.FreeSSpace -lt $limit){
    $true
    }else{
    $false
    $servers=@()
    $servers=@{
    Server="###server1"
    Drive='C:'
    Limit=25Gb
    $servers=@{
    Server="###server2"
    Drive='D:'
    Limit=15Gb
    $servers=@{
    Server="###server3"
    Drive='C:'
    Limit=50Gb
    $results=foreach($servers in $servers){
    if(isLow $server.Server $server.Drive $server.Limit){
    '{0} || {1} is low<br>' -f $servers.Server,$server.Drive
    if($results){
    Write-Host 'Sending Email notification' -fore green
    $mailprops=@{
    SmtpServer='192.168.x.x'
    From='[email protected]'
    To=$users
    Subject='ALERT!!! Low DiskSpace'
    Body=$results
    BodyAsHtml=$true
    Send-MailMessage @mailprops
    }else{
    Write-Host 'No one is past the limit' -ForegroundColor green
    The biggest issue is to realize that this is a computer.  If you type the same thing more than once then consider that the computer can do it for you.  Once you learn to think like a computer all of this becomes easier.
    ¯\_(ツ)_/¯

  • Javascript open() function returns undefined

    The javascript function open() specs like "fullscreen", "width", "height", seem not to work under Safari while they do under Firefox, Opera and even Explorer. So, I open a popup with : Win=open("<url>","","") and then , I use Win.resizeTo(<width>,<height>) where <width> and <height> was evaluated previously . But I obtain the message : "TypeError : 'undefined' is not an object (evaluating Win.resizeTo)".
    I found several problems with Safari (performance different from other browsers), and up to now, I managed to get round the problem. But in this case, I go blank !!!
    Please, can you help me to produce a code visible by Safarists ;o)

    Beaver13 wrote:
    Thank you "etresoft". In fact, I wrote the inappropriate term function, but as I detailed above, I used correctly resizeTo as a method of "what should be a window object". Syntax of the evaluation of this object by open is also correct since the root object window is implicit. Anyway, I tried adding window or this and I obtained the same behavior.
    In theory that is true, but it isn't working for you. While I'm quite fond of Javascript, it is a very flexible language and you could have installed any number of 3rd party additions that do all kinds of crazy things with it.
    Finally, could you say me how you would  open a popup with given dimensions ?
    I normally don't use pop-ups but I have one special case where a page is displayed inside of Google Earth. Google Earth isn't a real web browser, but looks like one, so it needs lots of hacks to get some functionality. When the user clicks an image link, it uses this function to pop-up a new window that redirects itself to the appropriate image URL, successfully downloading the requested image instead of the nasty error message the user would have seen otherwise - and no download. I will add a few extra comments to explain what is going on...
    // Pass in the id of the item to download.
    function embeddedDownloadItem(id)
         // Center the pop-up in a platform-neutral way.
        var top =
            window.screenTop
                ? window.screenTop
                : window.screenY;
        var left =
            window.screenLeft
                ? window.screenLeft
                : window.screenX;
        top += $(window).height();
        left += $(window).width();
        // Move it over a bit.
        left -= 200;
        // Use the id to construct a selector to
        // find and extract the URL.
        var url = $('#url-' + id).attr('value');
        // Download the file via new window.
        downloadWindow =
            window.open(
                url,
                "Download",
                'top=' + top + ', left=' + left
                    + ',width=200,height=100');
        // Close the new window in 5 seconds.
        setTimeout("downloadWindow.close();", 5000);
        // Hide it until that happens.
        window.focus();
    As you can see, I am using jQuery which does some of that crazy stuff I mentioned earlier. However, that is not something you really want to live without. This is a special case that just pops up a window, redirects to download an image, and then goes away. I actually recommend not using pop-ups at all because they are too easy to block. In this case, it is running out of Google Earth with doesn't have a pop-up blocker, so I lucked out.
    I don't know why your code isn't working. Have you tried the demos at w3schools? They are always very handy.
    I agree with you, Safari has the best debugging features, but, I'm a little more circumspect about "the most standard compliant", but maybe I'm wrong.
    That is just what I have found. I am not really a web developer, but I have been roped into it. Because I don't really enjoy it, I don't have the same obsession towards perfection that I would elsewhere. If I can get it working in the major browsers, that's good enough for me.
    I always build in Safari first. The latest Safari has a few more debugging bells and whistles but is actually a bit harder to use in this aspect than the previous version. I build a "clean-room" version of the site in Safari with no hacks of any kind. Everything works as it should in an "ideal" browser, which just happens to be Safari. The console window and "window.console.log()" are your friends. "Inspect element" is very powerful.
    I don't bother with Chrome because it is so similar to Safari. I have never seen a significant difference between the two.
    Next up is IE7. Parallels to the rescue. Thankfully, I don't have to support IE6 anymore. IE has some very nice, version-specific hacks that allow you retain some of your sanity. I also use Zend which automatically generates these constructs. I can do something like:
            $this->view->headLink()->appendStylesheet(
                $this->view->baseUrl() . '/css/ie7.css', 'all', 'IE 7');
            $this->view->headLink()->appendStylesheet(
                $this->view->baseUrl() . '/css/ie8.css', 'all', 'IE 8');
    which will generate:
    <!--[if IE 7]> <link href="/css/ie7.css" media="all" rel="stylesheet" type="text/css" /><![endif]-->
    <!--[if IE 8]> <link href="/css/ie8.css" media="all" rel="stylesheet" type="text/css" /><![endif]-->
    Zend supports the same thing with Javascript, with a little bit more mess:
            $this->view->headScript()->appendFile(
                $this->view->baseUrl() . '/js_include/warning.js',
                'text/javascript',
                array('conditional' => 'IE 6'));
            $this->view->headScript()->appendScript(
                sprintf(
                    'window.onload=function(){e("%s")}',
                    $this->view->baseUrl() . '/images'),
                'text/javascript',
                array('conditional' => 'IE 6'));
    generates:
    <!--[if IE 6]> <script type="text/javascript" src="/js_include/warning.js"></script><![endif]-->
    <!--[if IE 6]> <script type="text/javascript">
        //<![CDATA[
    window.onload=function(){e("/images")}    //]]>
    </script><![endif]-->
    In this example, I just pop-up a warning saying IE6 isn't supported at all.
    You can do most of the IE7 and IE8 support with the above CSS hacks. If you need to change the structure to support IE, then once it works in IE you have to go back and re-test in Safari.
    I have found that IE9 is much more standards-compliant and needs very little help.
    Firefox is actually one of the flakier browsers these days - even more so than IE9. I actually have to add a special section of Firefox hacks at the end of my CSS like this:
    /* Firefox hacks */
    @-moz-document url-prefix()
        #kml_loading,
        #kmz_loading,
        #shapefile_loading
            top: -1px;
    Unfortunately, Firefox wasn't known to be a troublemaker like IE so the hacks are more ugly than in IE.

  • Checking an Array with a form input field to return true or false?

    I have an array that when dumped, lists dates for all days of the month. There is a form, where the user specifies the date and when submitted, transfers to a processing.cfm file which is where i want the <cfif> to check if the date specified in form exists in the array (this way, it only limits the user of only being able to select a date from this month for an event). Is it possible to have a cfif where it will check whether or not the array contains the date the user has specified and the return true (if contains the date specified), and transfers the form to email.cfm (where it will email all the form inputs) or will return false (if outside that range) then return back to the eventform.cfm?

    Nevermind. Figured it out.
    Heres my code if it will help anyone:
    <!---CFSET's--->
                    <cfset theDate = Now()>
                    <cfset NextMonth = DateAdd('m', 1, theDate) />
                    <cfset nextMonthNum = daysInMonth(#NextMonth#) />
                    <cfset weekNum = (#weekOfMonth(now())#) />
                    <cfset daysNum = daysInMonth(now()) />
                    <cfset dateToday = Now()>
                    <cfscript>
                                                      function weekOfMonth(thisDate) {
                                                                var thisDay=day(thisDate);
                                                                var thisWeek=0;
                                                                if (thisDay LTE 7)
                                                                thisWeek=1;
                                                                else if (thisDay GT 7 AND thisDay LTE 14)
                                                                thisWeek=2;
                                                                else if (thisDay GT 14 AND thisDay LTE 21)
                                                                thisWeek=3;
                                                                else
                                                                thisWeek=4;
                                                                return thisWeek;
                                            </cfscript>
                    <cfset datearray = ArrayNew(1)>
                    <cfif #DatePart('w', TheDate)# GTE 2 AND #weekNum# GTE 3>
                        <cfloop index="x" from="1" to="#daysNum#">
                                      <cfset datearray[x] = "#DateFormat(now(), "mm")#/#x#/#DateFormat(now(), "yy")#" />
                                <cfset recordnumber = #x#>
                                                      </cfloop>
                        <cfloop index="y" from="1" to="#nextMonthNum#">
                                  <cfset potato = #y# + #recordnumber# >
                                      <cfset datearray[potato] = "#DateFormat(NextMonth, "mm")#/#y#/#DateFormat(NextMonth, "yy")#" >
                        </cfloop>
                                  <cfelse>
                                  <cfloop index="z" from="1" to="#daysNum#">
                                <cfset datearray[z] = "#DateFormat(now(), "mm")#/#z#/#DateFormat(now(), "yy")#">
                                  </cfloop>
                            </cfif>
                    <cfif #arrayContains( datearray, "#form.activitydate#" )#>
                              <cflocation url="monkey.cfm">
                                  <cfelse>
                                      <cfset datetrue = "no">
                                <script>
                                                                                    alert("Date Not Valid. Please Specify Event Date Within Valid Range.<br>(Allow a couple seconds to refresh)")
                                                                                    history.go(-1)
                                                                          </script>
                    </cfif>

  • Problems invoking sequential javascript functions to managed bean

    Hi all.
    I have a problem. I need to do the next steps in my application.
    1. From my jsff, I need to obtain a String generated in a function in the Managed Bean.
    2. Take this generated String in my jsff and send it to a javascript function in the same jsff.
    3. The javascript function will sign this String and later will also send it to the managed bean.
    Summarizing, in my page I need to call a function in managed bean to generate one String. The page must get this String and send it to a JavaScript function. Later, from this JavaScript funcion, send the String to the Managed Bean.
    I have tried to do this with event handling (AdfCustomEvent.queue), but I think that my approach isn`t right. Now I`m trying to do this with the task flow.
    Maybe this doub is because my lack of knowledge of adf... I am newby.
    Any suggestion please?
    Regards

    I just did same thing for gov CAC card functions....
    Create inputText/outputText visible="false" bind it to your bean, compute string in your bean and assign it to your it/ot.
    ExtendedRenderKitService erks = Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
    erks.addScript(context, script);
    In the script you can use AdfPage.PAGE.findComponent('") to find your component
    when your script done assign data to a second hidden control, that you can simple get from mb

Maybe you are looking for