Dynamically changing a DIV

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wkeithwork@gmail.com

    Dynamically changing a DIV

    I'm pulling my hair out...

    I have a few radio boxes where a user can choose different options and
    I want to show an explanation of each option after it's clicked.
    Here's what I have:

    <script type="text/JavaScript">

    function toggle(o){
    o.className = ( o.className == "show" ) ? "hide" : "show";
    }

    'function describetype(){
    ' if (window.event.s rcElement.value == "starter")
    typedesc.innerH TML="A Starter request is for a new employee who's
    never worked for cadbury or the Bottling Group before.";
    ' if (window.event.s rcElement.value == "leaver")
    typedesc.innerH TML="A Leaver request is for an existing employee who's
    permanently leaving the company.";
    '}

    'function starter(){
    'typedesc.inner HTML="A Starter request is for a new employee who's
    never worked for cadbury or the Bottling Group before.";
    '}

    'function leaver(){
    'typedesc.inner HTML="A Leaver request is for an existing employee
    who's permanently leaving the company.";
    '}

    function describetype(o) {
    if (o == "starter"){
    typedesc.innerH TML="Starters are...etc.";
    }
    if (o == "leaver"){
    typedesc.innerH TML="Leavers are...etc.";
    }
    }

    </script>

    The first "toggle" function works fine but the "describety pe" won't
    work. Here's the HTML:

    ....
    <td class="layout bold">
    <input type="radio" name="reqtype" value="starter"
    checked="checke d" onclick="descri betype(starter) "Starter<br >
    <input type="radio" name="reqtype" value="leaver"
    onclick="descri betype(leaver)" Leaver<br />
    </td>
    <td class="layout bold">
    <input type="radio" name="reqtype" value="mover"Mo ver<br />
    <input type="radio" name="reqtype" value="adhoc"Ad Hoc
    </td>
    ....

    The error keeps saying that "starter" or "leaver" is undefined. I'm
    not much of a javascript guy (mostly the cut and paste variety myself)
    but everything I've seen says this should work. No?

    Keith

  • Evertjan.

    #2
    Re: Dynamically changing a DIV

    wrote on 27 feb 2007 in comp.lang.javas cript:
    I have a few radio boxes where a user can choose different options and
    I want to show an explanation of each option after it's clicked.
    Here's what I have:
    >
    <script type="text/JavaScript">
    >
    function toggle(o){
    o.className = ( o.className == "show" ) ? "hide" : "show";
    >}
    >
    'function describetype(){
    >
    The apostrophe ' is a vbs remark character,
    javasctipt uses //

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • wkeithwork@gmail.com

      #3
      Re: Dynamically changing a DIV

      On Feb 27, 9:31 am, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
      wrote on 27 feb 2007 in comp.lang.javas cript:
      >
      >
      The apostrophe ' is a vbs remark character,
      javasctipt uses //
      >
      Ok lesson #1 learned. I changed the comment characters and it still
      didn't work but I switched to the ridiculously simple "starter" and
      "leaver" functions and that finally works. I wish I knew why it kept
      failing but time is more valuable than in-depth knowledge at this
      point. :)

      Thanks,

      Keith

      Comment

      • wkeithwork@gmail.com

        #4
        Re: Dynamically changing a DIV

        Ok I'm still trying to work on the same form and display a div based
        on a select statement and nothing I do seems to work.

        I'm trying to make a drop down select list that will display another
        list when I choose the second option. Here's the lists:

        <B>Employment Type</B>
        <select name="emptype" onchange="empty pe(this)">
        <option value=" "</option>
        <option value="employee ">Employee</option>
        <option value="contract or">Contracto r</option>
        </select><br>
        <img src="img/spacer_white.gi f" width=30 height=1>
        <div id=conttype class="hide">
        <select name="contractt ype">
        <option value=" "</option>
        <option value="payroll" >Payroll</option>
        <option value="agency"> Agency</option>
        </select><br />
        </div>

        If they choose "contractor " in the first list, I want a second
        dropdown to choose "Payroll" or "Agency".

        Here's the code I've got - again it's 99% copied and pasted so I'm
        thinking there's probably a syntax error or something:

        <script type="text/JavaScript">

        function toggle(o){
        o.className = ( o.className == "show" ) ? "hide" : "show";
        }

        function emptype(o){
        // This one just alerts me as a test. Even this doesn't work.
        var pick = o.options[o.selectedIndex].value;
        if (pick == "contractor ") alert("Contract or selected");

        // Here's what I tried before - didn't work either...
        //o = document.getEle mentsByName("em ptype");
        //if (o.selectedInde x = 2)
        // toggle(conttype );
        }

        </script>

        Thanks,

        Keith

        Comment

        • wkeithwork@gmail.com

          #5
          Re: Dynamically changing a DIV

          I think I solved my own problems. I had form objects named the same
          thing as functions in both cases and once I changed the names, it all
          worked like gangbusters. I assumed objects and functions were
          exclusive and it wouldn't matter... Lesson #2. :)

          Keith

          Comment

          • Evertjan.

            #6
            Re: Dynamically changing a DIV

            wrote on 01 mrt 2007 in comp.lang.javas cript:
            I think I solved my own problems. I had form objects named the same
            thing as functions in both cases and once I changed the names, it all
            worked like gangbusters. I assumed objects and functions were
            exclusive and it wouldn't matter... Lesson #2. :)
            >
            Without quoting we wouldn't know what you are talking about.

            This is usenet!

            --
            Evertjan.
            The Netherlands.
            (Please change the x'es to dots in my emailaddress)

            Comment

            • wkeithwork@gmail.com

              #7
              Re: Dynamically changing a DIV

              On Mar 2, 2:20 am, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
              wrote on 01 mrt 2007 in comp.lang.javas cript:
              >
              I think I solved my own problems. I had form objects named the same
              thing as functions in both cases and once I changed the names, it all
              worked like gangbusters. I assumed objects and functions were
              exclusive and it wouldn't matter... Lesson #2. :)
              >
              Without quoting we wouldn't know what you are talking about.
              >
              This is usenet!
              >
              Surely 99% of people use a news reader that keeps threads together...

              Anyway thanks again. :)

              Keith


              Comment

              • Evertjan.

                #8
                Re: Dynamically changing a DIV

                wrote on 02 mrt 2007 in comp.lang.javas cript:
                On Mar 2, 2:20 am, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
                > wrote on 01 mrt 2007 in comp.lang.javas cript:
                >>
                I think I solved my own problems. I had form objects named the same
                thing as functions in both cases and once I changed the names, it all
                worked like gangbusters. I assumed objects and functions were
                exclusive and it wouldn't matter... Lesson #2. :)
                >>
                >Without quoting we wouldn't know what you are talking about.
                >>
                >This is usenet!
                >
                Surely 99% of people use a news reader that keeps threads together...
                How do you know?

                You cannot, since the reader is not the point.

                Individual posts do not arrive syngronised on each news server, nor can you
                be sure they are kept there for a reasonable time.

                Furthermore it is polite "Usenet Netiquette" to edit the quotes to the
                essentials that are needed to understand the thread.
                Anyway thanks again. :)
                You are welcome.
                But why again?
                Did you already know the advice?

                --
                Evertjan.
                The Netherlands.
                (Please change the x'es to dots in my emailaddress)

                Comment

                Working...