How can i Display result in alert box.

Discussion in 'JavaScript' started by Proud Pakistani, Jan 3, 2007.

  1. #1
    Hello All!
    How i can display the results of the input from user using array in a Alert box?
    and i also want to sort it.
    I am new in learing java script, infact i am doing assignemnt, i have tried alot but failed to do so.:cool:
    I am pasting the question here and also the code which i have wrote
    Can anyone please help me in this??????:confused:

    Question:
    You have to develop an interactive page using JavaScript that takes 5 Names in an Array .This page should take 5 Names from the user and then display them in a dialog box. Moreover you have to Sort these names in alphabetical order.
    Your page should have three buttons. The names of buttons and their functionality are described below:
    1. Enter Names: On pressing this button the user should be prompted to give 5 Names one by one.
    2. Sort: On pressing this button, all the names, which have been entered in the prompt box, should be sorted alphabetically.
    3. Show Names: On pressing this button, all the Names that you have entered should be displayed in a dialog box.


    My code

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD><TITLE>My Assignment</TITLE>
    <META http-equiv=Content-Type content="text/html;

    charset=windows-1252">
    <SCRIPT>
    function checkForm()
    {
    var arr = new Array(5)
    arr[0] = window.prompt( "You have to enter five Names.

    --------- Please Enter the first name","A");
    arr[1] = window.prompt( "Enter second name", "A");
    arr[2] = window.prompt( "Enter Third name", "A" );
    arr[3] = window.prompt( "Enter Fourth name", "A");
    arr[4] = window.prompt( "Enter Fifth name", "A");

    }



    function sortNames()
    {
    window.alert("Names have been sorted");
    }



    function showNames()
    {

    window.alert("HELLO!!!!!");
    }
    </SCRIPT>


    <META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
    <BODY>
    <H1 align=center>Array with Events </H1>
    <form name="myForm1">
    <INPUT onclick=checkForm() type=submit value="Enter Names">
    </form>

    <BR><BR>
    <INPUT type=submit value="Sort Names" onclick="sortNames()">
    <BR><BR><BR><BR>

    <form name="myForm2">

    <INPUT type=submit value="Show Names" onclick="showNames()">
    </form>
    </BODY>

    </HTML>




    I will be very thankful
     
    Proud Pakistani, Jan 3, 2007 IP
  2. Proud Pakistani

    Proud Pakistani Peon

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Please Help me out :(
     
    Proud Pakistani, Jan 4, 2007 IP