Solved

Drop Down

Posted on 2002-05-19
8
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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

Technology Partners: 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!

Question has a verified solution.

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

Getting to know the threat landscape in which DDoS has evolved, and making the right choice to get ourselves geared up to defend against  DDoS attacks effectively. Get the necessary preparation works done and focus on Doing the First Things Right.
This article is written by John Gates, CISSP. Gates, the SNUG President-Elect, currently holds the position of Manager of Information Systems at Lake Park High School in Roselle, Illinois.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 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