0

I am creating a struts based application and i want to load a div based on content in a sj:textfield. I am using struts jquery plugin. The div has to be loaded by passing the textfield contents to a struts action.

Can anyone tell me how to do so since I could not find any instance of this anywhere.

nkvp
  • 342
  • 1
  • 8
  • 15
  • possible duplicate of [How to call Struts2 Action method in ajax?](http://stackoverflow.com/questions/3239960/how-to-call-struts2-action-method-in-ajax) – jmj Jun 25 '12 at 06:03
  • 1
    @jigar-joshi nope, there what they are asking is how to call Struts2 Action method in ajax, that's different. Here, i want to know if it is possible to load a div without a submit button using ajax by passing form parameters to struts action as the user types. – nkvp Jun 25 '12 at 19:15

1 Answers1

2

i am not sure, if i got u right. but i will give a try. check out the code below

<s:form action="action">
  <sj:textfield name="name" value="value" label="label/>
  <sj:submit targets="myResultDiv"/>
</s:form>

<div id="myResultDiv"></div>

after you submit the form, the result should be appeared in the div with id "myResultDiv", check out the struts2 jquery plugin page strut2-jquery-plugin-showcase

EDIT 1

<s:form id="myForm" action="action">
  <sj:textfield name="name" value="value" label="label" onChangeTopics="changeTopic"/>
</s:form>

<div id="myResultDiv"></div>
<script>
$.subscribe('changeTopic', function(event, data) {
var ui = event.originalEvent.ui;
if(ui.item) {
    $('#myResultDiv').html('<p>'+message+'</p>');
}
});
</script>
Community
  • 1
  • 1
Jaiwo99
  • 9,687
  • 3
  • 36
  • 53
  • actually, the form should not have a submit button. What i wanted is that the form should be submitted for each character, like autocomplete but the results should be loaded in the div tag. – nkvp Jun 25 '12 at 09:36
  • is it possible using the plugin or should i include jquery javascript? – nkvp Jun 25 '12 at 15:56
  • @nkvp you do not have to include jquery, once you include , jquery is automatically included. if u do not like to have a submit in the form, c EDIT 1 – Jaiwo99 Jun 25 '12 at 18:55
  • ok... sorry i didn't see it... but how does the form get submitted in the example? ill check and see.. what is "message" in the code? – nkvp Jun 26 '12 at 03:35