monkeybidz Posted February 22, 2008 Share Posted February 22, 2008 When I enter a value of less than 1.00 I get an alert. I want to be able to enter a numeric value of 0.01 and above. Here is the script: <script type ="text/javascript"> function chkbidprice() { //alert(parseInt(document.getElementById('buy').value)); if(parseInt(document.bid.bid.value) >0){} else { alert("Your maximum bid is invalid. Please bid again!"); return false; } if(parseInt(document.bid.bid.value) < parseInt(document.getElementById('start').value)) { alert("Your maximum bid should be greater or equal to start bid! Please try again!"); return false; } if((parseInt(document.getElementById('buy').value)>0) && parseInt(document.bid.bid.value) > parseInt(document.getElementById('buy').value)) { alert("Your maximum bid can not be greater than Buy it now ! Please try again!"); return false; } } </script> Quote Link to comment Share on other sites More sharing options...
phpQuestionerThe4th Posted February 22, 2008 Share Posted February 22, 2008 try this and see how it works out for you: <script type="text/javascript"> function chkbidprice() { var currentBidVal = document.bid.bid.value; var bidval = parseInt(currentBidVal); var intial = document.getElementById('start').value; var beginbid = parseInt(intial); var buyItNow = document.getElementById('buy').value; var buy = parseInt(buyItNow); if (bidval > 0) { // do nothing } else if (bidval == "0") { alert("Your maximum bid is invalid. Please bid again!"); } else if (bidval < beginbid) { alert("Your maximum bid should be greater or equal to start bid! Please try again!"); } else if (buy > "0" && bidval > buy) { alert("Your maximum bid can not be greater than Buy it now ! Please try again!"); } } </script> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 22, 2008 Share Posted February 22, 2008 use the toFixed function instead of parseInt Examples: http://www.mredkj.com/javascript/numberFormat.html Quote Link to comment Share on other sites More sharing options...
monkeybidz Posted February 22, 2008 Author Share Posted February 22, 2008 Did not work. That allowed me to bid 0, but not anything over 0. Quote Link to comment Share on other sites More sharing options...
phpQuestionerThe4th Posted February 22, 2008 Share Posted February 22, 2008 Then flip your operators; example: < becomes > or > becomes < Just depends on what your going for. Quote Link to comment Share on other sites More sharing options...
monkeybidz Posted February 22, 2008 Author Share Posted February 22, 2008 I changed this line from: if(parseInt(document.bid.bid.value) >0){} To: if(parseInt(document.bid.bid.value) >=0){} That seemed to do the trick. Does both of the operations you guys mentioned also. Quote Link to comment Share on other sites More sharing options...
phpQuestionerThe4th Posted February 22, 2008 Share Posted February 22, 2008 Glad It Worked Out For You Quote Link to comment Share on other sites More sharing options...
fenway Posted February 22, 2008 Share Posted February 22, 2008 Careful using parseInt without a radix. Quote Link to comment Share on other sites More sharing options...
nogray Posted February 23, 2008 Share Posted February 23, 2008 Yep, alert(parseInt("08")); // alerts 0 alert(parseInt("08", 10)); // alerts 8 Quote Link to comment Share on other sites More sharing options...
fenway Posted February 23, 2008 Share Posted February 23, 2008 More to the point: alert(parseInt("010")); // alerts 8 Octal prefix magic is automatic. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.