Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile JavaScript Function to Detect a DropdownListItem

    I have one TextBox say txtBox1 followed by a DropdownList --ddl1 and another textBox2 below that.
    Now the user types a name into textBox1 and then selects one Item from the dropdown list.Now if the selected dropdownItem's index is 2 I want to copy textBox1.Text to TextBox2.Text. other wise TextBox2.text is to be cleared.

    Can some one urgently help me with a javascript function to do this ?Iam using asp.net with VB.net coding

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Go to the html view, and in the head put this:
    Code:
    <script type="text/javascript">
    function moveText(drop, index)
    {
    	var oDrop = document.getElementById(drop);
    	var txt1 = document.getElementById('TextBox1');
    	var txt2 = document.getElementById('TextBox2');
    	if(oDrop.selectedIndex == index)
    	{
    		txt2.value = txt1.value;
    	}
    	else
    	{
    		txt2.value = '';
    	}
    
    }
    </script>
    And now in your vb code you'll have to add the event, so in the page load put this:
    Code:
    ddl1.Attributes.Add("onChange", "moveText('ddl1', '2')")


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •