You need to sign in to do that
Don't have an account?
stcforce
select option based execution of javascript.
I need to be able to execute some Javascript based on the selection of an option from a select list, however have found that the onselect as offered with vforce doesn't work. nb. i can't use onchange because the selection is supposed to navigate to antoher page. I would appreciate any help anyone is able to give. thank you.
<apex:selectListvalue="{!fUpdateCurrent.Object__c}"multiselect="false" onselect="alert('select'); size="1"id="theopl">
<apex:selectOptionsvalue="{!objectPicks}"/>
</apex:selectList>
Hi,
Try the below code snippet as reference:
<apex:page id="p1" controller="Page13">
<script>
var x='';
var t=new Array();
</script>
<apex:form id="f1">
<apex:pageBlock id="pb1">
<apex:pageblockSection id="pbs1" >
<apex:selectList id="pl1" value="{!countries}" multiselect="false" onclick="check()">
<apex:selectOptions value="{!items}"/>
</apex:selectList>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
<script>
function check()
{
var k,l=0,z;
x = (document.getElementById('p1:f1:pb1:pbs1:pl1').value);
alert(x);
var y = document.getElementById('p1:f1:pb1:pbs1:pl1');
//alert(y.options[3].text);
}
</script>
</apex:page>
public class Page13 {
String[] countries = new String[]{};
public String[] getCountries() {
return countries;
}
public void setCountries(String[] countries) {
this.countries = countries;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
options.add(new SelectOption('CHINA','China'));
options.add(new SelectOption('LONDON','London'));
return options;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Do you really need to do it in JS?
you can do it without coding a single javascript. here's a sample:
The VF page
The controller: