Solved

Drop Down

Posted on 2002-05-19
8
224 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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