3

A bit stumped, this works for this first control but how do I apply it to the rest (list)

 $(function () {
        $("#spinner").spinner({
            step: 0.01,
            numberFormat: "n"
        });


    });
@foreach (var item in Model)
{<input id="spinner"  value="@item.Price" name="[email protected]"/>}

4 Answers 4

3

Use a CSS class an ID is unique and will only pick up 1 element, a class can be applied to multiple elements:

$(function () {
    $(".spinner").spinner({
        step: 0.01,
        numberFormat: "n"
    });
});


@foreach (var item in Model)
{
   <input class="spinner"  value="@item.Price" name="[email protected]"/>
}
Sign up to request clarification or add additional context in comments.

Comments

1

Try giving the inputs a class and then setting your jQuery selector to use that class.

ie.

$(".spinner").spinner({
 ...
});

<input class="spinner" ... />

Comments

0

Well, I think your problem is that your code creates multiple inputs with the same ID.

IDs should be unique. Otherwise you'll have problems selecting them with Jquery.

Use a class instead.

Comments

0

Be careful of duplicate html IDs, as in your example all your input elements will have the same ID. This is against the HTML 4 spec and HTML 5 spec. Either assign unique IDs as you are doing with the name, or do not assign the ID at all.

As mentioned before, assign a class to each input element and select via class selector: e.g.

$(".spinner").spinner({....});

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.