create a multiline alert message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vjsv2007
    New Member
    • Oct 2007
    • 2

    create a multiline alert message

    Can you help to make one alert with all details?

    [CODE=javascript]<script type="text/javascript">

    <!--

    function validate_form ( )
    {
    valid = true;

    if ( document.form.n ame.value == "" )
    {
    alert ( "Please fill in the 'Your Name' box." );
    valid = false;
    }

    if ( ( document.form.g ender[0].checked == false ) && ( document.form.g ender[1].checked == false ) )
    {
    alert ("Please choose gender" );
    valid = false;
    }
    if ( document.form.a ge.selectedInde x == 0 )
    {
    alert ("Please select your age." );
    valid = false;
    }
    if ( document.form.t erms.checked == false )
    {
    alert ( "Please check the Terms & Conditions box." );
    valid = false;
    }

    return valid;
    }

    //-->

    </script>
    [/CODE]


    Full details here


    [HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitl ed Document</title>

    <script type="text/javascript">

    <!--

    function validate_form ( )
    {
    valid = true;

    if ( document.form.n ame.value == "" )
    {
    alert ( "Please fill in the 'Your Name' box." );
    valid = false;
    }

    if ( ( document.form.g ender[0].checked == false ) && ( document.form.g ender[1].checked == false ) )
    {
    alert ("Please choose gender" );
    valid = false;
    }
    if ( document.form.a ge.selectedInde x == 0 )
    {
    alert ("Please select your age." );
    valid = false;
    }
    if ( document.form.t erms.checked == false )
    {
    alert ( "Please check the Terms & Conditions box." );
    valid = false;
    }

    return valid;
    }

    //-->

    </script>

    </head>

    <body>
    <form id="form" name="form" method="post" action="" onSubmit="retur n validate_form ( );">
    <table width="500" border="1" align="center">
    <tr>
    <td>Your Name</td>
    <td>:</td>
    <td>
    <input name="name" type="text" id="name" /> </td>
    </tr>
    <tr>
    <td>Your Gender</td>
    <td>:</td>
    <td><label>
    <input type="radio" name="gender" id="Male" value="Male" />
    </label>
    Male
    <label>
    <input type="radio" name="gender" id="Female" value="Female" />
    Female</label></td>
    </tr>
    <tr>
    <td>Your Age</td>
    <td>:</td>
    <td><label>
    <select name="age" id="age">
    <option>Slect your age</option>
    <option value="0-16">0-16</option>
    <option value="17-20">17-20</option>
    <option value="21-30">21-30</option>
    <option value="31-40">31-40</option>
    <option value="41-50">41-50</option>
    <option value="51-60">51-60</option>
    </select>
    </label></td>
    </tr>
    <tr>
    <td>Do you agree the terms and coditions</td>
    <td>:</td>
    <td><label>
    <input name="terms" type="checkbox" id="terms" value="Yes" />
    Yes
    <input name="terms2" type="checkbox" id="terms2" value="no" />
    No</label></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><label>
    <input type="submit" name="submit" id="submit" value="Submit" />
    </label></td>
    </tr>
    </table>
    </form>
    </body>
    </html>[/HTML]
    Last edited by gits; Oct 11 '07, 12:31 PM. Reason: added code tags
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Be Specific about your Problem.
    And read out the Posting Guidelines before do Post.

    Debasis Jnaa

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      hi ...

      welcome to TSDN ...

      changed thread title ... please always use a good thread title

      kind regards

      Comment

      • vjsv2007
        New Member
        • Oct 2007
        • 2

        #4
        How to create alert only sinlge submit?

        Here I have tried javascript for validation a form, If I submit the form the alert msg are coming one by one. I do not like this way. can you solve this one alert display all required details ?


        [CODE=javascript] <script type="text/javascript">
        <!--
        function validate_form ( )
        {
        valid = true;
        if ( document.form.n ame.value == "" )
        {
        alert ( "Please fill in the 'Your Name' box." );
        valid = false;
        }

        if ( ( document.form.g ender[0].checked == false ) && ( document.form.g ender[1].checked == false ) )
        {
        alert ("Please choose gender" );
        valid = false;
        }
        if ( document.form.a ge.selectedInde x == 0 )
        {
        alert ("Please select your age." );
        valid = false;
        }
        if ( document.form.t erms.checked == false )
        {
        alert ( "Please check the Terms & Conditions box." );
        valid = false;
        }

        return valid;
        }

        //-->
        </script>[/CODE]
        Last edited by gits; Oct 11 '07, 06:10 PM. Reason: added code tags

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          threads merged ... please don't double post your questions on the same topic ...

          to your problem: let me give you an example ...

          [CODE=javascript]// create an empty message-string
          var message = '';

          // create a suffix that represents a linebreak
          var lb = '\n';

          // add a line
          message += 'whatever text you want here' + lb;

          // add one more line
          message += 'second line is here';

          alert(message);
          [/CODE]
          try to adapt that for your problem and post back in case you have problems with it

          kind regards

          Comment

          • mrhoo
            Contributor
            • Jun 2006
            • 428

            #6
            [CODE= javascript]function validate_form() {
            var valid= [];
            if ( document.form.n ame.value== "" ) {
            valid.push( " fill in the 'Your Name' box.") ;
            }
            if ( ( document.form.g ender[0].checked== false ) && ( document.form.g ender[1].checked== false ) ) {
            valid.push(" choose gender");
            }
            if ( document.form.a ge.selectedInde x== 0 ) {
            valid.push(" select your age." );
            }
            if ( document.form.t erms.checked== false ) {
            valid.push( "check the Terms & Conditions box." );
            }
            if(valid.length == 0)return true;
            else alert('Please '+valid.join('\ n\t');
            return false;
            }[/CODE]

            Comment

            Working...