user5586668
user5586668

Reputation:

JavaScript function href

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

Upvotes: 0

Views: 78

Answers (4)

somu
somu

Reputation: 447

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

Upvotes: 0

CoderPi
CoderPi

Reputation: 13211

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

Upvotes: 1

Konstantin Zadiran
Konstantin Zadiran

Reputation: 1541

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

Upvotes: 2

SidOfc
SidOfc

Reputation: 4594

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';
}

Upvotes: 0

Related Questions