Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
Hi,

I have one static dropdown. I need to change the value of dropdownon text change event.
The textbox(textPaid) and the drop down(ddlPaymentStatus) are placed inside a grid.
So, please give a javaScript solution to handle this.
 
Thanks in advance.
 

Eg: .if the amount is entered in text box() ,then the value in drop down() shld be changed as paid().. the static value of dropdown(open,paid, pending ,advance)
Posted 2-Dec-12 18:54pm
Edited 2-Dec-12 20:21pm
v4
Comments
Tadit Dash at 3-Dec-12 1:56am
   
Please post your codes by clicking on "Improve question" link.
aravindnass at 3-Dec-12 2:22am
   
.if the amount is entered in text box() ,then the value in drop down() shld be changed as paid()..here is the static value of dropdown <asp:ListItem Value="4">--Select-- <asp:ListItem Value="0">Open <asp:ListItem Value="1">Paid <asp:ListItem Value="2">Pending <asp:ListItem Value="3">Advance
Tadit Dash at 3-Dec-12 2:38am
   
So, what amount you will enter in the textbox.
Tell me how you want to select the dropdown. I mean what amount will make the dropdown to select the value "paid"?
aravindnass at 3-Dec-12 3:21am
   
if any value enter(on textbox) means it is paid and drop down will change paid..
aravindnass at 3-Dec-12 2:07am
   
haiii...tadit ..I have update my question ..plz see and give me a java script for dropdown changes based on text change in textbox
pradiprenushe at 3-Dec-12 2:18am
   
try my updated answer
pradiprenushe at 3-Dec-12 2:09am
   
Which value you want to select in dropdown? How to understand this.
aravindnass at 3-Dec-12 2:19am
   
heyy...if the amount is entered in text box() ,then the value in drop down() shld be changed as paid()..here is the static value of dropdown
 

 

<asp:ListItem Value="4">--Select--
<asp:ListItem Value="0">Open
<asp:ListItem Value="1">Paid
<asp:ListItem Value="2">Pending
<asp:ListItem Value="3">Advance
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I worked this out for you. Take a look at the code.
 
JavaScript code
<script type="text/javascript">
 
// Function is used to select the DropDown Paid value 
// if textbox contains any value.
function SelectPaidValue() {
 
      // Get the controls.
      var textPaid = document.getElementById('<%=textPaid.ClientID%>');
      var ddlPaymentStatus = document.getElementById("<%=ddlPaymentStatus.ClientID %>");
 
      // Check if data is there in textbox or not
      if (textPaid.value != "" && textPaid.value != null) {
          // If data is there select "Paid" from DropDownList.
          selectItemByValue(ddlPaymentStatus, 1);
      }
      else {
          // If data is not there, then select "--Select--" from DropDownList.
          selectItemByValue(ddlPaymentStatus, 4);
      }
}
 
// Function is used to select the DropDown option by value.
function selectItemByValue(elmnt, value) {
      // Loop through all the options and select the provided value.
      for (var i = 0; i < elmnt.options.length; i++) {
          if (elmnt.options[i].value == value)
               elmnt.selectedIndex = i;
          }
      }
 
</script>
aspx code
<asp:TextBox ID="textPaid" runat="server" onblur="SelectPaidValue()"></asp:TextBox>
<asp:DropDownList ID="ddlPaymentStatus" runat="server">
        <asp:ListItem Value="4">--Select--</asp:ListItem>
        <asp:ListItem Value="0">Open</asp:ListItem>
        <asp:ListItem Value="1">Paid</asp:ListItem>
        <asp:ListItem Value="2">Pending</asp:ListItem>
        <asp:ListItem Value="3">Advance</asp:ListItem>
</asp:DropDownList>
 
Thanks...
  Permalink  
v2
Comments
aravindnass at 3-Dec-12 5:59am
   
thanks a lot...dude...
Tadit Dash at 3-Dec-12 6:03am
   
Hi @aravindnass,
 
Please accept this answer and upvote, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...
 
Thanks,
Tadit
Tadit Dash at 4-Dec-12 1:31am
   
Hey you have not replied ?
Check my comment below.
Thanks...
aravindnass at 3-Dec-12 6:09am
   
the dropdown is placed inside a repeater..,How to get the element Id of dropdown...???
Tadit Dash at 3-Dec-12 6:35am
   
That's why I have written like "<%=ddlPaymentStatus.ClientID %>".
Are you facing issues in getting the dropdown with the current code ?
If yes, then tell me.
Tadit Dash at 4-Dec-12 2:23am
   
Hi @aravindnass,
 
Please accept this answer because you got the solution for your question.
We need to mark it as "Solved" so that it will not be in the "Unanswered question" list and it will help others also.
If you need any further help, add more question, we are here to help you. :)
 
Thanks,
Tadit
aravindnass at 4-Dec-12 5:41am
   
okkk.....tadit thankss..
Tadit Dash at 4-Dec-12 5:55am
   
Welcome... My Pleasure...
Thanks for accepting the answer...
 
Tadit.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this
 
 <script type="text/javascript">
        function SomeFunction() {
var txt= document.getElementById('<%=Test.ClientID%>');
if(txt.value !="")
{
            var x=document.getElementById("<%=dropdownid.ClientID %>");
x.selectedIndex =1;
}
        }
    </script>
 

<asp:TextBox ID="TextBox1" runat="server" onchange="SomeFunction()"></asp:TextBox>
  Permalink  
v3
Comments
aravindnass at 3-Dec-12 2:23am
   
.if the amount is entered in text box() ,then the value in drop down() shld be changed as paid()..here is the static value of dropdown <asp:ListItem Value="4">--Select-- <asp:ListItem Value="0">Open <asp:ListItem Value="1">Paid <asp:ListItem Value="2">Pending <asp:ListItem Value="3">Advance
pradiprenushe at 3-Dec-12 2:33am
   
try my update solution
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Solution is:
 protected void ddlPaymentStatus_SelectedIndexChanged(object sender, EventArgs e)
{
 
        DropDownList ddl = (DropDownList)sender;
        GridViewRow row = (GridViewRow)ddl.NamingContainer;
        int rowIndex = row.RowIndex;
        
        DropDownList DrpLocation1 = (DropDownList)row.FindControl("DrpLocation");
       
 
        TextBox textPaid1= (TextBox)row.FindControl("textPaid");
 
        textPaid1=DrpLocation1.text;
 
}

Please Accept if my answer is right.
  Permalink  
v2
Comments
aravindnass at 3-Dec-12 2:10am
   
heyy ...thanks for reply..
but what I need is change dropdown on textchange .plz give me javascript for thiss....
aravindnass at 3-Dec-12 2:23am
   
.if the amount is entered in text box() ,then the value in drop down() shld be changed as paid()..here is the static value of dropdown <asp:ListItem Value="4">--Select-- <asp:ListItem Value="0">Open <asp:ListItem Value="1">Paid <asp:ListItem Value="2">Pending <asp:ListItem Value="3">Advance
Arun1990 at 3-Dec-12 2:28am
   
you need to just change condition on my upper code:
if(textPaid1.text="What value";
DrpLocation1.text="paid";
 
there is no need of java script, use only asp.net code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 675
1 CPallini 320
2 Sergey Alexandrovich Kryukov 305
3 BillWoodruff 285
4 Peter Leow 255


Advertise | Privacy | Mobile
Web04 | 2.8.141029.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100