Jump to content

Only one comma at a time


haolan

Recommended Posts

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

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..

 

 

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(',')

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.