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

Problem with JavaScript

Hi all!
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:pageBlockSection title="Information" columns="2">
                      <apex:inputField value="{!NewTE.Traveler__c}" id="Traveler" required="true" 
                        <apex:actionsupport event="onchange" reRender="CountryName"/>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Country" for="CountryName"/>
                    <apex:inputField value="{!NewTE.Country_Name__c}" id="CountryName" />     
    <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)
                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");
                    alert('C '+c);//after this message I have an error
                    alert('done ');
                    alert('Country '+countryname.value);

            catch (error)
                alert('Error: '+error.faultstring);
I add a comment where script failed (Error: undefined)


Abhinav GuptaAbhinav Gupta
Can you please add more details i.e. what is alerting in Error message. As you are catching it in generic catch block, one cant be sure of what is the issue.

Plus, you are using old Ajax Toolkit, which is deprecated. You should be using JS Remoting now :

Remoting in Apex + VF can get your requirement addressed for sure.