We hope you'll join us for our 4/23 webinar on using data tables to apply reference ranges and AE codes in OC4. For more information and to register, visit https://register.gotowebinar.com/register/2882170018956684555

Accessing selected value from codelist

I have a requirement to produce a concatenated field based upon the code from a single-select drop-down list and a text field (i.e. 001-1234, where '001' is the code of the selected item in the codelist, and '1234' is the value form the text field).  I am able to concatenate the contents of two text fields, but I am having problems accessing the selected value from a single-select drop-down list

The code I am to using to (try to!) get the codelist value is given below.  Item "#SiteCodeList" is the code list itself, and "#SiteCodeNumber" is a second item into which I'm trying to copy the selected value from the code list.

I think the problem is with the line "var siteCodeNo = siteCodeList.val();".  Because this item is a drop-down list (rather than a text item), then I assume I need to use a different way to extract the value of the selected code.  However, after many attempts & much googling, I still haven't found a working solution.

Any help will be gratefully received...

<script src="includes/jmesa/jquery.min.js">// for OC versions before 3.1.4, use jquery-1.3.2.min.js !</script>
<div id="SiteCodeList"></div>
jQuery(document).ready(function($) {
var siteCodeList = $("#SiteCodeList").parent().parent().find("input");
var siteCodeNumber = $("#SiteCodeNumber").parent().parent().find("input");
siteCodeNumber.attr("readonly", true);
function getSiteCodeNo(){
 var siteCodeNo = siteCodeList.val();
 if (siteCodeNumber.val() != siteCodeNo){
siteCodeList.click(function() {


  • lindsay.stevenslindsay.stevens Posts: 404 ✭✭✭
    via Email
    .val() gets you the element value. if you're after the selected option's
    coded value which is stored in the option's attribute called 'value'. so I
    suppose you could try something like: siteCodeList.attr("value")

    anyway, i think the actual problem is that the selector you've got var
    siteCodeList is .find("input") however the dropdown element type is not
    'input', it is 'select'.
  • billingibillingi Posts: 28

    Thanks for your feedback.  I tried your suggestions, but I still haven't got it to work yet!  I'll keep trying, as it must be possible...

  • adridderadridder Posts: 38
    via Email
    Hi Ian,

    I think in this bit of code:
    siteCodeList.click(function() {

    You're missing the terminating ")"

    siteCodeList.click(function() {

  • billingibillingi Posts: 28
    Thanks for all of the feedback.  Everything is now working as a result of the following changes:

    * Use find("select") to get the selector for the drop-down list
    * [Scientifically!] inserting the missing ')' and semi-colons until the code was syntactically correct.

    However, I was still able to use .val() to get the selected value from the drop-down list.  It seems either way works.
This discussion has been closed.