You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adriana G <ad...@gmail.com> on 2012/07/30 18:20:25 UTC

Ajax and struts 1

Help!

I need to refresh a select option  using ajax,
i have this function that returns me an string list,
and i need to put in a select option. but it doesn't work with the
<html:select> tag.

I used to fill the select option with a persistent object declared in the
form, but i now i know how to updated taking into account the result o f
the ajax function.
Thks.

function doAjaxPost(tipo) {
// get the form values
var name = $('#name').val();
$.ajax({
type: "POST",
url: "/fethusweb/registraPaciente.do",
data: "name=" + name +"&enviar="+tipo,
success:
function(response){

var result = response.substring(1,response.length-3);
var vectorResponse = result.split(",");
var menu= document.getElementsByClassName("menu","david");
for(var i in vectorResponse){
var theOption = new Option;
 theOption.text = vectorResponse[i];
theOption.value = 1;
menu[0].options[i]=theOption;
}

          },
               error: function(e){
                     alert('Error: ' + e);
                 }
             });
          }


-----//

 <html:select styleClass="select" property="ciudad.idCiudad"

           name="registrarPacienteForm" >

           <logic:iterate id="objeto" name="registrarPacienteForm"

                   property="ciudades">

                   <html-el:option value="${objeto.idCiudad}">

                           <c:out value="${objeto.nombre}" />

                   </html-el:option>

           </logic:iterate>

   </html:select>


-- 
Adriii :)..



-- 
Adriii :)..

Re: Ajax and struts 1

Posted by "Ing. Alvaro Gomez" <ag...@ss.sertracen.com.sv>.
in user servlet in ajax in single...
call servlet in action is regenerate el code in html de selection


On 30/07/2012 11:19 a.m., Adriana G wrote:
> I fill the select with a peersistent list than come from a method that
> returns a result from the DB.
>
> but i don't know how to update the select without refresing the whole page,
> that's why i'm trying ajax with this function, but i don't know how to use
> it.
>
> On Mon, Jul 30, 2012 at 12:05 PM, Dave Newton<da...@gmail.com>  wrote:
>
>> Define "doesn't work".
>>
>> What's in the response? JSON?
>>
>> How are you accessing the select element? I don't see anything where you
>> set its ID or get it by its class name etc.
>>
>> What's in the JS console after your AJAX call returns? Anything?
>>
>> Dave
>>
>> On Mon, Jul 30, 2012 at 12:20 PM, Adriana G<ad...@gmail.com>
>> wrote:
>>
>>> Help!
>>>
>>> I need to refresh a select option  using ajax,
>>> i have this function that returns me an string list,
>>> and i need to put in a select option. but it doesn't work with the
>>> <html:select>  tag.
>>>
>>> I used to fill the select option with a persistent object declared in the
>>> form, but i now i know how to updated taking into account the result o f
>>> the ajax function.
>>> Thks.
>>>
>>> function doAjaxPost(tipo) {
>>> // get the form values
>>> var name = $('#name').val();
>>> $.ajax({
>>> type: "POST",
>>> url: "/fethusweb/registraPaciente.do",
>>> data: "name=" + name +"&enviar="+tipo,
>>> success:
>>> function(response){
>>>
>>> var result = response.substring(1,response.length-3);
>>> var vectorResponse = result.split(",");
>>> var menu= document.getElementsByClassName("menu","david");
>>> for(var i in vectorResponse){
>>> var theOption = new Option;
>>>   theOption.text = vectorResponse[i];
>>> theOption.value = 1;
>>> menu[0].options[i]=theOption;
>>> }
>>>
>>>            },
>>>                 error: function(e){
>>>                       alert('Error: ' + e);
>>>                   }
>>>               });
>>>            }
>>>
>>>
>>> -----//
>>>
>>>   <html:select styleClass="select" property="ciudad.idCiudad"
>>>
>>>             name="registrarPacienteForm">
>>>
>>>             <logic:iterate id="objeto" name="registrarPacienteForm"
>>>
>>>                     property="ciudades">
>>>
>>>                     <html-el:option value="${objeto.idCiudad}">
>>>
>>>                             <c:out value="${objeto.nombre}" />
>>>
>>>                     </html-el:option>
>>>
>>>             </logic:iterate>
>>>
>>>     </html:select>
>>>
>>>
>>> --
>>> Adriii :)..
>>>
>>>
>>>
>>> --
>>> Adriii :)..
>>>
>>
>>
>> --
>> e: davelnewton@gmail.com
>> m: 908-380-8699
>> s: davelnewton_skype
>> t: @dave_newton<https://twitter.com/dave_newton>
>> b: Bucky Bits Blog<http://buckybits.blogspot.com/>


