Jump to content


Photo

javascript function does not return true in firefox

javascript firefox

  • Please log in to reply
5 replies to this topic

#1 ra_ie_darkness

ra_ie_darkness

    Member

  • Members
  • PipPip
  • 22 posts

Posted 24 April 2013 - 03:25 AM

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



#2 gristoi

gristoi

    Advanced Member

  • Members
  • PipPipPip
  • 810 posts

Posted 24 April 2013 - 06:32 AM

if your using a direct comparator against true is true then it needs to be === : 

if(checkEmpty===true && checkNum===true && checkStr===true)

To err is human... to really foul up requires the root password

#3 ra_ie_darkness

ra_ie_darkness

    Member

  • Members
  • PipPip
  • 22 posts

Posted 24 April 2013 - 06:38 AM

if(checkEmpty===true && checkNum===true && checkStr===true)

didn't work :-\



#4 nogray

nogray

    Advanced Member

  • Members
  • PipPipPip
  • 930 posts
  • LocationSan Francisco CA

Posted 24 April 2013 - 01:25 PM

Always put your form validation on the form onsubmit event.


NoGray.com


#5 ra_ie_darkness

ra_ie_darkness

    Member

  • Members
  • PipPip
  • 22 posts

Posted 26 April 2013 - 08:13 AM

understandable but onsubmit did not work either. I still have the same problem



#6 Adam

Adam

    Advanced Member

  • Gurus
  • 5,683 posts
  • LocationSheffield / UK

Posted 29 April 2013 - 05:18 AM

I can't see any reason why it wouldn't work. Which version of Firefox on what OS are you testing? Could you create a http://jsfiddle.com so we can view the behaviour not working ourselves?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com