Solved

Initializing a dropdown menu

Posted on 1999-01-27
9
144 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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…

706 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

16 Experts available now in Live!

Get 1:1 Help Now