<script type="text/javascript">
function toggle(id)
{
var thingy=document.getElementById(id);
if (thingy.style.display=="none")
{
thingy.style.display = "block";
//thingy.style.visibility="visible";
}
else
{
thingy.style.display = "none";
//thingy.style.visibility="hidden";
}
}
function addtask(id)
{
var name=prompt("Please enter Task name","");
var ble=prompt("Please enter Task Description","");
if ((name!=null && name!="") && (ble!=null && ble!="") && (id!=null && id!=""))
{
window.location = "ctsk.php?action=post&pid=" + id + "&nm=" + name + "&des=" + ble;
}
}
function edittask(na,de,id,id2)
{
var name=prompt("Please enter Task name",na);
var ble=prompt("Please enter Task Description",de);
if ((name!=null && name!="") && (ble!=null && ble!="") && (id!=null && id!="") && (id2!=null && id2!=""))
{
window.location = "ctsk.php?action=post&pid=" + id + "&nm=" + name + "&des=" + ble"&id=" + id2 ;
}
}
</script>
Whenever I call any of these functions, nothing happens. I ran it through a debugger and it tells me that these functions have not been defined. What can y'all see that ive done wrong?
P88 - The EvilSpaceHamster
[web] Javascript error
I just know this is gonna be a stupid error, but i need to know whats up. And where else best to ask than GameDev?
I have the following code:
To really understand function scoping in javascript, you need to understand that functions are first-class objects. That means that they're just pieces of code assigned to a variable. For example, the following two lines are functionally (basically) identical:
function toggle(id) {}
var toggle = function(id) {}
The first one is just syntactic sugar that makes javascript look more like other common C-style-syntax languages.<br><br>What this means is that you need to call the functions after they have been declared. For example, the following would give you an error:<br><br>toggle('mythingy');<br><br>function toggle(id) { /* whatever */ }<br><br>This is unlike some other languages, like PHP, where a function can be called above its declaration (if they're in the same file). In javascript, you need to make sure the line of code that declares the function gets run before the line of code that calls the function.<br><br>Sorry for the vague, theoretical response, but you didn't give enough code to give a specific solution. Let me know if this was helpful.
function toggle(id) {}
var toggle = function(id) {}
The first one is just syntactic sugar that makes javascript look more like other common C-style-syntax languages.<br><br>What this means is that you need to call the functions after they have been declared. For example, the following would give you an error:<br><br>toggle('mythingy');<br><br>function toggle(id) { /* whatever */ }<br><br>This is unlike some other languages, like PHP, where a function can be called above its declaration (if they're in the same file). In javascript, you need to make sure the line of code that declares the function gets run before the line of code that calls the function.<br><br>Sorry for the vague, theoretical response, but you didn't give enough code to give a specific solution. Let me know if this was helpful.
If those functions are in a separate file, did you remember to include them?
<script type="text/javascript" src="MyScriptFile.js"></script>
<script type="text/javascript" src="MyScriptFile.js"></script>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement