[Seaside] How do I use JQuery with Javascript variable
Francisco Martins
chicoary at gmail.com
Mon Jan 30 01:09:42 UTC 2012
Thanks Johan for your answer.
See my code below:
renderContentOn: html
| checkedValue |
(html jQuery: #testButton)
onClick: (html jQuery ajax
callback: [:val | checkedValue := val]
value: (JSStream on: '$(''[name="someRadioGroup"]:radio:checked").val()');
onComplete: ((html jQuery: #result) load
html: [:renderer | renderer html: 'The radio element with value
<tt>' , checkedValue , '</tt> is checked.'])).
html
form: [html
div: [html label for: #radioYes;
with: 'What is your answer?'.
html
radioGroup: [:group |
html radioButton id: #radioYes;
group: group;
name: #someRadioGroup;
value: #yes;
selected: true;
with: 'Yes'.
html radioButton id: #radioNo;
group: group;
name: #someRadioGroup;
value: #no;
with: 'No'.
html radioButton id: #radioMaybe;
group: group;
name: #someRadioGroup;
value: #maybe;
with: 'Maybe'.
html radioButton id: #radioConfused;
group: group;
name: #someRadioGroup;
value: #confused;
with: 'I dunno']].
html
div: [html button type: #button;
id: #testButton;
class: #green90x24;
with: 'Which?'].
html div id: #result]
Unfortunately the code did not work. I did something wrong?
> Francisco,
>
> If you want to include a callback to the server on click, this is how I would do it:
>
> (html jQuery: #testButton) onClick: (
> (html jQuery ajax
> callback: [:val | checkedValue := val]
> value: (JSStream on: '$(''[name=''someRadioGroup'']:radio:checked'').val()');
> onComplete: (html jQuery: #result) load html: [:renderer| renderer html: 'The radio element with value <tt>' , checkedValue, '</tt> is checked.'])
>
> This effectively makes two callbacks: one to retrieve the value and one to render the html.
>
> Johan
--
Sds.,
Francisco Ary Martins
http://chicoary.wordpress.com
----
"A filosofia não é senão uma poesia sofisticada."
Montaigne
More information about the seaside
mailing list