wood burning stoves 2.0*
The moose likes Portals and Portlets and the fly likes javascript for select box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "javascript for select box " Watch "javascript for select box " New topic
Author

javascript for select box

Ashita Singh
Greenhorn

Joined: Aug 14, 2008
Posts: 8
I have a javascript question. I have a drop down box. And after I display the results of the selected option, I want it to continue to show the selected menu item. Say, I selected "Complete" from my select box. I display the results of the "complete" option. But then the select box option goes back to "All" and I want it to stay at "Complete" because I am showing results from "Complete" option.
Ashita Singh
Greenhorn

Joined: Aug 14, 2008
Posts: 8
here's a code snippet:

<form >
Show only:
<select id="filter" name="filter" size="1">
<option value="All">All</option>
<option value="Complete">Complete</option>
<option value="Expired">Expired</option>
<option value="Entered">Entered</option>
<option value="Open">Open</option>
</select>
<input type=button on click=searchOrdersByStatus() value="Go">
<br><br>
</form>

function searchOrdersByStatus()
{
//var passFilter = '<%=request.getParameter("filter")!=null?request.getParameter("filter"):"null"%>';

var passFilter = document.getElementsByName('filter')[0].value;
alert("pt.1 : " + passFilter);

var len = document.myForm.filter.length;
alert("pt.2 : " + passFilter);
for(var x=0;x<len;x++)
{
if(document.myForm.filter.options[x].value== passFilter)
{
alert("pt. 3 : " + document.myForm.filter.options[x].value)
passFilter2 = document.myForm.filter.options[x].value;

alert("pt. 4 : " + passFilter2)
document.myForm.filter.options[x].value.selected=true;
}
}
$('#dperrmsgdiv').load('https://${pageContext.request.serverName}/orders/jsp/processing.jsp');
var reqstr="https://${pageContext.request.serverName}/orders/s2/orderstatus?accountId="+ acntid+"&filter=" + passFilter2;
$('#dpdiv').load(reqstr);
}
Santhosh Kumar
Ranch Hand

Joined: Nov 07, 2000
Posts: 242
While generating the html, include "selected" keyword for the option which you want to be selected by default. For ex.,

Ashita Singh
Greenhorn

Joined: Aug 14, 2008
Posts: 8
yes. But after i display the results of "Complete" orders, i want the drop down box to continue to show "Complete" and not "All". The current code that I have shows complete orders resultset but in dropdown it goes back to "All"
Ashita Singh
Greenhorn

Joined: Aug 14, 2008
Posts: 8
I thought by making the foll in javascript function:

document.myForm.filter.options[x].value.selected=true;

I would be able to but it's not happening. It still shows results of "Complete" but in drop down it goes back to "All"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Originally posted by Ashita Singh:
I thought by making the foll in javascript function:


Please use real words when posting to the forums. Abbreviations such as "foll" in place of "following" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Be sure that you are not setting the select attribute to true for more than one of the select element's options. that only makes sense if the element is marked as multiple.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript for select box
 
Similar Threads
Changing options(contents) of a select element in Struts' jsp form
Retrieving list of values from select box using javascript
how to access combo-box value in javascript?
I want to fill a Listbox with values dynamically using JSP when I press a button
Select box get refresh after populating the data into a table.