return false; not working

In have an onchange event associated with an input control and whe this event fires I validate the contents. If they are valid there is no problem but if they are invalid I use a 'return false;' but the cursor still goes to the next control anyway.

Note:
I have this logic on two different servers, It works on one but not the other. Thee servers are suposedly the same. What can I look for to solve this problem

Thanks

Andy

Comments

  • Can you show us the javascript code? If simply the return false didn't work I would say you probably return false in your statement and exit prematurely.

    function Validate(form) {
    var msg=""
    if (form1.name.value.length < 5 || form1.name.value.length > 20 ) {
    msg += " Username must be 5 - 20 characters.";
    }
    if (form1.pwd1.value.length < 5 || form1.pwd1.value.length > 20 ) {
    msg += "
    Password must be 5 - 20 characters.";
    }
    if (msg != "") { alert(msg); return false; }

    }

    This will not go on to the next statement (that is exit the funtion) if the condifiton is false.

    You say it works on another server though check if you are really using the same scripts and configuration.

    : In have an onchange event associated with an input control and whe this event fires I validate the contents. If they are valid there is no problem but if they are invalid I use a 'return false;' but the cursor still goes to the next control anyway.
    :
    : Note:
    : I have this logic on two different servers, It works on one but not the other. Thee servers are suposedly the same. What can I look for to solve this problem
    :
    : Thanks
    :
    : Andy
    :
    :

    [hr][grey]To err is human, but to really foul things up requires a computer. (Farmers Almanac)[/grey] :-)

  • I have HTML 2 editable Input Textbox Controls, inpForecastPct and inpForecastWgt. Upon entry inpForecastPct gets the focus. In the onChange event I have "return function chgForecastPct(this);", see following code. If the value entered i not = "D" or > 100.00 I display an Alert message and "return false;". This part works on all 3 servers, I get the appropriate message and the function stops. What does not work on servers 2 & 3 is that the cursor proceeds to the next Input Textbox, inpForecastWgt rather than remain in the current Textbox, inpForecastPct. In other words the onChange event is not being cancelled.

    The documentation states that the onChange event is cancelable and has been around since version 1


    All 3 servers are running Scripting Version 5.6.8513

    Server 1 is an XP Pro, IE 6
    Server 2 & 3 are Windows 2000, IE 6








    function chgForecastPct(obj)
    {
    var rx = obj.parentElement.parentElement.rowIndex;
    var chkobj = eval("document.forms[0].DataGrid1__ctl" + parseInt(rx + 1) + "_chkForecastPct");
    var inpobj = eval("document.forms[0].DataGrid1__ctl" + parseInt(rx + 1) + "_inpForecastPct");
    var hdnobj = eval("document.forms[0].DataGrid1__ctl" + parseInt(rx + 1) + "_hdnForecastPct");

    inpobj.value = Trim(inpobj.value.toUpperCase());
    hdnobj.value = Trim(hdnobj.value.toUpperCase());

    /* check for valid input */

    if(isNaN(parseFloat(inpobj.value)) && inpobj.value != "D")
    {
    alert("Invalid Numeric Pct Value...(D, 0-9)");
    error_sw = true;
    return false;
    }
    else
    {
    if(parseFloat(inpobj.value) > 100.00)
    {
    alert("Invalid Numeric Pct Value...(0-9, D)");
    error_sw = true;
    return false;
    }
    }

    /* if no errors... */

    if(Trim(inpobj.value) == Trim(hdnobj.value))
    {
    inpobj.className = " inputBdr";

    chkobj.checked = false;
    --upd_cnt;

    }
    else
    {
    inpobj.className = "inputBdr".concat(" inputChg");
    if(!chkobj.checked)
    {
    chkobj.checked = true;
    ++upd_cnt;
    }
    }


    }




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion