Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Drop Down

Posted on 2002-05-19
8
Medium Priority
?
230 Views
Last Modified: 2010-04-01
I would like to allow the user to select an option from a drop down and have it cause the information displayed on the page to change without have to have them press any submit buttons.  Is this possible.  I tried using onchange and the other on´s but got know where with it.

Thanks
0
Comment
Question by:menreeq
8 Comments
 
LVL 6

Expert Comment

by:kotan
ID: 7020671
Try this,

<script>
function goTo(val) {
 location.href="yourJspPage.jsp?parameter="+val;
}
</script>

In table:
<td>
<select name="selectOptions" onchange="goTo(this.options[this.selectedIndex].value)">
             <option value="option 1">option1</option>
             <option value="option 2">option2</option>
             <option value="option 3">option 3</option>
           </select>
            &nbsp; View Option &nbsp;
</td>
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 300 total points
ID: 7021652
if you want to change text without reloading try:

<SCRIPT LANGUAGE="JavaScript">
function updateText(optionValue) {
    text = "This is your initial display.'"
    if (optionValue == 1) {
         text = "Text if 1 is selected."
    }
    else if (optionValue == 2) {
         text = "Text if 2 is selected."
    }
    else if (optionValue == 2) {
         text = "Text if 3 is selected."
    }

    document.all("MyID1").innerText = text;
}
</SCRIPT>

<P ID="MyID1">This is your initial display.</P>

<FORM><select name="updateText" onchange="updateText(this.options[this.selectedIndex].value)">
            <option value=1>option1</option>
            <option value=2>option2</option>
            <option value=3>option 3</option>
          </select>
</FORM>


HTH,
CJ
0
 

Author Comment

by:menreeq
ID: 7021771
Great, but I am pulling the different options from a bean...so i want to refresh the page and call the options from the bean how would i go about that? can i insert the call to the bean from within the script tags?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:cheekycj
ID: 7021787
Like this:

I am assuming your bean is a collection or an arraylist:
<select name="selectOptions" onchange="goTo(this.options[this.selectedIndex].value)">
   <% for (int i = 0; i < yourBean.size(); i++) {
            String value = (String) yourBean.get(i); %>
            <option value="<%=value%>">Option <%i+1%></option>
   <% } %>
          </select>
0
 

Author Comment

by:menreeq
ID: 7036883
I have it to the point that i have a submit query button that calls my bean and populates the fields corresponding to the selection selected.  Using your suggestions i made a javascript function that does a click() for that submit querry button, i also have it as style:display-none to make the button not appear.  It works but i don´t like the fact that the page has to reload since the button submits the information to a servlet that then calls the bean....should i be able to change the information in the input boxes without having to submit the form(i am using input boxes because i want the user to be able to edit the data)?  If so how?  
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7037537
you would have to have your servlet retrieve all the info and store it in JavaScript vars to be able to  update the page without reloading.
0
 

Expert Comment

by:mark_at_serialmonkey
ID: 7038339
If you didn't want the whole page to refresh you could write a servlet that just returns the parameters from your bean and hide it in a hidden frame. Then use DHTML to update the options. You may have trouble working this with IE and Netscape though (but the solution given by cheekycj above wouldn't work in Netscape either since it doesn't support innerText calls (at least V4 Netscape doesn't anyway as far as I know)
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7044583
Glad I could help, Thanx for the "A"
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In this article, the configuration steps in Zabbix to monitor devices via SNMP will be discussed with some real examples on Cisco Router/Switch, Catalyst Switch, NAS Synology device.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question