if else syntax -

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • daniel

    if else syntax -

    I'm trying to do a simply if else thing but for some reason it doesn't
    work. The commented code works - as you can see I'm using jquery but
    the problem only happens when I convert the two .click functions into
    one with an if.. else statement. The commented section works but i
    would like to get the simpler one following working.

    /* $("#unsubscribe ").hide();

    $("#subscribe h4 a").click(funct ion(){
    $("#subscribe") .hide();
    $("#unsubscribe ").fadeIn() ;
    return false;
    });
    $("#unsubscri be h4 a").click(funct ion(){
    $("#unsubscribe ").hide();
    $("#subscribe") .fadeIn();
    return false;
    });*/


    $("#unsubscribe ").hide();
    var formswitch = 0;

    $(".left h4 a").click(funct ion(){
    if (formswitch == 0) {$("#subscribe" ).hide();
    $("#unsubscribe ").fadeIn() ;
    var formswitch = 1;
    return false;}
    else {$("#unsubscrib e").hide();
    $("#subscribe") .fadeIn();
    return false;}
    });
  • Bjoern Hoehrmann

    #2
    Re: if else syntax -

    * daniel wrote in comp.lang.javas cript:
    >I'm trying to do a simply if else thing but for some reason it doesn't
    >work. The commented code works - as you can see I'm using jquery but
    >the problem only happens when I convert the two .click functions into
    >one with an if.. else statement. The commented section works but i
    >would like to get the simpler one following working.
    > var formswitch = 0;
    >
    > $(".left h4 a").click(funct ion(){
    > if (formswitch == 0) {$("#subscribe" ).hide();
    > $("#unsubscribe ").fadeIn() ;
    > var formswitch = 1;
    Presumably you did not mean to specify the 'var' here; other than that
    there seems little wrong with this, though I would strongly suggest to
    use proper indentation at least when asking others to debug your code,
    and you might want to put the "return false" at the end of the function
    rather than duplicate it.
    --
    Björn Höhrmann · mailto:bjoern@h oehrmann.de · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

    Comment

    • daniel

      #3
      Re: if else syntax -

      I'm not sure which one it was but that was the fix. I think the silly
      mistake of putting the var in there was it.

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: if else syntax -

        daniel wrote:
        I'm not sure which one it was but that was the fix. I think the silly
        mistake of putting the var in there was it.
        Which only leaves the silly mistake of using jQuery in its current form to
        be corrected.




        PointedEars
        --
        Prototype.js was written by people who don't know javascript for people
        who don't know javascript. People who don't know javascript are not
        the best source of advice on designing systems that use javascript.
        -- Richard Cornford, cljs, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

        Comment

        Working...