SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    396
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Global variables in Javascript?

    Hi guys,

    I've got a function that works out what page your on, and returns a value 'url' :

    Code JAVASCRIPT:
    function checkpage() {
    	var queryS = getQueryString("S");
    	if (queryS == 'case1') {
    		var url="case1.php"
    		return url;
    	} else if (queryS == 'case2') {
    		var url="case2.php";
    		return url;
    	}
    }

    Now, assuming I want to use that variable in another function, for example
    Code JAVASCRIPT:
    function outputurl(url) {
    alert(url);
    }
    For some reason it just says undefined. How exactly do I pass the variable from one function to another?

    Thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    outputurl(checkpage());
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    396
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Many thanks pmw57, how do I actually get a variable to take the value though?

    url = checkpage();

    Edit: Just got it working, many thanks!


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
  •