Getting Parameters

<< Click to Display Table of Contents >>

Navigation:  Snippets >

Getting Parameters

Previous pageReturn to chapter overviewNext page

An easy way to get parameters into the Javascript is via the URL.

 

A typical URL could look like this

 

http://www.mywebsite/index.php?id=param

 

or

 

http://www.mywebsite/index.html?id=param

 

In your script (at the start or in an onready function) do the following

 

        var inputparameter = location.search.substring(4);

        if( inputparameter === "") { xui.alert("No Site Defined! - Refresh with Site in URL");  }

        if( inputparameter === "param" ) { xui.alert("input = "+inputparameter); another_function_call_1;   }

 

If you have loads of input options you could use a switch

 

 switch(inputparameter)

         {

         case "param":

                 actions......

                 break;

         case "another":

                 actions.....

                 break;

         }

 

The parameter we want to get starts at position 4.

 ?id=param

 01234