0
[<input id=​"unit_quantity_0" name=​"lines[0]​[quantity]​" placeholder=​"Quantité" type=​"text" value=​"23,60">​
,<input id=​"unit_quantity_2" name=​"lines[2]​[quantity]​" placeholder=​"Quantité" type=​"text" value=​"5,60">​]

How do I change the ',' in values to '.'

$("[id^=unit_quantity_]") returns the array.

Thanks.

1
  • You have an array of DOM elements. The <input id=​"unit_quantity_0".... is just their textual representation in the console. $("[id^=unit_quantity_]") does not return an array but a jQuery object. You can use jQuery methods to manipulate the selected elements (which is the whole point of jQuery). See also: replace all occurrences in a string. Commented Mar 3, 2012 at 16:22

2 Answers 2

3

How about:

$("[id^='unit_quantity_']").val(function (i, old) {
    return old.replace(/,/g, ".");
});

Example: http://jsfiddle.net/andrewwhitaker/325We/

Using the overload of .val that takes a function that lets you describe how to replace the old values.

Sign up to request clarification or add additional context in comments.

Comments

0
$("[id^=unit_quantity_]").each(function(){
    var $this=$(this);
    $this.val( $this.val().replace(/,/g,'.'));
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.