PDA

View Full Version : spring bind path in javascript


mummySpring
Dec 6th, 2007, 03:51 PM
hi all,

how to take the spring bind path's value into javascript.
i can do this,
-jsp-
<form name="form1">
<spring bind: path="user.name">

-javascript-
document.form1.name.value;

but if its like this,
<spring bind: path="user.address.state">

i m guessing id be like this
document.form1.address.state.value;

the javascript error console gave me error saying no such properties.

please help me...
thanks in advance

mummySpring
Dec 6th, 2007, 04:05 PM
i still dunno the correct way to deal with the problem..
but this way kinda work..

-jsp-
<form name="form1">
<spring bind: path="user.address.state">
<input name="${status.exprssion}" value="${status.value}" type="hidden" />
<input name="state" type="text">
</spring bind>

-javascript-
document.form1.state.value;

it certainly works for me.hehehe
but if theres anotherr way,please do share.

na-ah...guess the so-called trick tricked me back...
problem arise after that when validation still takes the user.address.state value which is still null...huhu~~~

pmularien
Dec 6th, 2007, 04:56 PM
If you're referencing form fields in Javascript, I'd suggest using the 'id' attribute instead of relying on the form field name, which is provided by Spring, and may change. Then use:

document.getElementById('state').value='sdfsdf';

... instead.

mummySpring
Dec 6th, 2007, 05:02 PM
ok...
another solution is by using getElementById (input id) on the javascript instead of calling the input name value.

huh..finally