function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DeepikareddyDeepikareddy 

How to pass the id of Selectlist value to the Javascript in Salesforce

Do anyone have idea to pass the Selectlist value to the Javascript in Salesforce using Document.Element.id .

i need to get the selected value as an alert ;;
 Please let me know how can i get the values , using the javascript Element.id Only

Or provide useful links will go through it .. 
<apex:page id="pg" >
  
 <apex:form id="frm">
 
 <script>
      
      function  getvalue(){
        alert("hi");
       var selectedvalue =document.getElementById("pg:frm:otptpanel:selectlist").value; 
       alert(selectedvalue);
      }
     
      </script>
  <apex:outputPanel id="otptpanel" >
   
    <apex:selectList id="selectedval" size="1" onchange="getvalue()"> 
   <apex:selectOption itemLabel="Hyderbad" itemValue="Hyd"/>
     <apex:selectOption itemLabel="Banglore" itemValue="Ban"/> 
      <apex:selectOption itemLabel="Chennai" itemValue="Che"/>  
    
   </apex:selectList>
  
      </apex:outputPanel>
  
   
 
 
 </apex:form>
 
</apex:page>

using the Javascript Element only .. 
Thanks
Deepika
 
Best Answer chosen by Deepikareddy
Maharajan CMaharajan C
Hi Deepika:

Use the below changes in JS:

var selectedvalue =document.getElementById("pg:frm:selectedval").value; 
alert(selectedvalue);

Thanks,
Maharajan.C


 

All Answers

Maharajan CMaharajan C
Hi Deepika:

Use the below changes in JS:

var selectedvalue =document.getElementById("pg:frm:selectedval").value; 
alert(selectedvalue);

Thanks,
Maharajan.C


 
This was selected as the best answer
DeepikareddyDeepikareddy
Thank u Maharajan..!