Re: Ajax and struts 1

Posted by Dave Newton <da...@gmail.com>.
Oh, so you're asking how to write JavaScript and update a select box?

There should be plenty of tutorials on the internet; that you're using
Struts 1 doesn't change any of the client-side stuff.

Dave

On Mon, Jul 30, 2012 at 1:19 PM, Adriana G <ad...@gmail.com> wrote:

> I fill the select with a peersistent list than come from a method that
> returns a result from the DB.
>
> but i don't know how to update the select without refresing the whole page,
> that's why i'm trying ajax with this function, but i don't know how to use
> it.
>
> On Mon, Jul 30, 2012 at 12:05 PM, Dave Newton <da...@gmail.com>
> wrote:
>
> > Define "doesn't work".
> >
> > What's in the response? JSON?
> >
> > How are you accessing the select element? I don't see anything where you
> > set its ID or get it by its class name etc.
> >
> > What's in the JS console after your AJAX call returns? Anything?
> >
> > Dave
> >
> > On Mon, Jul 30, 2012 at 12:20 PM, Adriana G <ad...@gmail.com>
> > wrote:
> >
> > > Help!
> > >
> > > I need to refresh a select option  using ajax,
> > > i have this function that returns me an string list,
> > > and i need to put in a select option. but it doesn't work with the
> > > <html:select> tag.
> > >
> > > I used to fill the select option with a persistent object declared in
> the
> > > form, but i now i know how to updated taking into account the result o
> f
> > > the ajax function.
> > > Thks.
> > >
> > > function doAjaxPost(tipo) {
> > > // get the form values
> > > var name = $('#name').val();
> > > $.ajax({
> > > type: "POST",
> > > url: "/fethusweb/registraPaciente.do",
> > > data: "name=" + name +"&enviar="+tipo,
> > > success:
> > > function(response){
> > >
> > > var result = response.substring(1,response.length-3);
> > > var vectorResponse = result.split(",");
> > > var menu= document.getElementsByClassName("menu","david");
> > > for(var i in vectorResponse){
> > > var theOption = new Option;
> > >  theOption.text = vectorResponse[i];
> > > theOption.value = 1;
> > > menu[0].options[i]=theOption;
> > > }
> > >
> > >           },
> > >                error: function(e){
> > >                      alert('Error: ' + e);
> > >                  }
> > >              });
> > >           }
> > >
> > >
> > > -----//
> > >
> > >  <html:select styleClass="select" property="ciudad.idCiudad"
> > >
> > >            name="registrarPacienteForm" >
> > >
> > >            <logic:iterate id="objeto" name="registrarPacienteForm"
> > >
> > >                    property="ciudades">
> > >
> > >                    <html-el:option value="${objeto.idCiudad}">
> > >
> > >                            <c:out value="${objeto.nombre}" />
> > >
> > >                    </html-el:option>
> > >
> > >            </logic:iterate>
> > >
> > >    </html:select>
> > >
> > >
> > > --
> > > Adriii :)..
> > >
> > >
> > >
> > > --
> > > Adriii :)..
> > >
> >
> >
> >
> > --
> > e: davelnewton@gmail.com
> > m: 908-380-8699
> > s: davelnewton_skype
> > t: @dave_newton <https://twitter.com/dave_newton>
> > b: Bucky Bits Blog <http://buckybits.blogspot.com/>
> >
>
>
>
> --
> Adriii :)..
>



-- 
e: davelnewton@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton <https://twitter.com/dave_newton>
b: Bucky Bits Blog <http://buckybits.blogspot.com/>

Re: Ajax and struts 1

Posted by Adriana G <ad...@gmail.com>.
I fill the select with a peersistent list than come from a method that
returns a result from the DB.

but i don't know how to update the select without refresing the whole page,
that's why i'm trying ajax with this function, but i don't know how to use
it.

On Mon, Jul 30, 2012 at 12:05 PM, Dave Newton <da...@gmail.com> wrote:

