0

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

2
  • 3
    onclick="nextquestion();" Commented Dec 1, 2015 at 13:38
  • <area shape="rect" coords="78,348,182,395" href="contact.html"> would be a whole lot easier. Commented Dec 1, 2015 at 13:47

4 Answers 4

2

Why don't use <area .... href="" />? Href is valid for area tag

Sign up to request clarification or add additional context in comments.

Comments

1

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

0

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

Also window.location = "contact.html"; works and window.location.href = "contact.html"; is a synonym (developer.mozilla.org/en-US/docs/Web/API/Window/location).
0

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()">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.