+ Start a Discussion
AnjaneyluAnjaneylu 

what is the use of SRC attribute in SCRIPT tag in visualforce page..

hi 
what is the use of SRC attribute in SCRIPT tag in visualforce page.. ?
here i have seen this piece of code for creating account record through visualforce page. 
why he used this attribute.
here example is :
<apex:page id="page">   
                  <script src="/soap/ajax/36.0/connection.js" type="text/javascript">
             
         </script>
         <script>
         function callAjax(){
             sforce.connection.sessionid = '{!$Api.session_id}';
             var accountnam = document.getElementById('page:fm:accountname').value;
             var indust = document.getElementById('page:fm:accountindustry').value;
             var account1 = new sforce.sobject("account");
             account1.name = accountnam;
             account1.industry = indust;
             var result = sforce.connection.create([account1]);
             document.getElementById('page:fm:reslt').innerhtml = result;
         }
         </script>
         
     <apex:form id="fm">
              Account name : &nbsp;  &nbsp;   &nbsp;  <apex:inputText id="accountname"/><br/>
         Industry :  &nbsp;  &nbsp;   &nbsp; &nbsp;  &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<apex:inputText id="accountIndustry"/><br/>
         <apex:commandButton value="Call ajax" oncomplete="callAjax()" />
         <apex:outputLabel id="reslt" />
         
     </apex:form>
</apex:page>

please help me 
Thanks in Advance
Anji reddy
 
Best Answer chosen by Anjaneylu
Dutta SouravDutta Sourav
Hi,

The src attribute specifies the URL of an external script file.
If you want to run the same JavaScript on several VF Pages, you should create an external JavaScript file, instead of writing the same script over and over again.
Save the script file with a .js extension, and then refer to it using the src attribute in the <script> tag.

To see the source code of the .js file, check:
https://ap1.salesforce.com/soap/ajax/36.0/connection.js

Kind Regards,
Sourav

All Answers

AnjaneyluAnjaneylu
and here in the code he mentioned src attribute as 
 
<script src="/soap/ajax/36.0/connection.js" type="text/javascript">

  </script>

what is the use of this line..
 
Dutta SouravDutta Sourav
Hi,

The src attribute specifies the URL of an external script file.
If you want to run the same JavaScript on several VF Pages, you should create an external JavaScript file, instead of writing the same script over and over again.
Save the script file with a .js extension, and then refer to it using the src attribute in the <script> tag.

To see the source code of the .js file, check:
https://ap1.salesforce.com/soap/ajax/36.0/connection.js

Kind Regards,
Sourav
This was selected as the best answer
AnjaneyluAnjaneylu
thank you sourav for your great reply.. and here
 initially i have not written any javascript files. but in the code  mentioned that src = "soap/ajax/36.0/connection.js"
from where we are getting this.. 

thanks in advance..
anji
Dutta SouravDutta Sourav
Hi Anji,

It's an in-built code developed by Salesforce.

Kind Regards,
Sourav.
 
AnjaneyluAnjaneylu
ok. i got it clearly.
but my above  code is not working properly..
can you help me.
here  i'm unable to save the account record..

thanks
anji