SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Parameters

  1. #1
    SitePoint Addict AdRock952's Avatar
    Join Date
    Aug 2006
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parameters

    I have got a function for geocoding and would like to know if and how I can set parameters in the function

    This is the function which takes a postcode as a parameter

    Code HTML4Strict:
    Postcode Lookup : <input type="text" id="formPostcode" value="
    <input type="button" value="Lookup (incorrect)"  onclick="incorrectGeocodeLookup(document.getElementById('formPostcode'));"/>"
    />

    this is the funcion
    Code JavaScript:
    function startGeocodeLookup(elem) {
        	    var postcode=elem.value;
        	    var formLat=document.getElementById('formLat');
        	    var formLong=document.getElementById('formLong');
        	    usePointFromPostcode(postcode,
        	    function (point) {
    		if (!point) {
    		    alert(postcode + " not found");
    		} else {
    		    formLat.value=point.lat();
              	    formLong.value=point.lng();
    		}
    	    }
    	    );
            }
    would it be possible to pass some more parameters so in these 2 lines i can choose which form elements to pass it?
    Code JavaScript:
    var formLat=document.getElementById('formLat');
    var formLong=document.getElementById('formLong');

    would this work
    Code JavaScript:
    function startGeocodeLookup(elem, start, finish) {
        	    var postcode=elem.value;
        	    var formLat=start;
        	    var formLong=finish;
        	    usePointFromPostcode(postcode,
        	    function (point) {
    		if (!point) {
    		    alert(postcode + " not found");
    		} else {
    		    formLat.value=point.lat();
              	    formLong.value=point.lng();
    		}
    	    }
    	    );
            }
    Code HTML4Strict:
    <input type="button" value="" onclick="workingGeocodeLookup(document.getElementById('formPostcode', formStart, formFinish));"/>

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No, but this would:
    Code Javascript:
    <input type="button" value="" onclick="workingGeocodeLookup(document.getElementById('formPostcode'), formStart, formFinish);"/>
    Just change the closing bracket position.

    Also, you should consider using unobtrusive javascript instead of ancient-style inline event listeners.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •