Jump to content

javascript function does not return true in firefox


ra_ie_darkness

Recommended Posts

I have written a fucntion in javascript for validation.

The submit button is inside a form

<input type="submit" name="submit_request" value="Submit" id="submit_req" onclick="return checkQ(event);" style="backgroundColor:Transparent;border:0;color:blue;width:100;"/>

This is the function

function checkQ()
{   
    //Validation
    var checkEmpty; //check empty text field
    var checkNum;   //check whether authorized value is greater than the requested value
    var checkStr    //check whether string is entered
    var qLength = document.getElementsByName("pQuantity[]").length;
    for(i=0;i<qLength;i++)
    {
        var pValue = document.getElementsByName("pQuantity[]")[i].value; //authorized quantity
        var reQnty = document.getElementsByName("quantity[]")[i].value; //requested quantity
        if(pValue != "")
        {
            checkEmpty = true;
        }
        else
        {
            alert("Quantity missing");
            checkEmpty = false;
            return false;
        }
        if(Number(pValue)>Number(reQnty))
        {
            alert("greater value");
            checkNum = false;
            return false;
        }
        else
        {
            checkNum = true;
        }
        if(!Number(pValue))
        {
            alert("You are only allowed to enter a number");
            checkStr = false;
            return false;
        }
        else
        {
            checkStr = true;
        }
    }
    if(checkEmpty==true && checkNum==true && checkStr==true)
    {
        alert("working");
        return true;
    }
}

It works fine in chrome and IE but for some reason even when every condition is satifisfied the form is not submitted in firefox. I get the alert dialogue box saying "working" but nothing happens after that. how to fix it

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.