SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict rwar's Avatar
    Join Date
    Sep 2001
    Location
    PF / RS / BR
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    two events in same form

    Can I have two events in the same form? I'm trying to validate some fields (one event) and get the value of this list box (another one). I tried to put both in the form1_check, but it didn't work (because are different events? Maybe.). My code:

    PHP Code:
    <SCRIPT LANGUAGE="javascript">

    function form1_check()
    {
        var obj = document.form1;
        if( obj.nda.value == "" )
        {
            alert( "Digite um valor para o campo NDA!" );
            obj.nda.focus();
            return false;
        }

        if( isNaN( parseInt( obj.nda.value )))
        {
            alert( "O campo deve conter somente números!" );
            obj.nda.focus();
            obj.nda.select();
            return false;
        }

        if( obj.cad[0].selected == true )
        {
            alert( "Escolha um valor para o campo CAD!" );
            obj.cad.focus();
            return false;
        }

        return true;
    }

    </SCRIPT>

    </HEAD>

    <BODY BGCOLOR="BLACK" TEXT="#00CCAA">
    <BR>
    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
        <TR>
        <TD WIDTH="35%">&nbsp;</TD>

        <TD><H2><I><CENTER>Balanço Hídrico Mensal</CENTER></I></H2>
        
        <FORM METHOD="POST" ACTION="<?php echo $cidades?>" NAME="form1">

        <B>NDA: </B><INPUT TYPE="text" NAME="nda" SIZE=4 MAXLENGTH=3><BR><BR>

        <B>CAD: </B>
        <SELECT NAME="cad" SIZE="1">
            <OPTION VALUE="#" SELECTED>Selecione um valor!</OPTION>
                <OPTION VALUE=50>50</OPTION>
                <OPTION VALUE=100>100</OPTION>
                <OPTION VALUE=150>150</OPTION>
                <OPTION VALUE=200>200</OPTION>
        </SELECT><BR><BR>

        <B>Selecione um município </B>
        <SELECT NAME="cidades" SIZE="1">
            <OPTION VALUE="passo_fundo.php">Passo Fundo</OPTION>
            <OPTION VALUE="santa_maria.php">Santa Maria</OPTION>
        </SELECT><BR><BR>

        <INPUT TYPE="button" VALUE="Obter informações!" 
        onClick="document.location = document.form1.cidades.options[document.form1.cidades.selectedIndex].value;
    " onSubmit = "form1_check()">
        </FORM>
        
        </TD>
        </TR>
    </TABLE>

    </BODY>
    </HTML>
    Any help?
    php? mysql? apache? That's it.

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes you can have multiple events. Events tend to be one of javascripts strongest points imo. Since explaining the theory behind events would require a large article I will send you to an article to get you started.

    http://www.webreference.com/js/column74/

    That article leads to other articles for different browsers (each browser handles event differently) But with that article you can control timing of the event and which events do what.

    Best of luck
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •