URL variables using JavaScript

By narendra kothule

// Create variable is_input to see if there is a ? in the url
var is_input = document.URL.indexOf(‘?’);

// Check the position of the ? in the url
if (is_input != -1)
{
// Create variable from ? in the url to the end of the string
addr_str = document.URL.substring(is_input+1, document.URL.length);

// Loop through the url and write out values found
// or a line break to seperate values by the &
for (count = 0; count < addr_str.length; count++)
{
if (addr_str.charAt(count) == “&”)
// Write a line break for each & found
{
document.write (“<br>”);
}
else
// Write the part of the url
{
document.write (addr_str.charAt(count));
}
}

}
// If there is no ? in the url state no values found
else
{
document.write(“No values detected”);
}

Tags: , , ,

Leave a Reply