Skip to main content

Class 5

Class 5 Keypoint:

Using GetUrlVar to get variables from other HTML file pages.

Page A can open Page B with variables as input for page B, so page B can show different content for each input.
For this we use the following function inside page B: 
function GetUrlVar(VarName)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + VarName + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
var filmid = decodeURIComponent(GetUrlVar('filmid')); var numID= Number(filmid);
document.getElementById("demo").innerHTML = writeText(numID);
    


Where filmid is the variable to store variable from URL, but it is saved as char string, to cast to integer we create numID and cast to an integer with Number();

And in page A we open page B (items.html) as follow:
        "items.html?filmid=x", where x is the id number to pass to page B.


Homework:

















Comments

Popular posts from this blog

Class 7

  Class 7  Key-point : Using Google's API to read from Spread Sheet into our website. Must initialize Google Spread Sheet with special URL which allow java script to access all data inside a spreadsheet. The function init() initializes and opens the spread sheet and then sends the data to the function processSheetsData() in order to get data values from it.  We do this by using rows and columns.

Class 8

  Class 8  Key-point : Using iframe to input google maps onto website. We can do this by importing Google Map's API, then set the latitude and longitude. Also we can set the zoom of the map to show different locations, such zoom=20 for buildings or zoom=4 for countries.

Class 9

  Class 9  Key-point : We can use materialize CSS to format our layout by using cards.  Use for loop to fill cards when listing items, to avoid repeating code. Instead of repeating this segment for every item listed we add a for loop. Also we implement reading the data from Google Spread Sheet so the for loop will run row number of times, where row is the number of items listed on the Spread Sheet.     We get the following result.