blm126
09-25-2005, 06:47 PM
I'm trying to write a script that can access a variable stored in the url. Like somefile.html?something=variable
Right now I've got a script that works but I would like to streamline it.
My current script is
<head>
<SCRIPT LANGUAGE="javascript">
function urlvar1()
{
var locate = window.location
document.locform.loc.value = locate
var loc = document.locform.loc.value
var start = loc.indexOf("=") + 1
var result = loc.substring(start)
return result
}
</SCRIPT>
<body>
<FORM NAME="locform">
<INPUT TYPE="hidden" NAME="loc">
</FORM>
<script type="text/javascript" language="javascript">
document.write(urlvar1())
</script>
</body>
It works,but I want to find a way to get rid of the form. Right now I'm using it to turn window.location property into a string. Does anyone know another way to turn the url into a string. I want all the code to go in the function urlvar1() so all you do is link to the script then call the function without the extra html.
Right now I've got a script that works but I would like to streamline it.
My current script is
<head>
<SCRIPT LANGUAGE="javascript">
function urlvar1()
{
var locate = window.location
document.locform.loc.value = locate
var loc = document.locform.loc.value
var start = loc.indexOf("=") + 1
var result = loc.substring(start)
return result
}
</SCRIPT>
<body>
<FORM NAME="locform">
<INPUT TYPE="hidden" NAME="loc">
</FORM>
<script type="text/javascript" language="javascript">
document.write(urlvar1())
</script>
</body>
It works,but I want to find a way to get rid of the form. Right now I'm using it to turn window.location property into a string. Does anyone know another way to turn the url into a string. I want all the code to go in the function urlvar1() so all you do is link to the script then call the function without the extra html.