I'm creating a function in javascript that is activated by an onclick and I just need a simple line of javascipt code to link to another html page.
<area shape="rect" coords="78,348,182,395" onclick="nextquestion">
user clicks on that area
function nextquestion(){
window.location="contact.html";
}
links to this function
4 Answers 4
Why don't use <area .... href="" />? Href is valid for area tag
Comments
You are not executing the function in this code:
<area shape="rect" coords="78,348,182,395" onclick="nextquestion">
nextquestion only stays there as a unused variable pointing to the function.
Use nextquestion() to actually execute the function:
<area shape="rect" coords="78,348,182,395" onclick="nextquestion()">
Comments
You'd want to change your onclick to call the function, in JS this requires a set of parentheses after the name of the function like:
<area shape="rect" coords="78,348,182,395" onclick="nextquestion();">
Then in your JS
function nextquestion() {
window.location.href = 'contact.html';
}
1 Comment
did you try this ?
<area shape="rect" coords="78,348,182,395" href = 'contact.html'>
or
<area shape="rect" coords="78,348,182,395" onclick="nextquestion()">
onclick="nextquestion();"<area shape="rect" coords="78,348,182,395" href="contact.html">would be a whole lot easier.