You need to sign in to do that
Don't have an account?
can't able to validate by using jquery
<apex:page>
<script type="text/javascript">
jQuery=$.noConflict();
function fnredirect(){
var widgetname = jQuery(".widgetname").val();
reg_sku=/^([a-zA-Z0-9\_\:\-\ ])+$/;
alert('widgetname');
if(widgetname == '')
{
alert('Please enter a widget Name');
jquery(".widgetname").focus();
return false;
}
}
</script>
<apex:commandButton value="Save" action="{!Save}" onclick="fnredirect();" />
<apex:pageblockSectionItem >
<apex:outputLabel value="Widget Name"></apex:outputLabel>
<apex:inputfield value="{!element.Name}" styleclass="widgetname" id="widgetname" />
</apex:pageblockSectionItem>
</apex:page>
But I cant get alert when I click on save button
Try Including the Jquery library file in your VF Page.
I have Included the Jquery Library file in Static Resources and am callingt it on page using <apex:Includescript> Tag Below Code works for me.
<apex:page >
<apex:includeScript value="{!URLFOR($Resource.App_Resource1,'lib/js/jquery144min.js')}"/>
<script type="text/javascript">
$jQuery = jQuery.noConflict();
function fnredirect(){
var widgetname = $jQuery(".widgetname").val();
reg_sku=/^([a-zA-Z0-9\_\:\-\ ])+$/;
alert('widgetname');
if(widgetname == '')
{
alert('Please enter a widget Name');
$jQuery(".widgetname").focus();
return false;
}
}
</script>
<apex:form >
<apex:commandButton value="Save" action="{!Save}" onclick="fnredirect();" reRender="dummy" />
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageblockSectionItem >
<apex:outputLabel value="Widget Name"></apex:outputLabel>
<!-- <apex:inputfield value="{!element.Name}" styleclass="widgetname" id="widgetname" />-->
</apex:pageblockSectionItem></apex:pageBlockSection></apex:pageBlock></apex:form>
</apex:page>
All Answers
Try Including the Jquery library file in your VF Page.
I have Included the Jquery Library file in Static Resources and am callingt it on page using <apex:Includescript> Tag Below Code works for me.
<apex:page >
<apex:includeScript value="{!URLFOR($Resource.App_Resource1,'lib/js/jquery144min.js')}"/>
<script type="text/javascript">
$jQuery = jQuery.noConflict();
function fnredirect(){
var widgetname = $jQuery(".widgetname").val();
reg_sku=/^([a-zA-Z0-9\_\:\-\ ])+$/;
alert('widgetname');
if(widgetname == '')
{
alert('Please enter a widget Name');
$jQuery(".widgetname").focus();
return false;
}
}
</script>
<apex:form >
<apex:commandButton value="Save" action="{!Save}" onclick="fnredirect();" reRender="dummy" />
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageblockSectionItem >
<apex:outputLabel value="Widget Name"></apex:outputLabel>
<!-- <apex:inputfield value="{!element.Name}" styleclass="widgetname" id="widgetname" />-->
</apex:pageblockSectionItem></apex:pageBlockSection></apex:pageBlock></apex:form>
</apex:page>