SomeguySomewhere
SomeguySomewhere

Reputation: 3

How to put an html link inside a Javascript fucntion?

So I have two html files, one named matrix.html and one named oneOne.html and a Javascript file named set.js.

matrix.html looks like this:

<form id=form1>
    <script type="text/javascript" src="_layout/js/set.js"></script>

    <select id="size1">
        <option value="1">1</option>`
    </select>

    <select id="size2">
        <option value="1">1</option>
    </select>

    <input type="button" value="Set" onclick="set();"/>
</form>

And the Javascript files, set.js, looks like this:

function set()
{
    var size1 = document.getElementById('size1').value;
    var size2 = document.getElementById('size2').value;

    if(size1 == "1" && size2 == "1")
    {

    }
}

What I want to happen is when the "Set" button is pushed it links to my html file, oneOne.html. The problem I'm having is that I don't know how to do that inside the if statement in the Javascript function. How would I go about doing that?

Upvotes: 0

Views: 50

Answers (1)

jmore009
jmore009

Reputation: 12931

You can just use Javascript redirect to go to the link if the statement evaluates to true

if(size1 == "1" && size2 == "1")
{
  window.location = "oneOne.html";
}

Upvotes: 2

Related Questions