Solved

Initializing a dropdown menu

Posted on 1999-01-27
9
150 Views
Last Modified: 2010-04-09
In a dropdown menu (ie ComboBox) The initial value is based upon the user selection from the previous page ( Menu already has that value)  and I have to initialize that value to the menu.
help me to do that one
0
Comment
Question by:jimevans
[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
  • 5
  • 4
9 Comments
 
LVL 4

Expert Comment

by:martinag
ID: 1845734
How do you get to the second page? A link?
Here's the general idea:
Page 1:
<FORM NAME="thatForm">
<SELECT NAME="thatList">
<OPTION>1
<OPTION>2
<OPTION>3
<OPTION>4
</SELECT>
</FORM>
<A HREF="javascript:location.href='page2b.htm?listIndex='+document.thatForm.thatList.selectedIndex">Page 2</A>

Page 2:
Between <HEAD> and </HEAD>:
<SCRIPT LANGUAGE="JavaScript">
<!--
if (location.search && location.search.length > 1) {
  // We've got something to split.

  // Remove ?
  query = location.search.substring(1);

  // Split at &

  containsAmp = 1;
  while (query.indexOf('&') != -1) {
    nameValue = query.substring(0, query.indexOf('&'));
    split(nameValue);
    query = query.substring(query.indexOf('&')+1);
    containsAmp = 0;
  }
  split(query.substring(query.indexOf('&')));

  if (containsAmp) {
    split(query);
  }
}
function split(nameValue) {
    if (nameValue.indexOf('=') != -1) {
      Name = nameValue.substring(0, nameValue.indexOf('='));
      Value = nameValue.substring(Name.length+1);
      Name = Name.substring(0,1).toUpperCase() + Name.substring(1);
      eval("var" + Name + " = '" + Value + "'");
    }
}
document.thatForm.thatList.listIndex=((self.varListIndex)?varListIndex:0)
// -->
</SCRIPT>

<BODY> tag:
<BODY onLoad="document.thatForm.thatList.selectedIndex=((self.varListIndex)?parseInt(varListIndex):0)">

Martin
0
 

Author Comment

by:jimevans
ID: 1845735
Hi Martinag
     your assumptions are almost correct but I am not passing the index I am passing the selected string itself. I have used "this.options.[this.options.SelectedIndex].value"  to get the value and Passing it exacly in the same way you have assumed.
Waiting for a more detailed explnation from you
thankyou

 
0
 
LVL 4

Expert Comment

by:martinag
ID: 1845736
Ok, here's the new version.
Page 1:
<FORM NAME="thatForm">
<SELECT NAME="thatList">
<OPTION>1
<OPTION>2
<OPTION>3
<OPTION>4
</SELECT>
</FORM>
<A HREF="javascript:l=document.thatForm.thatList;location.href='test107b.htm?select='+escape(l.options[l.selectedIndex].value)">Page 2</A>

Page 2:
<SCRIPT LANGUAGE="JavaScript">
<!--
if (location.search && location.search.length > 1) {
  query = location.search.substring(1);
  containsAmp = 1;
  while (query.indexOf('&') != -1) {
    nameValue = query.substring(0, query.indexOf('&'));
    split(nameValue);
    query = query.substring(query.indexOf('&')+1);
    containsAmp = 0;
  }
  split(query.substring(query.indexOf('&')));

  if (containsAmp) {
    split(query);
  }
}
function split(nameValue) {
    if (nameValue.indexOf('=') != -1) {
      Name = nameValue.substring(0, nameValue.indexOf('='));
      Value = nameValue.substring(Name.length+1);
      Name = Name.substring(0,1).toUpperCase() + Name.substring(1);
      eval("var" + Name + " = '" + Value + "'");
    }
}

function selectList() {
  if (!self.varSelect) return;
  s = varSelect;
  l = document.thatForm.thatList;
  for (i=0;i<l.options.length;i++)
    if (l.options[i].value == s)
      l.selectedIndex = i;
}
// -->
</SCRIPT>
<BODY onLoad="selectList()">

<FORM NAME="thatForm">
<SELECT NAME="thatList">
<OPTION>1
<OPTION>2
<OPTION>3
<OPTION>4
</SELECT>
</FORM>

Martin
0
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!

 

Author Comment

by:jimevans
ID: 1845737
Hi Martinag
    I tried using your code. but it didn't work.
I am working on a asp file and it is not calling the OnLoad function
Plase clarify
0
 
LVL 4

Expert Comment

by:martinag
ID: 1845738
Remove the onLoad and the selectList function. Put this after the listbox:
<SCRIPT LANGUAGE="JavaScript">
<!--
if (!self.varSelect) return;
 s = varSelect;
 l = document.thatForm.thatList;
 for (i=0;i<l.options.length;i++)
   if (l.options[i].value == s)
     l.selectedIndex = i;
// -->
</SCRIPT>

Martin
0
 

Author Comment

by:jimevans
ID: 1845739
Hi Martinag
     varSelect is undefined
      Sorry for disturbing you a lot.
      My URL has the value "xxxx.htm?Alphabet=a"
      Kindly tell me the way to extact that value in Javascript
Thanks a lot
0
 

Author Comment

by:jimevans
ID: 1845740
hi Martinag
I have finished the work.
Thanks for your  help



0
 
LVL 4

Accepted Solution

by:
martinag earned 10 total points
ID: 1845741
Great!
Here's an answer for you to grade.

Martin
0
 

Author Comment

by:jimevans
ID: 1845742
thanks Martinag
Great help you did to finish my assignment
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

740 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