SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict rwar's Avatar
    Join Date
    Sep 2001
    PF / RS / BR
    0 Post(s)
    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!" );
            return false;

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

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

        return true;



        <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>

        <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>

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

    Any help?
    php? mysql? apache? That's it.

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Whistler BC originally from Guelph Ontario
    0 Post(s)
    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.

    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.


Posting Permissions

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