Web Analytics Made Easy -
StatCounter ASP.NET listbox and javascript - CodingForum

Announcement

Collapse
No announcement yet.

ASP.NET listbox and javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ASP.NET listbox and javascript

    actually what i want to do is that i have two list boxes. when i click any one one a particular item, the other listbox's same idex item should get highlighted too.. producing a list of listview effect ie. whenever an item is clicked on either of the listboxes, the sames index item on the other listbox will get highlighted too..
    to test this i made the below code to see how to integrate javascript in asp.NET

    i made a list box and added a javascript function to it
    i made the listbox
    <asp:listbox id="lstFilter" Runat="server"></asp:listbox>
    i added a javascript event to it on PageLoad
    lstFilter.Attributes.Add("onchange", "SelectPair(window.document.form1.lstFilter.options[selectedIndex].text);")
    then i wrote the javascript function :
    <script language="javascript">
    function SelectPair(window.document.form1.lstFilter.options[selectedIndex].text)
    {
    //lstvalue.select(
    window.document.Form1.lstFilter.options[selectedIndex].text = "hahahah"
    }
    </script>
    but nothing is working....can u pls help....
    tks a lot...

  • #2
    I personally would say use .NET to do this with a post back event and have it select the value.


    you javascript function is wrong that is why it is not working..

    when you pass an object or value, you do not repeat it in the function, instead you use a variable to do it

    Play with this and it should help you out.

    Code:
    <script>
      function SelectOther(D1,D2){
        document.f1[D2].selectedIndex = document.f1[D1].selectedIndex 
      }
    </script>
    
    
    
    <form name="f1">
      <select name="S1" onchange='SelectOther("S1","S2")'>
        <option># 1</option>
        <option># 2</option>
        <option># 3</option>
        <option># 4</option>
        <option># 5</option>
        <option># 6</option>
        </select>
      <select name="S2" onchange='SelectOther("S2","S1")'>
        <option># 1</option>
        <option># 2</option>
        <option># 3</option>
        <option># 4</option>
        <option># 5</option>
        <option># 6</option>
      </select>
    </form>
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

    Comment


    • #3
      ...or simply this:

      <select name="S1" onchange="this.form.S2.selectedIndex=this.selectedIndex">
      ...
      <select name="S2" onchange="this.form.S1.selectedIndex=this.selectedIndex">
      Glenn
      vBulletin Mods That Rock!

      Comment

      Working...
      X