Andrew Bort Andrew Bort - 1 month ago 9
Javascript Question

Uncaught ReferenceError: parseURL is not defined

I've defined a function named parseURL in javascript in the head of my file, and I have a button set so that when it is clicked, it should call said function. However, for some reason my debugger is telling me that parseURL is not defined. The exact error is "Uncaught ReferenceError: parseURL is not defined"

<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<link rel="stylesheet" href="../css/style.css" type="text/css" />
<TITLE>
Pic Grabber (javascript)
</TITLE>
<script type="text/javascript" src="linkedURL.js" />

<script type="text/javascript">
var Page = {};
Page.currentURL = null;
Page.link = document.getElementById("link");

/*
###################################
# The function that "doesn't exist"
###################################
*/

function parseURL(){
Page.url = document.getElementById("url").value;

if(!checkValidURL(Page.url)){
alert("Must Enter a valid URL");
}

Page.link.innerHTML = Page.url;

return true;
}

function checkValidURL(url){
var request = false;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest;
}
else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHttp");
}
else{
alert("FAIL");
}

if (request) {
request.open("GET", url);
if (request.status == 200) {
return true;
}
}

return false;
}

</script>
</HEAD>
<BODY>
<div class="wrap">
<h1><a href="#">My Database</a></h1>
<ul id="menu">
<li><a href="../index.php">Home</a></li>
<li><a href="../upload.php">Upload</a></li>
<li><a href="#">Advanced Search</a></li>
<li><a href="#">My Profile</a></li>
</ul>
<div class="clear"></div>
<div id="left">
<a href="#" id="link"></a>
</div>
<div id="right">
<div class="box">
<form id="input">
<p>URL:</p><br/>
<input type="text" id="url" /><br />

#################################
# This is where the error appears
#################################

<input type="button" id="getButton" value="Get Pics" onclick="parseURL()" />
<input type="button" id="back" value="<< Back" onclick="back()" disabled="true"/>
<input type="button" id="next" value="Next >>" onclick="next()" disabled="true"/>
</form>
</div>
</div>
</div>

</BODY>

</HTML>


It seems like it should be an easy fix, I've tried a bunch of things though and nothing seems to be working. Any help is appreciated.

Joe Joe
Answer

Move this:

<script type="text/javascript" src="linkedURL.js" />

to here:

<script type="text/javascript" src="linkedURL.js"> </script>
</BODY>
Comments