We help IT Professionals succeed at work.

java script problem

beridius
beridius asked
on
I have problem with some javascript I have a function called address and another function called address1 they both do the samething but in diffrent textbox but only one works?
Comment
Watch Question

paste  your code

Author

Commented:
<script language="javascript" type="text/javascript">
function PostcodeAnywhere_Interactive_Find_v1_10Begin(Key, SearchTerm, PreferredLanguage, Filter, UserName)
   {
      var scriptTag = document.getElementById("PCA6d35cfc188f1451f9cfdf1b5d751a716");
      var headTag = document.getElementsByTagName("head").item(0);
      var strUrl = "";

      //Build the url
      strUrl = "http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/Find/v1.10/json.ws?";
      strUrl += "&Key=" + encodeURI(Key);
      strUrl += "&SearchTerm=" + encodeURI(SearchTerm);
      strUrl += "&PreferredLanguage=" + encodeURI(PreferredLanguage);
      strUrl += "&Filter=" + encodeURI(Filter);
      strUrl += "&UserName=" + encodeURI(UserName);
      strUrl += "&CallbackFunction=PostcodeAnywhere_Interactive_Find_v1_10End";

      //Make the request
      if (scriptTag) 
         {
            try
              {
                  headTag.removeChild(scriptTag);
              }
            catch (e)
              {
                  //Ignore
              }
         }
      scriptTag = document.createElement("script");
      scriptTag.src = strUrl
      scriptTag.type = "text/javascript";
      scriptTag.id = "PCA6d35cfc188f1451f9cfdf1b5d751a716";
      headTag.appendChild(scriptTag);
   }

function PostcodeAnywhere_Interactive_Find_v1_10End(response)
   {
      //Test for an error
      if (response.length==1 && typeof(response[0].Error) != 'undefined')
         {
            //Show the error message
            alert(response[0].Description);
         }
      else
         {
            //Check if there were any items found
            if (response.length==0)
               {
                  alert("Sorry, no matching items found");
               }
            else
               {
                   document.getElementById('return').style.display = '';
					document.getElementById('return').options.length = 0;
                    for (var i=0;i<response.length;i++)
			            document.getElementById('return').options.add(new Option(response[i].StreetAddress + ", " + response[i].Place, response[i].Id));
               }
         }
   }
   
   
   
   
   
   function PostcodeAnywhere_Interactive_RetrieveById_v1_10Begin(Key, Id, PreferredLanguage, UserName)
   {
      var scriptTag = document.getElementById("PCAa73f9bc2b60d4e4cbd595512478a3291");
      var headTag = document.getElementsByTagName("head").item(0);
      var strUrl = "";

      //Build the url
      strUrl = "http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/RetrieveById/v1.10/json.ws?";
      strUrl += "&Key=" + encodeURI(Key);
      strUrl += "&Id=" + encodeURI(Id);
      strUrl += "&PreferredLanguage=" + encodeURI(PreferredLanguage);
      strUrl += "&UserName=" + encodeURI(UserName);
      strUrl += "&CallbackFunction=PostcodeAnywhere_Interactive_RetrieveById_v1_10End";

      //Make the request
      if (scriptTag) 
         {
            try
              {
                  headTag.removeChild(scriptTag);
              }
            catch (e)
              {
                  //Ignore
              }
         }
      scriptTag = document.createElement("script");
      scriptTag.src = strUrl
      scriptTag.type = "text/javascript";
      scriptTag.id = "PCAa73f9bc2b60d4e4cbd595512478a3291";
      headTag.appendChild(scriptTag);
   }

function PostcodeAnywhere_Interactive_RetrieveById_v1_10End(response)
   {
      //Test for an error
      if (response.length==1 && typeof(response[0].Error) != 'undefined')
         {
            //Show the error message
            alert(response[0].Description);
         }
      else
         {
            //Check if there were any items found
            if (response.length==0)
               {
                  alert("Sorry, no matching items found");
               }
            else
               {
				   var retstring1 = response[0].Company; 
				   var retstring2 = response[0].Line1;
				   var retstring3 = response[0].Line2; 
				   var retstring4 = response[0].Line3;
				   var retstring5 = response[0].PostTown; 
				   var retstring6 = response[0].County;
				   var retstring7 = response[0].Postcode;
			      
				    document.getElementById("ClientAddress1").value=retstring2;
					document.getElementById("ClientAddress2").value=retstring3;
					document.getElementById("ClientAddress3").value=retstring4;
					document.getElementById("ClientAddress4").value=retstring5;
					document.getElementById("ClientAddress5").value=retstring6;
					document.getElementById("ClientPostcode").value=retstring7;
			
					
			
			         
				   
			       document.getElementById('return').style.display = 'none';
               }
         }
   }

</script>

Open in new window

in which line you are getting problem.
Kiran SonawaneProject Lead
Top Expert 2011

Commented:
Show your response string (it might be json string) you are getting by alerting it like alert(response) after line number 99
Top Expert 2007
Commented:
Put the keyword

debugger;

on its own line where you suspect the error to be (or at the top of the function, or...) and let Firebug help.
Top Expert 2007

Commented:
And what did you discover?

Oh, and no worries - glad to help.