You need to sign in to do that
Don't have an account?
![Andrey Andrey](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Problem with JavaScript
Hi all!
I need to pass a value from javascrip (in vf page) to inputField
Here code:
Thanks!
I need to pass a value from javascrip (in vf page) to inputField
Here code:
<apex:page standardController="Travel_Expenses__c" extensions="TE_Object" action="{!Parameters}"> <apex:form > <apex:pageBlock title="Travel Information Edit" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!Save}" value="Save"/> <apex:commandButton action="{!SaveAndNew}" value="Save & New"/> <apex:commandButton action="{!Cancel}" value="Cancel"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Information" columns="2"> <apex:inputField value="{!NewTE.Traveler__c}" id="Traveler" required="true" onchange="TakeCountry(this.id);"> <apex:actionsupport event="onchange" reRender="CountryName"/> </apex:inputField> <apex:pageBlockSectionItem > <apex:outputLabel value="Country" for="CountryName"/> <apex:inputField value="{!NewTE.Country_Name__c}" id="CountryName" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <script language="JavaScript1.2" src="/js/functions.js"></script> <script src="/soap/ajax/9.0/connection.js" type="text/javascript"></script> <script type="text/javascript"> function TakeCountry(id) { try { sforce.connection.sessionId = '{!$Api.Session_ID}'; var cval = document.getElementById(id).value; if (cval!=null) { country=sforce.connection.query("Select Country_Names__c from Travel_Information__c WHERE name='"+cval+"'"); alert('Selected '+country); records = country.getArray("records"); c=records[0].Country_Names__c; alert('C '+c);//after this message I have an error countryname=document.getElementById({!$Component.CountryName}).value; alert('done '); countryname.value='country'; alert('Country '+countryname.value); } } catch (error) { alert('Error: '+error.faultstring); } } </script> </apex:page>I add a comment where script failed (Error: undefined)
Thanks!
Plus, you are using old Ajax Toolkit, which is deprecated. You should be using JS Remoting now : https://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm
Remoting in Apex + VF can get your requirement addressed for sure.