2

I have two different side-panels with different settings, but would like to use one "login" form to access either depending on whether I clicked link A or B. So, I need to use the original string from either links' onclick attribute to change the onclick attribute of the "login" form so I can then pass that string into the function it uses.

I am admit-tingly a newb, albeit a quick learner. I am missing something here and can't figure it out, and may even be going in the wrong direction, so if I am please straighten me out! :)

Link A
<a href="#" id="leftOpen" onclick="openLogin(leftPanel)"></a>

Link B
<a href="#" id="rightOpen" onclick="openLogin(rightPanel)"></a>

Login Link
<a href="#" id="loginBtn" onclick="openPanel()"></a>

Login Link should be this after first function if clicked Link A
<a href="#" id="loginBtn" onclick="openPanel(leftPanel)"></a>


Functions

function openLogin(panel){
    var panel;
    $("#login").css("z-index", "1000");
    $("#login").addClass("show");
    document.getElementByID("#loginBtn").setAttribute("onclick","openPanel(\" . panel . \")");
    };

function openPanel(open){
    var open;
    if (window.XMLHttpRequest) {
        xmlhttp=new XMLHttpRequest();
    }
    else {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            result=xmlhttp.responseText;
                if (result == 0) {
                    $("#login").css("z-index", "-1");
                    $("#login").removeClass("show");
                    $("#" . open).addClass("openSettings");  // Got to be something wrong here!
                    document.getElementById("pwd").value='';
                }
                else {
                    alert("The password entered is incorrect.")
                    document.getElementById("pwd").value='';
                }
        }
    }
    var url="../somewhere/mychk.php?pwd="+document.getElementById("pwd").value;
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
};
1
  • the concatenation operator in javascript is +, not . Commented Nov 13, 2013 at 6:20

1 Answer 1

1

You need to pass in a string in your onclick events, for the id of your panels

<a href="#" id="leftOpen" onclick="openLogin('leftPanel')"></a>

You are redefining panel in openLogin, thus overwriting whatever you pass in

function openLogin(panel){

    // remove this line
    // var panel;

    $("#login").css("z-index", "1000");
    $("#login").addClass("show");
    document.getElementByID("#loginBtn").setAttribute("onclick", "openPanel('" + panel + "')");
};

Depending on what your panel(s) ids are, if you use the correct concatenation operator, the following should work

$("#" + open).addClass("openSettings");
Sign up to request clarification or add additional context in comments.

1 Comment

Kavun, I'm about to try this out, but I am unsure what you mean with the "correct concatenation operator". Would you mind elaborating on this please?

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.