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
neeedhelpneeedhelp 

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

Best Answer chosen by Admin (Salesforce Developers) 
Sridhar VenkateswaraluSridhar Venkateswaralu

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

Sridhar VenkateswaraluSridhar Venkateswaralu

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>

This was selected as the best answer
neeedhelpneeedhelp

Hi Sridhar,

 

Need one more help from u.....   when ever I copy and paste the below two lines of code I need to remove '/n' tag by doing validations........How can I do it

 

  <span class='st_twitter_large' displayText='Tweet'></span>

<span class='st_linkedin_large' displayText='LinkedIn'></span>
<span class='st_facebook_large' displayText='Facebook'></span>

 

 

<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "ur-60b10a2-3d12-df15-639c-718eeb5b82c6"}); </script>