Forums

Input Box: how to replace a COMMA into a DOT

monak83 15 Jun, 2011
Hi,
I have a form where users puts dimensions of a banner.
Dimensions are width and heigth.
These dimensions can be also decimal like "12.4".
My users are italian and they use COMMA and non DOT so if they put "12,4" javascript validation number system makes an error.
So I whould replace COMMA with DOT automatically.

Here a piece of my form:

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 440px;">Base (in cm)</label>
    <input class="cf_inputbox required validate-number" maxlength="150" size="5" id="text_2" name="base" type="text" onChange="updatethis(this.form);" value="" />


I have found online this solution:

onchange="this.value=this.value.replace(/\,/,'.');"


and I have modified my code like here:

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 440px;">Base (in cm)</label>
    <input class="cf_inputbox required validate-number" maxlength="150" size="5" id="text_2" name="base" type="text" onChange="updatethis(this.form); this.value=this.value.replace(/\,/,'.');" value="" />


but doesn't update every time my input box, some times yes and sometimes no.

Why?

You can see my form here:
http://www.sgagrafica.com/index.php?option=com_content&view=article&id=77&Itemid=120

Regards
monak83
GreyHead 27 Jun, 2011
Hi monak83,

Here's a script that seems to work OK. Add it to the Form JavaScript box, then add the 'no_comma' class to any inputs where you want to have the comma replaced.
window.addEvent('domready', function() {
  $$('.no_comma').each(function(item) {
    item.addEvent('keyup', function(){
      this.value = this.value.replace(/,/, '.') ;
    });
  });
});

Here's your input with the class added:
<input class="cf_inputbox required validate-number no_comma" maxlength="150" size="5" id="text_2" name="base" type="text" value="" />

Bob
GreyHead 28 Jul, 2011
Hi monak83,

I took a look at the form but as the superficie input appears to be both required and readonly I gave up.

I did see that in IE9 there is this error "Line: 522
Error: The value of the property 'BixFormUpdate' is null or undefined, not a Function object"

Bob
monak83 28 Jul, 2011
So is not a problem caused by "replace comma into dot" function?
How should I do?

Thanks so much for your time Bob.

monak83
GreyHead 29 Jul, 2011
Hi monak83,

It may be a problem with my code snippet - though in the tests I ran that seemed to be OK. If everything else works whe you remove it then it could be a problem.

But the readonly+required input makes the form practically unusable anyhow.

Bob
GreyHead 29 Jul, 2011
Hi monak83,

I don't think that is causing the problem but it makes the form unusable so I'm not going to waste time on it.

And on the other form you linked to there is a JavaScript error that 'displaydesc is not defined'. That seems to be some other script that is missing or broken.

Bob
monak83 29 Jul, 2011
Do you have another idea/solution to replace COMMA with DOT?
Probably with another script the problem is solved?!?!?

Regards

monak83
This topic is locked and no more replies can be posted.