Reputation: 21
I have the following function (onButtonClick
) when the button is clicked only the first function works. All the included functions work if I only have one of them in the button function.
I have also tried the on button click function this way as well. Still does not work.
setProjectData() && getProjectData() && window.location.href='support_page.html';
Any ideas on what I may be missing?
<span class="profile_container_right">
<a onclick='onButtonClick()'; return true;"; ><img src="images/bSUPPORT.png"/></a>
</span>
<script>
/* on button click */
function onButtonClick(){
setProjectData();
getProjectData();
window.location.href='support_page.html';
}
function setProjectData() {
// --- set local storage project descriptions ---
vProjectName=‘The Project Name’;
localStorage.setItem('xProjectName', vProjectName);
return true;
}
function getProjectData() {
// --- get local storage project descriptions ---
vProjectName = localStorage.getItem('xProjectName');
alert('you entered the GET project data function ='+vProjectName);
return true;
}
</script>
Upvotes: 0
Views: 693
Reputation: 1531
First issue is the use of quotes in the onclick binding:
onclick='onButtonClick()'; return true;";
The correct syntax for onclick is onclick="yourFunctionCall();"
for example:
onclick="onButtonClick(); return true;"
Second issue is your use of quotes in the setProjectData function:
vProjectName=‘The Project Name’;
Change to single quotes or double quotes:
vProjectName="The Project Name";
With these syntax issues fixed your code should execute as expected.
Side note use var
to declare variables within a function to make them adhere to the scope of the function. Declaring a js variable without the var
exposes the variable globally.
Upvotes: 3