I'm not proud at all of this code, I wrote it long long time ago, but it
works, so here it is. You need to create an action that receives a
parameter called valueSelected, get the values for the second select,
and returns them with the following aspect:

<OPTIONS>
        <OPTION value="45298-1">1</OPTION>
        <OPTION value="45298-10">10</OPTION>
</OPTIONS>

Code HTML

<html:select property="firstSelect" styleId="firstSelect"
onchange="getSecurities()">
[load the first select]
</html:select>

<html:select property="secondSelect" styleId="secondSelect">
</html:select>

Code Javascript

function getSecurities() {
  var select = document.getElementById("secondSelect ");
  while (select.length>1){
    select.remove(1);
  }
  var valueSelected = document.getElementById("firstSelect").value;
  var url ="MyActionToGetValuesForSecondSelect.accion"
  var params = " valueSelected ="+ valueSelected +"&mySecondParameter="+
mySecondParameter
  updateAjaxSelect(url,params,"idSecurities")
 }

var browser = 'IE'
try {
        if (XPathEvaluator) browser='FF'
}
catch(E){}

function updateAjaxSelect(url,params,idSelect){
        var select = document.getElementById(idSelect);
  get(url,params,function(doc) {
        if (browser=='FF') {
                        var oEvaluator = new XPathEvaluator();
                        var oResult =
oEvaluator.evaluate("OPTIONS/OPTION", doc, null,
XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
                        if (oResult != null) {
                var oElement = oResult.iterateNext();
                while(oElement) {
                oElement = oResult.iterateNext();
                                var opt =
document.createElement("option");
                //alert("oElement.text "+oElement.textContent
                //alert("oElement.getAttribute('value')
"+oElement.getAttribute("value"))
 
opt.appendChild(document.createTextNode(oElement.textContent));
                opt.value = oElement.getAttribute("value");
                        select.appendChild(opt);
                //alert(oElement);
                        }
                }
        }
        else {
                        var nodos = doc.selectNodes("OPTIONS/OPTION")
                        for (i=0;i<nodos.length;i++){
                        var opt = document.createElement("option");
        opt.appendChild(document.createTextNode(nodos[i].text));
        opt.value = nodos[i].getAttribute("value");
                select.appendChild(opt);
                        }
        }
                }
        )
}

if ( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function()
{
        try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e)
{}
        try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e)
{}
        try { return new ActiveXObject("Msxml2.XMLHTTP")     } catch(e)
{}
        try { return new ActiveXObject("Microsoft.XMLHTTP")  } catch(e)
{}
        throw new Error("This browser does not support XMLHttpRequest");
};

function get(url, vars, callback) {
        var req =  new XMLHttpRequest();
        req.open("POST", url, true);
        req.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
        req.onreadystatechange = function() {
                if (req.readyState != 4 || req.status != 200)
                        return;
                var doc = req.responseXML
                if (!doc)
                        return;
                callback(doc);
        };
        req.send(vars);
}

-----Original Message-----
From: Dave Newton [mailto:davelnew...@gmail.com] 
Sent: Tuesday, February 22, 2011 8:55 PM
To: Struts Users Mailing List
Cc: Jerson John; jlm...@gmail.com
Subject: Re: Double Select Tag

On Tue, Feb 22, 2011 at 8:50 PM, Jerson John wrote:
> Could u send me some sample code for it ...Appreciate ur help

I think probably searching for "ajax autocomplete" will bring up
hundreds of examples; I'd try that first.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org


-----Original Message-----
From: Jerson John [mailto:jer...@cprvision.com] 
Sent: Tuesday, February 22, 2011 8:51 PM
To: 'Struts Users Mailing List'; jlm...@gmail.com
Subject: RE: Double Select Tag

Hi JL,
   Could u send me some sample code for it ...Appreciate ur help


Many Thanks and Regards,


-----Original Message-----
From: jlm...@gmail.com [mailto:jlm...@gmail.com] 
Sent: Tuesday, February 22, 2011 12:41 PM
To: Jerson John; 'Struts Users Mailing List'
Subject: Re: Double Select Tag

Not right now, but you will find plenty of them on dojo's web page. But
if
you are gonna use it only once, then I would suggest to implement it
manually, rather than start looking the dojo api(can be quite comples).

Actually, I got someplace an example of a select loaded dinamically
using
ajax directly. It's pretty simple, so you should be able wo work
something
out of it. I will look and send it tomorrow.
------Mensaje original------
De: Jerson John
Para: 'Struts Users Mailing List'
Para: Yo
Asunto: RE: Double Select Tag
Enviado: 21 Feb, 2011 23:29

Thanks a lot for this quick reply...I roughly understood what u mean by
ur
three option...For the third one using dojo...Can u please provide me
some
sample code for that...I will be a great help ...

Many Thanks and Regards,

Jerson

-----Original Message-----
From: jlm...@gmail.com [mailto:jlm...@gmail.com] 
Sent: Tuesday, February 22, 2011 12:19 PM
To: Struts Users Mailing List
Subject: Re: Double Select Tag

Well, there are diferent options for this:
1) Load all the posibles values of the second select into javascript
arrays
when loading the page, and the populate the second select using
javascript
once the user has made a selection in the first select
2) Once the user has selected an element in the first select, navigate
to
present the same page, but with the second select also loaded.
3) Use Ajax to populate dinamically the second select retrieving the
data
from the server once the users selects one element on the first select.

You can write the javascript yourself, or use a toolkit like Dojo to
abstract yourself of that.

Depending on the amount of data, and the likelihood of changes in it, I
would use options 1 or 3, but it's up to you.

JL
------Mensaje original------
De: Jerson John
Para: 'Struts Users Mailing List'
Responder a: Struts Users Mailing List
Asunto: Double Select Tag
Enviado: 21 Feb, 2011 22:50

Hi,
  Can some one help me on double select tag with Hibernate...I am having
two
classes AssetCat,AssetSubCat and My first list should be assetcat list
and
according to the Assetcat selection I need to populate the second list
which
is assetsubcat list....Please advice me on this...I try to google it but
Only could find hardcoded string array stuff...Please advice me on
this..

Thanks in advance

Many Thanks and Regards,

Jerson




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Sent via BlackBerry from T-Mobile




Sent via BlackBerry from T-Mobile



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org


Internet communications are not secure and therefore Banco
Santander International does not accept legal responsibility for
the contents of this message. Any views or opinions presented
are solely those of the author and do not necessarily represent
those of Banco Santander International unless otherwise
specifically stated.

Las comunicaciones v'ia Internet no son seguras y, por lo tanto,
Banco Santander International no asume responsabilidad legal
ni de ning'un otro tipo por el contenido de este mensaje.
Cualquier opini'on transmitida pertenece 'unicamente al autor y
no necesariamente representa la opini'on de Banco Santander
International, a no ser que est'e expresamente detallado.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to