ra_ie_darkness Posted April 24, 2013 Share Posted April 24, 2013 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 Link to comment https://forums.phpfreaks.com/topic/277243-javascript-function-does-not-return-true-in-firefox/ Share on other sites More sharing options...
gristoi Posted April 24, 2013 Share Posted April 24, 2013 if your using a direct comparator against true is true then it needs to be === : if(checkEmpty===true && checkNum===true && checkStr===true) Link to comment https://forums.phpfreaks.com/topic/277243-javascript-function-does-not-return-true-in-firefox/#findComment-1426285 Share on other sites More sharing options...
ra_ie_darkness Posted April 24, 2013 Author Share Posted April 24, 2013 if(checkEmpty===true && checkNum===true && checkStr===true) didn't work Link to comment https://forums.phpfreaks.com/topic/277243-javascript-function-does-not-return-true-in-firefox/#findComment-1426287 Share on other sites More sharing options...
nogray Posted April 24, 2013 Share Posted April 24, 2013 Always put your form validation on the form onsubmit event. Link to comment https://forums.phpfreaks.com/topic/277243-javascript-function-does-not-return-true-in-firefox/#findComment-1426374 Share on other sites More sharing options...
ra_ie_darkness Posted April 26, 2013 Author Share Posted April 26, 2013 understandable but onsubmit did not work either. I still have the same problem Link to comment https://forums.phpfreaks.com/topic/277243-javascript-function-does-not-return-true-in-firefox/#findComment-1426715 Share on other sites More sharing options...
Adam Posted April 29, 2013 Share Posted April 29, 2013 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? Link to comment https://forums.phpfreaks.com/topic/277243-javascript-function-does-not-return-true-in-firefox/#findComment-1427082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.