Hello again people of Stack
I have a small problem with my code. I am trying to send my variable with the window.location.href
, but I keep getting the error not defined
.
This is the function wich chooses my image (src) and the id (chosenid) The chosenid does work as I've tested that.
function HeadShow() {
var HeadItems = document.getElementById('HeadItems');
HeadItems.style.display = 'block';
}
function headHide(src, chosenid) {
var head = document.getElementById("head");
var HeadItems = document.getElementById('HeadItems');
HeadItems.style.display = 'none';
head.innerHTML = "<img src='" + src + "' width=80; height=80;>";
var chosenhead = chosenid;
}
Then, I also have the function which should send the variable to the next page:
function send() {
window.location.href = "test3.php?head=" + chosenhead;
}
All I get is the error: chosenhead is not defined
Hope you guys can help me out with this.
You defined your chosenhead variable inside a function.. so it's only accessible in the scope of this function. Move it outside the function:
var chosenhead = '';
function HeadShow() {
var HeadItems = document.getElementById('HeadItems');
HeadItems.style.display = 'block';
}
function headHide(src, chosenid) {
var head = document.getElementById("head");
var HeadItems = document.getElementById('HeadItems');
HeadItems.style.display = 'none';
head.innerHTML = "<img src='" +src+ "' width=80; height=80;>";
chosenhead = chosenid;
}
function send()
{
window.location.href = "test3.php?head=" + chosenhead;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments