on 22/08/2001 05:26, Dinesh Somasundram at [EMAIL PROTECTED] wrote:

> Hi All,
>
> With regards to my previous question about City, State and Country (which is
> way off the JSP topic), Mio-Nino P. Marquez pointed me to
> http://www.devshed.com/Server_Side/MySQL/JS_Arrays/. This is a PHP and MySQL
> combination. Something that I was quite good at, before jumping off to JSP.
>
> Kevin Duffy gave some very interesting insights about using Arrays instead
> of Vectors.
>
> But all still boils down to generating a JavaScript. Which lead me to my
> next question?
>
> How do I generate a JavaScript file from within my JSP on-the-fly? Any
> sample is deeply appreciated.
>
> Thanx,
> Dinesh, S.

This will not do a JavaScript on the fly but will create a new HTML OPTION
list for a SELECT in JavaScript (on the fly)

//*********** JavaScript code

arry[0] = new Array('Item1','Item2','Item3');
arry[1] = new Array('Item4','Item5','Item6');

function setOptions(thisArry) {
  yourForm.yourSelect.length=arry[thisArry].length+1;
  for (i=0;i<arry[thisArry].length;i++) {
    nuOption = new Option(arry[thisArry][i], arry[thisArry][i],false,false)
;
        yourForm.yourSelect.options[i+1]=nuOption;
    }
}

//*********** HTML
.
.
........<form id="yourForm">
            <select id="yourSelect"></select>


//***********

When you call "setOptions(0)" your select list will read Item1, Item2,
Item3.  Calling "setOptions(1)" your select list will read Item4, Item5,
Item6.  There is a better way to do all of this using DOM (which would be a
way to do the Javascript on the fly via XML) but earlier browsers like
Netscape 4.x do not support DOM.  BTW you can set the "false" to true and
the item will be the selected Item.

HTH

//*
Steven Elliott      <[EMAIL PROTECTED]
Head of Technology
VTV Learning Corporation
         Los Angeles  -  Boston  -  Lisbon
           http://www.vtvlearning.com/

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to