0

I want to direct the user to another page when they check a checkbox. This is what I tried.

<input type="checkbox" name="cheque_status" value="0" id="chequeList" onclick="myfunc()"/>

            <iframe style="display:none;">
                <script>
                    function myfunc(){
                        if(document.getElementById("chequeList").checked= true) {
                                location.href = "/index.cfm";
                            }
                    }
                </script>
            </iframe>

Basically what I am trying to do is, if there is any onclick on the checkbox, then it should redirect users to that index.cfm page. However, it doesn't work for me.

What am I doing wrong? Please help.

Thank you.

2
  • 1
    Remove the = true in your test. It's an assignment, not a comparison. Commented Mar 6, 2017 at 11:59
  • Use a link. Use a real link. Checkboxes are not links and shouldn't behave like links. Commented Mar 6, 2017 at 12:11

1 Answer 1

1

You've provided the <script> as alternative content to an <iframe> which doesn't have a src and isn't displayed.

Remove the iframe.

(Also fix your = in the JS: You need a comparison, not an assignment).

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

1 Comment

I removed the iframe and also the = and it works perfectly. Thank you.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.