Hi,
I am using the following code to select a customer on a form. It's working, it captures the Customer_ID and displays the Customer Name in the HTMLDROPDOWN control. When a customer selection is made, how can I also capture the Last_Name + First_Name value and plug it into another field on the same form? Like an OnClick() function that sets the Customer_Name field = Last_Name + First_Name?
<%= HtmlDropDown("Customer_ID",poRO.Customer_ID,"tCustomers","Customer_ID","Last_Name + [(] + First_Name + [)]",[class="form-control"],"--- Select a Customer","") %>
TIA,
Steve
You can't directly capture anything but the Value from an Html Text control in a POST operation.
However, you can do this with JavaScript as you pointed out. If you want to use JavaScript you can do the following:
- Capture the
onchangeevent on the combo - Capture whatever value you need to catch by looking at the ComboBox Html (ie.
$("#comboBox>option[value='<selectedValue>']").text()) - Write the value into a hidden form variable ie.
<input type="hidden" value="captured text" />
You can get the captured text with something like this:
// Grab the selected value
var value = $("#Forum").val();
// Get the prompt text
var selectedText = $("#Forum>option[value='" + value + "']").text()
// Assign to a hidden variable that posts back
$("#hiddenCaption").val(selectedText)
However, I'd advise against that - while that works it's pretty messy and can have weird side effects if there are certain characters in the label string.
You should be able to do the co-relation on the server where the prompt originated in the first place and capture it there.
+++ Rick ---