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? Quote Link to comment 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! Quote Link to comment 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 Quote Link to comment 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.. Quote Link to comment 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(',') 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.