Solved

Initializing a dropdown menu

Posted on 1999-01-27
9
145 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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…
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now