show hide form

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

    #1

    show hide form

    Hey

    Say I have two <form> on a page like this :

    <form action="private .asp" method="post" name="form1">
    // code
    <input type=submit value="submit" name="submit">
    </form>

    <form action="private 2.asp" method="post" name="form2">
    // code
    <input type=submit value="submit" name="submit">
    </form>

    Is it possible to hide both on form load and then from a drop down menu
    choose which of the two to show ?



  • Yann-Erwan Perio

    #2
    Re: show hide form

    earl wrote:
    [color=blue]
    > <input type=submit value="submit" name="submit">[/color]

    Don't name a "submit" button "submit", you're overriding the js submit
    method for the form (not that you should use it anyway).
    [color=blue]
    > Is it possible to hide both on form load and then from a drop down menu
    > choose which of the two to show ?[/color]

    Certainly, see below. Note however that there are some accessibility
    issues to consider, for instance users deprived from javascript, or
    having non-supporting agents, might not be able to navigate your website.


    <style type="text/css">
    #f1, #f2 {visibility:hid den}
    </style>

    <div id="f1">
    <form action="foo">
    <!-- content goes here -->
    <input type="submit" value="submit 1">
    </form>
    </div>

    <div id="f2">
    <form action="foo">
    <!-- content goes here -->
    <input type="submit" value="submit 2">
    </form>
    </div>

    <form action="#">
    <select onchange="f(thi s)">
    <option value="">---</option>
    <option value="f1">Show form 1</option>
    <option value="f2">Show form 2</option>
    </select>
    </form>

    <script type="text/javascript">
    function f(sel){
    var d=document, dv;
    if(d.getElement ById){
    for(var ii=0; ii<sel.options. length; ii++){
    dv=d.getElement ById(sel.option s[ii].value);
    if(dv)
    dv.style.visibi lity=sel.option s[ii].selected?"visi ble":"hidden";
    }
    }
    }
    </script>


    HTH
    Yep.

    Comment

    • earl

      #3
      Re: show hide form

      "Yann-Erwan Perio" <y-e.perio@em-lyon.com> wrote in message
      news:3faff986$0 $13296$626a54ce @news.free.fr.. .[color=blue]
      > earl wrote:
      >[color=green]
      > > <input type=submit value="submit" name="submit">[/color]
      >
      > Don't name a "submit" button "submit", you're overriding the js submit
      > method for the form (not that you should use it anyway).
      >[color=green]
      > > Is it possible to hide both on form load and then from a drop down menu
      > > choose which of the two to show ?[/color]
      >
      > Certainly, see below. Note however that there are some accessibility
      > issues to consider, for instance users deprived from javascript, or
      > having non-supporting agents, might not be able to navigate your website.
      >
      >
      > <style type="text/css">
      > #f1, #f2 {visibility:hid den}
      > </style>
      >
      > <div id="f1">
      > <form action="foo">
      > <!-- content goes here -->
      > <input type="submit" value="submit 1">
      > </form>
      > </div>
      >
      > <div id="f2">
      > <form action="foo">
      > <!-- content goes here -->
      > <input type="submit" value="submit 2">
      > </form>
      > </div>
      >
      > <form action="#">
      > <select onchange="f(thi s)">
      > <option value="">---</option>
      > <option value="f1">Show form 1</option>
      > <option value="f2">Show form 2</option>
      > </select>
      > </form>
      >
      > <script type="text/javascript">
      > function f(sel){
      > var d=document, dv;
      > if(d.getElement ById){
      > for(var ii=0; ii<sel.options. length; ii++){
      > dv=d.getElement ById(sel.option s[ii].value);
      > if(dv)
      > dv.style.visibi lity=sel.option s[ii].selected?"visi ble":"hidden";
      > }
      > }
      > }
      > </script>
      >
      >
      > HTH
      > Yep.[/color]

      Thanks for the reply.

      One thing though, is it possible to make f1 and f2 overlap ?


      Comment

      • Yann-Erwan Perio

        #4
        Re: show hide form

        earl wrote:
        [color=blue]
        > One thing though, is it possible to make f1 and f2 overlap ?[/color]

        Sure, either position them absolutely or change the display property
        instead of the visibility one. The CSS part becomes something like

        <style type="text/css">
        #f1, #f2 {display:none;}
        form{margin:0}
        </style>

        and the style setting part something like

        dv.style.displa y=sel.options[ii].selected?"bloc k":"none";


        HTH
        Yep.

        Comment

        Working...