#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Posts
    11
    Rep Power
    0

    javascript hell = if this and this happens then do this


    okay im building a form that asks if its for 1 or 2 people. If they click on 2 people then with javascript the form opens up some more details.

    Now the problem I am trying to get javascript to validate the form and make stuff has been entered.

    How do I tell javascript that if the form is displaying certain fields then check those fields and if it isnt displaying those fields then don bother checking it.

    Heres the code


    <script type=text/javascript>
    // _w : which ID (1) or (2)
    // _h : (h)ide or (s)how
    function toggleT(_w,_h) {
    if (document.all) { // is IE
    if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
    if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
    } else { // is NS?
    if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
    if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
    }
    }
    </script>

    <!-- START OF SIGNLE QUOTE CODE -->
    <script>
    <!--
    function validateform()
    {
    // validate name
    if ((document.lifesearch.name.value==""))
    {
    window.alert ("Please enter your name");
    document.lifesearch.name.focus();
    return false;
    }

    // validate telephone
    if ((_h=='s') && (document.lifesearch.Daytime_Telephone.value==""))
    {
    window.alert ("enter phone");
    document.lifesearch.Daytime_Telephone.focus();
    return false;
    }
    }
    //-->
    </script>


    <form>
    Visible <input name="r1" type="radio" checked value="" onClick="toggleT('divt1','s')">
    Hidden <input name="r1" type="radio" value="" onClick="toggleT('divt1','h')">
    </form>




    <form action="/cgi-bin/formmail" method="post" name="lifesearch" id="lifesearch" onSubmit="return validateform( this.form )">
    <input type="hidden" name="subject" value="Life">
    <input type="hidden" name="recipient" value="stuart@brokenworld.org">

    <input type="hidden" name="title" value="Thank you for your comments">
    <input type="hidden" name="required" value="">
    <input type="hidden" name="redirect" value="/form_replys/life_thankyou_index.shtml">
    <input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT">

    Daytime Telephone Number <input type="text" size="15" name="name">



    <span id="divt1" style="visibility:visible;position:relative;top:0;left:0">
    <form action="" name="dropdown" id="dropdown">
    drop down works <input type="text" size="15" name="Daytime_Telephone">

    </span>














    <div align="right"><input type="image" name="submit" src="/images/btn_submit.gif" value="Submit Form" value="Submit" border="0" id="life" onSubmit="return validateform( this.form )"></div>

    </form></form>
    <!-- END OF SIGNLE QUOTE CODE -->
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Check if value="" && visibility="visible/show"
    Right now _h is local to your toggle function. Need to make it global.
    Last edited by bricker42; May 9th, 2002 at 09:22 PM.

IMN logo majestic logo threadwatch logo seochat tools logo