Solved

Initializing a dropdown menu

Posted on 1999-01-27
9
147 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

770 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