Solved

Drop Down

Posted on 2002-05-19
8
221 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 75 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now