当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - onclick() event in dropdown list items

问题描述:

I have dropdown list label of "primary Carrier" which contains values for ex. Amazon, Waymart, Best-Buy and the values are coming from database and here is the condition I need to follow .. if primary carrier dropdown label is not "Amazon" then need to display some options.

Here is my code:

<m:td width="250"

onclick="javascript:flagWarn=false;javascript:datechanged=true;javascript:addeditrow('claimSearchForm1');">

<h:outputLabel for="primaryCarrier" value="Primary Carrier " />

<h:selectOneMenu id="primaryCarrier"

value="#{crossoverClaimDataBean.providerClaimVO.claimLineItemDetails.primaryCarrier}"

onchange="javascript:selectOne=true;" >

onclick=if(!amazon(this,'t1_options)

<f:selectItems value="#{crossoverClaimDataBean.primaryCarrierList}" />

</h:selectOneMenu>

<m:div sid="t1_options" styleclass="hide">

<h:outputLabel for="lname6"

value="Other Insured's Last Name" />

<h:outputLabel for="mi6" value="MI" />

Please let me know my approach is correct or not. If not please guide me.

网友答案:

You can do something like this,

<h:outputLabel id="primaryLabel" for="primaryCarrier" value="Primary Carrier"  />
<h:selectOneMenu id="primaryCarrier"
 value="#{crossoverClaimDataBean.providerClaimVO.claimLineItemDetails.primaryCarrier}"
 onchange="javascript:selectOne=true;"  >    
onclick=if(!amazon(this,'t1_options)

<f:selectItems value="#{crossoverClaimDataBean.primaryCarrierList}" />

And in your javascript,

document.onreadystatechange = function () {
  if (document.readyState == "complete") {
    //document is ready. Do your stuff here
    var labelValue = document.getElementById("primaryLabel").innerText;
     if(labelValue === 'Amazon'){

      } else {
         // Do the stuff here..
      }
    }
}

If you are using jQuery,

$( document ).ready(function() {
   var labelValue = $("#primaryLabel").text();
    if(labelValue === 'Amazon'){

    } else {
         // Do the stuff here..
    }
}); 

Hope this helps..

分享给朋友:
您可能感兴趣的文章:
随机阅读: