Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Select Chosen Option in Menu

Posted on 2004-11-01
12
Medium Priority
?
2,532 Views
Last Modified: 2008-01-09
I have the following script set up so that one someone choses an option from a menu it passes through variables, but it does not "select" that option that was chosen. Here is my code so far:

<html>
<head>
<title>Test</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
   eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
   if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>

<body>
<form name="selectMonth">
<select name="menu" id="menu" onChange="MM_jumpMenu('self',this,1)">
<option value="monthcal.dll?BeginDate=10/1/04&EndDate=12/31/05">October 2004</option>
<option value="monthcal.dll?BeginDate=11/1/04&EndDate=12/31/05">November 2004</option>
<option value="monthcal.dll?BeginDate=12/1/04&EndDate=12/31/05">December 2004</option>
<option value="monthcal.dll?BeginDate=1/1/05&EndDate=12/31/05">Janurary 2005</option>
<option value="monthcal.dll?BeginDate=2/1/05&EndDate=12/31/05">February 2005</option>
</select>
</form>
</body>
</html>

Let's say someone choses November 2004. I want the November 2004 option to appear like:

<option value="monthcal.dll?BeginDate=11/1/04&EndDate=12/31/05" selected>November 2004</option>

I need to be able to do this with javascript only, if that is possible.
0
Comment
Question by:thecode101
[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
  • 7
  • 5
12 Comments
 
LVL 25

Expert Comment

by:devic
ID: 12465547
change the line:
<select name="menu" id="menu" onChange="MM_jumpMenu('self',this,1)">
to:
<select name="menu" id="menu" onChange="MM_jumpMenu('self',this,0)">
0
 
LVL 25

Expert Comment

by:devic
ID: 12465560
wait, you change location of the same page....
0
 
LVL 3

Author Comment

by:thecode101
ID: 12465644
That change did not work. Yes when an option is chosen it reloads the page with different variables passed through.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 25

Expert Comment

by:devic
ID: 12465677
ok, try this:
==================
<html>
<head>
<title>Test</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore)
{ //v3.0
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
}
function setDef()
{
      if(self.location.href.indexOf("?")!=-1)
      {
            alert(self.location.href.split("?")[1])
            document.selectMonth.menu.value="monthcal.dll?"+self.location.href.split("?")[1];
      }
}
//-->
</script>
</head>

<body onload=setDef();>
<form name="selectMonth">
<select name="menu" id="menu" onChange="MM_jumpMenu('self',this,1)">
<option value="monthcal.dll?BeginDate=10/1/04&EndDate=12/31/05">October 2004</option>
<option value="monthcal.dll?BeginDate=11/1/04&EndDate=12/31/05">November 2004</option>
<option value="monthcal.dll?BeginDate=12/1/04&EndDate=12/31/05">December 2004</option>
<option value="monthcal.dll?BeginDate=1/1/05&EndDate=12/31/05">Janurary 2005</option>
<option value="monthcal.dll?BeginDate=2/1/05&EndDate=12/31/05">February 2005</option>
</select>
</form>
</body>
</html>
0
 
LVL 3

Author Comment

by:thecode101
ID: 12465719
That did not work either. There is no problem with passing the variables. The problem is that when November is clicked that option needs to be selected when the page is reloaded. If December is clicked that option needs to be selected when the page is reloaded.
0
 
LVL 25

Expert Comment

by:devic
ID: 12465764
note you can not test this on your desktop, only on server:
if you want test it on desktop,

then change name of file to: test.html AND replace all monthcal.dll to test.html

EXAMPLE:

============= test.html ===============
<html>
<head>
<title>Test</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore)
{ //v3.0
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
}
function setDef()
{
      if(self.location.href.indexOf("?")!=-1)
      {
            document.selectMonth.menu.value="test.html?"+self.location.href.split("?")[1];
      }
}
//-->
</script>
</head>

<body onload=setDef();>
<form name="selectMonth">
<select name="menu" id="menu" onChange="MM_jumpMenu('self',this,1)">
<option value="test.html?BeginDate=10/1/04&EndDate=12/31/05">October 2004</option>
<option value="test.html?BeginDate=11/1/04&EndDate=12/31/05">November 2004</option>
<option value="test.html?BeginDate=12/1/04&EndDate=12/31/05">December 2004</option>
<option value="test.html?BeginDate=1/1/05&EndDate=12/31/05">Janurary 2005</option>
<option value="test.html?BeginDate=2/1/05&EndDate=12/31/05">February 2005</option>
</select>
</form>
</body>
</html>
0
 
LVL 3

Author Comment

by:thecode101
ID: 12465826
I am testing this on a server, and yes I renamed the page for testing purposes. It is not working. When the page is reloaded, and lets say for example December is chosen the html code should changed to:

<option value="test.html?BeginDate=12/1/04&EndDate=12/31/05" select>December 2004</option>

instead of

<option value="test.html?BeginDate=12/1/04&EndDate=12/31/05">December 2004</option>

So that December will be highlighted an appeared default selected.
0
 
LVL 25

Accepted Solution

by:
devic earned 2000 total points
ID: 12465916
ach, I got it, you need the color ;)

====================================
<html>
<head>
<title>Test</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore)
{ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
}
function setDef()
{
    if(self.location.href.indexOf("?")!=-1)
    {
        document.selectMonth.menu.focus();
            document.selectMonth.menu.value="test.html?"+self.location.href.split("?")[1];
    }
}
//-->
</script>
</head>

<body onload=setDef();>
<form name="selectMonth">
<select name="menu" id="menu" onChange="MM_jumpMenu('self',this,1)">
<option value="test.html?BeginDate=10/1/04&EndDate=12/31/05">October 2004</option>
<option value="test.html?BeginDate=11/1/04&EndDate=12/31/05">November 2004</option>
<option value="test.html?BeginDate=12/1/04&EndDate=12/31/05">December 2004</option>
<option value="test.html?BeginDate=1/1/05&EndDate=12/31/05">Janurary 2005</option>
<option value="test.html?BeginDate=2/1/05&EndDate=12/31/05">February 2005</option>
</select>
</form>
</body>
</html>
0
 
LVL 3

Author Comment

by:thecode101
ID: 12466011
Still not working, I am using Firefox 1.0 and IE 6.0. When you test it and chose an option, when the page reloads is that option you just selected the default option in the select menu?
0
 
LVL 25

Expert Comment

by:devic
ID: 12466212
http://home.arcor.de/athens/expexc/js/String/test.html

IE: selected
FireFox: selected without hilighting

and what do you see?
0
 
LVL 3

Author Comment

by:thecode101
ID: 12466344
Well yours worked and when I copied it exactly it worked for me. I don't know what I was doing wrong, but I am glad it is working. Thanks for your help.
0
 
LVL 25

Expert Comment

by:devic
ID: 12466367
thank you too!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

597 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