NEED help with javascript/php bad. Can anyone let me know what's wrong with this code?

  • chicagojock09

    Posts: 11

    Jun 10, 2014 12:42 AM GMT
    //w3schools.com, quirksmode.org, and stackoverflow.com
    window.onload = initPlaySelector; //The onload event occurs when an object has been loaded.

    function initPlaySelector() { //Specifies a JavaScript to be executed when the event occurs

    var plays = document.getElementsByClassName("playheader");
    for (var i = 0; i plays[i].onmouseover = hiliteMe(this); //The onmouseover event occurs when the pointer is moved onto an element. The this element refers to the object that is going to be called in the function.
    plays[i].onmouseout = unhiliteMe(this);//The onmouseout event occurs when a user moves the mouse pointer out of an element.
    plays[i].onclick = togglePlotSum(this);//The onclick event occurs when the user clicks on an element.
    }
    }


    function hiliteMe(this) {//Since "this" is present in the event handler it is sent to the function
    Need a search statement here
    this.className = this.className.replace("playheader", "hilite");//thisSum calls the object Sum so when an element is unhilited, it switches the CSS style from the class hilite to the class playheader.

    }

    function unhiliteMe(this) {
    Need a search statement here
    this.className = this.className.replace("hilite", "playheader");//thisSum calls the object Sum so when an element is unhilited, it switches the CSS style from the class hilite to the class playheader.
    }

    function togglePlotSum(this) { //This is where the "
    s" visibility are toggled and in the "switch" case it evaluates the id of the entire play then grabs the ids of the summaries to switch between the displays
    switch (this) {//The value of the playid is compared with the values of each subsequent case.

    case "first":

    if (document.getElementById("sum1").style.display == "block") {
    document.getElementById("sum1").style.display="none";//This is to be executed if the condition is true
    }

    else {

    document.getElementById("sum1").style.display="block";//This is to be executed if the condition is false
    }
    break;

    case "second":
    if (document.getElementById("sum2").style.display == "block") {
    document.getElementById("sum2").style.display="none";
    }

    else {
    document.getElementById("sum2").style.display="block";
    }

    break;

    case "third":
    if (document.getElementById("sum3").style.display == "block") {
    document.getElementById("sum3").style.display="none";
    }

    else {
    document.getElementById("sum3").style.display="block";
    }

    break;

    case "fourth":
    if (document.getElementById("sum4").style.display == "block") {
    document.getElementById("sum4").style.display="none";
    }

    else {
    document.getElementById("sum4").style.display="block";
    }

    break;

    case "fifth":
    if (document.getElementById("sum5").style.display == "block") {
    document.getElementById("sum5").style.display="none";
    }

    else {
    document.getElementById("sum5").style.display="block";
    }

    break;

    case "sixth":
    if (document.getElementById("sum6").style.display == "block") {
    document.getElementById("sum6").style.display="none";
    }

    else {
    document.getElementById("sum6").style.display = "block";
    }

    break;
    }
    }
  • Posted by a hidden member.
    Log in to view his profile

    Jun 10, 2014 2:53 PM GMT
    No clue! But as a hunch, double-check the placement of the open and end brackets. Also, does it matter whether or not there's a space between the open brackets and the double forward slashes?
  • Posted by a hidden member.
    Log in to view his profile

    Jun 10, 2014 7:39 PM GMT
    That switch statement bothers me; it seems like overkill or something. Each case statement is doing the same thing which strikes me as sketchy. What about using the "in" operator? E.g.,

    var object = {
        first: "sum1",
        second: "sum2"
        // etc.
    };

    if (this in object) { ... }

    http://stackoverflow.com/questions/1119336/in-statement-in-javascript-jquery

    Put breakpoints on each of your functions and make sure they're getting called when you think they should be.

  • chicagojock09

    Posts: 11

    Jun 10, 2014 11:38 PM GMT
    Thank you. Yeah I could have used nested if statements but I got the case to work as well. Finished the javascript portion. Now I need help with php.