+ Start a Discussion
JamesSSJamesSS 

How to throw the error alert?

My code:
Class:

public class Jserrors{
public list<Selectoption> Performance{set; get;}
public Jserrors(){
Performance = pick();
}
public list<SelectOption> pick(){

op.add(new selectOption('Prospect','Prospect');
op.add(new selectOption('Customer-Direct','Customer-Direct');
op.add(new selectOption('Other','Other');
return op;
}
}

VF code:
<apex:page controller="Jserrors">
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" />
<script>
$(function($) {
<script>
function save(){
$('.Radios').find('input:radio').each(function(){
alert("please select atleast one");
});
}
</script>
});
});
</script>
<apex:form >
<div>
<div style = "margin-bottom:10px;">Radios</div>
<div>
<apex:selectRadio layout="pageDirection" id = "radios" styleClass="Radios">
<apex:selectOptions value="{!Performance}"></apex:selectOptions>
</apex:selectRadio>
<button onclick = "save();">Save</button>
</div>
</div>
</apex:form>
</apex:page>

How to throw the alert error when I didn't select any one of the radio in clicking the save buuton?

souvik9086souvik9086

Try this

 

<apex:SelectRadio value="{!selectedValue}" layout="pageDirection" id = "radios" styleClass="Radios">
<apex:selectOptions value="{!Performance}"></apex:selectOptions>
</apex:SelectRadio>

 

Here selectedValue can be a string.

You can check in the javascript whether that value is blank and then display the alert.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

JamesSSJamesSS

I need to check this value in inside of javascript only.Is it possible?

sfdcfoxsfdcfox
Use the onChange event of apex:selectRadio. When the value changes, your JavaScript will execute.