> Define "doesn't work".
>
> What's in the response? JSON?
>
> How are you accessing the select element? I don't see anything where you
> set its ID or get it by its class name etc.
>
> What's in the JS console after your AJAX call returns? Anything?
>
> Dave
>
> On Mon, Jul 30, 2012 at 12:20 PM, Adriana G <ad...@gmail.com>
> wrote:
>
> > Help!
> >
> > I need to refresh a select option  using ajax,
> > i have this function that returns me an string list,
> > and i need to put in a select option. but it doesn't work with the
> > <html:select> tag.
> >
> > I used to fill the select option with a persistent object declared in the
> > form, but i now i know how to updated taking into account the result o f
> > the ajax function.
> > Thks.
> >
> > function doAjaxPost(tipo) {
> > // get the form values
> > var name = $('#name').val();
> > $.ajax({
> > type: "POST",
> > url: "/fethusweb/registraPaciente.do",
> > data: "name=" + name +"&enviar="+tipo,
> > success:
> > function(response){
> >
> > var result = response.substring(1,response.length-3);
> > var vectorResponse = result.split(",");
> > var menu= document.getElementsByClassName("menu","david");
> > for(var i in vectorResponse){
> > var theOption = new Option;
> >  theOption.text = vectorResponse[i];
> > theOption.value = 1;
> > menu[0].options[i]=theOption;
> > }
> >
> >           },
> >                error: function(e){
> >                      alert('Error: ' + e);
> >                  }
> >              });
> >           }
> >
> >
> > -----//
> >
> >  <html:select styleClass="select" property="ciudad.idCiudad"
> >
> >            name="registrarPacienteForm" >
> >
> >            <logic:iterate id="objeto" name="registrarPacienteForm"
> >
> >                    property="ciudades">
> >
> >                    <html-el:option value="${objeto.idCiudad}">
> >
> >                            <c:out value="${objeto.nombre}" />
> >
> >                    </html-el:option>
> >
> >            </logic:iterate>
> >
> >    </html:select>
> >
> >
> > --
> > Adriii :)..
> >
> >
> >
> > --
> > Adriii :)..
> >
>
>
>
> --
> e: davelnewton@gmail.com
> m: 908-380-8699
> s: davelnewton_skype
> t: @dave_newton <https://twitter.com/dave_newton>
> b: Bucky Bits Blog <http://buckybits.blogspot.com/>
>



-- 
Adriii :)..

Re: Ajax and struts 1

Posted by Dave Newton <da...@gmail.com>.
Define "doesn't work".

What's in the response? JSON?

How are you accessing the select element? I don't see anything where you
set its ID or get it by its class name etc.

What's in the JS console after your AJAX call returns? Anything?

Dave

On Mon, Jul 30, 2012 at 12:20 PM, Adriana G <ad...@gmail.com> wrote:

> Help!
>
> I need to refresh a select option  using ajax,
> i have this function that returns me an string list,
> and i need to put in a select option. but it doesn't work with the
> <html:select> tag.
>
> I used to fill the select option with a persistent object declared in the
> form, but i now i know how to updated taking into account the result o f
> the ajax function.
> Thks.
>
> function doAjaxPost(tipo) {
> // get the form values
> var name = $('#name').val();
> $.ajax({
> type: "POST",
> url: "/fethusweb/registraPaciente.do",
> data: "name=" + name +"&enviar="+tipo,
> success:
> function(response){
>
> var result = response.substring(1,response.length-3);
> var vectorResponse = result.split(",");
> var menu= document.getElementsByClassName("menu","david");
> for(var i in vectorResponse){
> var theOption = new Option;
>  theOption.text = vectorResponse[i];
> theOption.value = 1;
> menu[0].options[i]=theOption;
> }
>
>           },
>                error: function(e){
>                      alert('Error: ' + e);
>                  }
>              });
>           }
>
>
> -----//
>
>  <html:select styleClass="select" property="ciudad.idCiudad"
>
>            name="registrarPacienteForm" >
>
>            <logic:iterate id="objeto" name="registrarPacienteForm"
>
>                    property="ciudades">
>
>                    <html-el:option value="${objeto.idCiudad}">
>
>                            <c:out value="${objeto.nombre}" />
>
>                    </html-el:option>
>
>            </logic:iterate>
>
>    </html:select>
>
>
> --
> Adriii :)..
>
>
>
> --
> Adriii :)..
>



-- 
e: davelnewton@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton <https://twitter.com/dave_newton>
b: Bucky Bits Blog <http://buckybits.blogspot.com/>