I'm trying to pass not only THIS but also a textbox to a javascript function. Based on which selection is made in the dropdown, the textbox which is just to the right of the dropdown is filled with the contents from another textbox on the page. There are
maybe 100 dropdown boxes with the same number of text boxes. Here's a sample:
The call to the function passes this ok, and I can access the dropdown. The value of the textbox is stored in tbox and I can access the value, but I don't know how to use it to access the textbox on the page and modify the contents. See below.
<script type="text/javascript">
function payees(ddinfo, tbox) {
var cbbroker = document.getElementById('<%=cbbroker.ClientID%>');
var txtbroker = document.getElementById('<%=txtbroker.ClientID%>').value;
if ((cbbroker.checked == true) && (txtbroker.length > 0)) {
var SelectElement = document.getElementById(ddinfo.id);
//var SelectElement = document.getElementById('<%=Dddiscountpaidto.ClientID%>');
var selecteditem = SelectElement.options[SelectElement.selectedIndex].value;
var text = SelectElement.options[SelectElement.selectedIndex].text;
if (text == "Broker") {
console.log("Selected item loandiscount: " + selecteditem);
document.getElementById(tbox.id).value = txtbroker;
} else if (text == "-Select-") {
;
document.getElementById(tbox.id).value = "";
}
}
}
</script>
The tbox variable hold the name of the textbox which needs to get populated.
I don't know how to make this work syntactically. How does one extract the contents and use it in conjunction with :
Accroding to your description,I don't understand your requirment clearly.Do you need to combine to use javascript and pass parameter?
I have created a test like this:
function payees(ddinfo, tbox) {
var ddinfo = document.getElementById('<%=Dddiscountpaidto.ClientID%>');
var tbox = document.getElementById('<%=txtdiscountpayee.ClientID%>');
var cbbroker = document.getElementById('<%=cbbroker.ClientID%>');
var txtbroker = document.getElementById('<%=txtbroker.ClientID%>').value;
if ((cbbroker.checked == true) && (txtbroker.length > 0)) {
//var SelectElement = document.getElementById(ddinfo.id);
var SelectElement = ddinfo;
var selecteditem = SelectElement.options[SelectElement.selectedIndex].value;
var text = SelectElement.options[SelectElement.selectedIndex].text;
if (text == "Broker") {
console.log("Selected item loandiscount: " + selecteditem);
tbox.value = txtbroker;
} else if (text == "-Select-") {
tbox.value = "";
}
}
}
<asp:DropDownList runat="server" ID="Dddiscountpaidto" onchange="payees()">
<asp:ListItem Value="0" Text="-Select-"></asp:ListItem>
<asp:ListItem Value="1" Text="Broker"></asp:ListItem>
<asp:ListItem Value="2" Text="Broker Affiliate"></asp:ListItem>
<asp:ListItem Value="3" Text="Lender"></asp:ListItem>
<asp:ListItem Value="4" Text="Lender Affiliate"></asp:ListItem>
</asp:DropDownList>
<asp:TextBox runat="server" ID="txtdiscountpayee" />
<asp:CheckBox runat="server" Checked="true" ID="cbbroker"/>
<asp:TextBox runat="server" ID="txtbroker" Text="Test" />
Result:
Best regards,
Yijing Sun
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Thanks for your help on it Bruce and passing the ClientID is the preferred method so I don't have to hard code every single textbox I'm trying to change into the function. I'm able to get this below into my debugger so the tbox is there holding the ClientID.
The problem is getting this line to work: document.getElementById("'" + tbox + "'").value = txtbroker;
Accroding to your description and codes,it's problem is cann't find the control. When you write a change function in the dropdownlist, the server side will identify payees(this, '<%=txtdiscountpayee.ClientID%>') as a string. And txtdiscountpayee.ClientID
will be passed to tboxId. So, you cann't find contorl id as txtdiscountpayee.ClientID. I suggest you add ClientIDMode="Static" and pass txtdiscountpayee instead of txtdiscountpayee.ClientID.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
246 Points
1307 Posts
Passing more than 1 parameter
Nov 28, 2020 08:29 PM|sking|LINK
I'm trying to pass not only THIS but also a textbox to a javascript function. Based on which selection is made in the dropdown, the textbox which is just to the right of the dropdown is filled with the contents from another textbox on the page. There are maybe 100 dropdown boxes with the same number of text boxes. Here's a sample:
<asp:DropDownList ID="Dddiscountpaidto" runat="server" onchange="payees(this, txtdiscountpayee)">
<asp:ListItem Value="0" Text="-Select-" Selected="True"></asp:ListItem>
<asp:ListItem Value="1" Text="Broker"></asp:ListItem>
<asp:ListItem Value="2" Text="Broker Affiliate"></asp:ListItem>
<asp:ListItem Value="3" Text="Lender"></asp:ListItem>
<asp:ListItem Value="4" Text="Lender Affiliate"></asp:ListItem>
<asp:ListItem Value="5" Text="Investor"></asp:ListItem>
<asp:ListItem Value="6" Text="Affiliate"></asp:ListItem>
<asp:ListItem Value="7" Text="Other"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="txtdiscountpayee" runat="server" Width="165" MaxLength="25"></asp:TextBox>
The call to the function passes this ok, and I can access the dropdown. The value of the textbox is stored in tbox and I can access the value, but I don't know how to use it to access the textbox on the page and modify the contents. See below.
The tbox variable hold the name of the textbox which needs to get populated.
I don't know how to make this work syntactically. How does one extract the contents and use it in conjunction with :
document.getElementById('<%="'" + tbox + "'".clientid%>').value = txtbroker;
document.getElementById('<%=txtdiscountpayee.ClientID%>').value = txtbroker;
California Mortgage | California refinance
Contributor
3390 Points
1284 Posts
Re: Passing more than 1 parameter
Nov 30, 2020 08:08 AM|yij sun|LINK
Hi sking,
Accroding to your description,I don't understand your requirment clearly.Do you need to combine to use javascript and pass parameter?
I have created a test like this:
Result:
Best regards,
Yijing Sun
All-Star
57864 Points
15491 Posts
Re: Passing more than 1 parameter
Nov 30, 2020 05:05 PM|bruce (sqlwork.com)|LINK
you should pass the id, rather than variable name:
<asp:DropDownList ID="Dddiscountpaidto" runat="server" onchange="payees(this, '<%=txtdiscountpayee.ClientID%>')">
then lookup the element:
Member
246 Points
1307 Posts
Re: Passing more than 1 parameter
Dec 01, 2020 02:59 AM|sking|LINK
Thanks for your help on it Bruce and passing the ClientID is the preferred method so I don't have to hard code every single textbox I'm trying to change into the function. I'm able to get this below into my debugger so the tbox is there holding the ClientID. The problem is getting this line to work: document.getElementById("'" + tbox + "'").value = txtbroker;
Dropdown info ID: ctl00_ContentPlaceHolder2_Dddiscountpaidto
fees.aspx:27 Selected item loandiscount: 1
fees.aspx:30 textbox: <%=txtdiscountpayee.ClientID%>
Uncaught TypeError: Cannot set property 'value' of null
at payees (fees.aspx:31)
California Mortgage | California refinance
Contributor
3390 Points
1284 Posts
Re: Passing more than 1 parameter
Dec 02, 2020 08:48 AM|yij sun|LINK
Hi sking,
Accroding to your description and codes,it's problem is cann't find the control. When you write a change function in the dropdownlist, the server side will identify payees(this, '<%=txtdiscountpayee.ClientID%>') as a string. And txtdiscountpayee.ClientID will be passed to tboxId. So, you cann't find contorl id as txtdiscountpayee.ClientID. I suggest you add ClientIDMode="Static" and pass txtdiscountpayee instead of txtdiscountpayee.ClientID.
Just like this:
Best regards,
Yijing Sun
Member
246 Points
1307 Posts
Re: Passing more than 1 parameter
Dec 02, 2020 01:50 PM|sking|LINK
Thanks! Got it working now.
California Mortgage | California refinance