0

I'm afraid my title is somewhat messy. I am working with Spring MVC and my form is associated to a class with several ArrayList and when trying to get javascript(jquery is fine) to recover the value of one o its attributes it always returns "undefined" of [Object object] instead of the value.

My jsp

        <c:forEach var="item" items="${form.fact}" varStatus="status">
                   <tr>
                        <td>
                            <sf:hidden path="fact[${status.index}].name"/>
                            <c:out value="${form.fact[status.index].name}" />
                        </td>
                        <sf:hidden path="fact[${status.index}].id"/>
                    </tr>
         </c:forEach>

The value I'm trying to recover for my js is the one that is hidden, that is, the "id".

when using:

var nm= $("fact2.id").val();

I get undefined although when checking the code of the page I see:

 <input id="fact2.id" name="fact[2].id" type="hidden" value="55572"/>

I have tried with

document.getElementById("fact2.id")
document.getElementsByName("fact[2].id")

but can't manage to get the value.

If anybody can help I would greatly appreciate it. Thank you.

2 Answers 2

1

Your selector is wrong, you need to use id-selector (#id) also need to escape the . in the id

var nm= $("#fact2\\.id").val();
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. The id-selector was a tipyng error, it was there originally, but I hadn't thought about escaping the <code>.</code>. Works perfectly now.
0

Please Check This. It is working fine.This is working in all cases. In case of any issue please let me know.

$("[id^=fact2]").val();

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.