Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript for select box

 
Ashita Singh
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 242
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While generating the html, include "selected" keyword for the option which you want to be selected by default. For ex.,

 
Ashita Singh
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic