Jump to content

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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