haolan Posted August 9, 2007 Share Posted August 9, 2007 Hey I am about to make a wannabe calculator, and i wanna make sure that my users can only write one comma in the display. My buttons are "on screen" so when i click the comma button i need to whether there already is a comma in the display (which is a textbox). If so, it may just ignore the press on the button. How do I make that check? Link to comment https://forums.phpfreaks.com/topic/64139-only-one-comma-at-a-time/ Share on other sites More sharing options...
Karl33to Posted August 9, 2007 Share Posted August 9, 2007 if (document.formName.fieldName.value.indexOf(',') !=-1){ // a comma exists, so do something here } also, call me picky, but calculators don't have a comma button on them! Link to comment https://forums.phpfreaks.com/topic/64139-only-one-comma-at-a-time/#findComment-319714 Share on other sites More sharing options...
haolan Posted August 9, 2007 Author Share Posted August 9, 2007 hehe i know.. but i am from Denmark.. And in Denmark we use comma instead of period Link to comment https://forums.phpfreaks.com/topic/64139-only-one-comma-at-a-time/#findComment-319765 Share on other sites More sharing options...
haolan Posted August 9, 2007 Author Share Posted August 9, 2007 hmm but your code does not work.. <script type="text/javascript"> function tjekComma() { if (document.profit_form.profit_display.value.indexOf(',') !=-1) { // DO NOTHING! } else { document.profit_form.profit_display.value = document.profit_form.profit_display.value += ','; } </script> i can still add a lot of commas... I have tried to put the document.profit..blablabla.. in the if instead of else.. But it wont work anyway.. Link to comment https://forums.phpfreaks.com/topic/64139-only-one-comma-at-a-time/#findComment-319772 Share on other sites More sharing options...
gurroa Posted August 10, 2007 Share Posted August 10, 2007 See php.gurroa.cz/test/simplecalc.html. You still have to use period in math operations. And also try to test result if somethings doesn't work, like what result are you getting from this function document.profit_form.profit_display.value.indexOf(',') Link to comment https://forums.phpfreaks.com/topic/64139-only-one-comma-at-a-time/#findComment-320168 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.