I have a small button which when pressed asks for a name and then adds the input to the URL which can then be processed by PHP. My code is below.
function staff_prompt(url)
{
var url = url;
var staffname=prompt("Please enter your Name below:","Staff Member Name");
if (staffname == null) {
}
else if (staffname == "Staff Member Name") {
alert('You must enter a value to continue');
staff_prompt();
}
else if (staffname == "") {
alert('You must enter a value to continue');
staff_prompt();
}
else {
var windowgo = url + "&staffmember=" + staffname;
window.location = windowgo;
}
}
My Button code is below
onclick="staff_prompt('index.php?app=orders&page=action&action=go_orderedviewtype=<?php echo $viewtype ?>&orderid=<?php echo $orderid ?>')
Sometimes it works well, however other times it seems to go to "http://undefined....ect" I cannot replicate the situation, sometimes it happens and sometimes not
I am thinking that maybe the code is not very good... why would the javascript not detect sometimes the variable 'url'.