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> Link to comment https://forums.phpfreaks.com/topic/92394-getting-errors-whith-numbers/ 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> Link to comment https://forums.phpfreaks.com/topic/92394-getting-errors-whith-numbers/#findComment-473397 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 Link to comment https://forums.phpfreaks.com/topic/92394-getting-errors-whith-numbers/#findComment-473402 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. Link to comment https://forums.phpfreaks.com/topic/92394-getting-errors-whith-numbers/#findComment-473410 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. Link to comment https://forums.phpfreaks.com/topic/92394-getting-errors-whith-numbers/#findComment-473412 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. Link to comment https://forums.phpfreaks.com/topic/92394-getting-errors-whith-numbers/#findComment-473418 Share on other sites More sharing options...
phpQuestionerThe4th Posted February 22, 2008 Share Posted February 22, 2008 Glad It Worked Out For You Link to comment https://forums.phpfreaks.com/topic/92394-getting-errors-whith-numbers/#findComment-473425 Share on other sites More sharing options...
fenway Posted February 22, 2008 Share Posted February 22, 2008 Careful using parseInt without a radix. Link to comment https://forums.phpfreaks.com/topic/92394-getting-errors-whith-numbers/#findComment-474010 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 Link to comment https://forums.phpfreaks.com/topic/92394-getting-errors-whith-numbers/#findComment-474120 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. Link to comment https://forums.phpfreaks.com/topic/92394-getting-errors-whith-numbers/#findComment-474474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.