Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Initializing a dropdown menu

Posted on 1999-01-27
9
Medium Priority
?
154 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
Industry Leaders: 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 40 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

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.

Question has a verified solution.

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

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.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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…
Suggested Courses

810 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