Any suggestion ??
<apex:page controller="AlertConId" >
<script type="text/javascript">
function demo(fst,lst)
{
var fn = document.getElementById(fst).value;
var ln = document.getElementById(lst).value;
myFunction(fn,ln);
}
</script>
<apex:form >
<apex:actionFunction name="myFunction" action="{!save}">
<apex:param value="" name="fname" assignTo="{!fname}"/>
<apex:param value="" name="lname" assignTo="{!lname}"/>
</apex:actionFunction>
<apex:pageBlock id="ref">
<apex:pageBlockSection >
<apex:inputText id="fname" label="FirstName"/>
<apex:inputText id="lname" label="LastName"/>
<apex:commandButton value="Go" onclick="demo('{!$Component.fname}','{!$Component.lname}')" reRender="ref"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
------------------------------------------------------------------------------------------------------------
public class AlertConId
{
public Contact ct {get;set;}
public string fname {get;set;}
public string lname {get;set;}
public void save()
{
string first = ApexPages.currentPage().getParameters().get('fname');
string last = ApexPages.currentPage().getParameters().get('lname');
system.debug(first + last);
ct = new Contact();
ct.firstname = first;
ct.lastname = last;
try{
insert ct;
}
catch(Exception e){}
}
}
Hi Sandeep, When you have set the value in the variables with the help of the param then why did you tried to get it from the URL. You should directly use the variables as set in the page. Please change your code as below :
Please let us know if you need any further information or help on this.Thanks,Abhishek Bansal.public class AlertConId
{
public Contact ct {get;set;}
public string fname {get;set;}
public string lname {get;set;}
public void save()
{
// In your VF page you have set the vaues in the variables fname and lname so directly use them
system.debug(fname + lname);
ct = new Contact();
ct.firstname = fname;
ct.lastname = lname;
try{
insert ct;
}
catch(Exception e){}
}
}