Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Select list will not display

    I've managed to fill a select elements option with a javascript array. Now I want it to display what the user selected in an alert window when he/she hits submit. I'm at wits end here can anybody help? here is my code:
    <script language="JavaScript">
    <!-- // JavaScript Week 6 Homework: Pizza D'Action

    var choose = new Array(); // when the page is loaded, declare a variable as an Array
    // add code here, to create the Array that will be used to create the Select
    choose[0] = "check"
    choose[1] = "money order"
    choose[2] = "visa"
    choose[3] = "master card"
    choose[4] = "AMEX"
    choose[5] = "cash"
    choose[6] = "other"
    function seeForm(){ {
    // add code here, to loop through all buttons in pdel (pickup or delivery) and show which was selected

    // loop through all buttons in agegroup
    for( var i=0; i<(document.forms[0].pdel.length); i++ ) {
    if(document.forms[0].pdel[i].checked) {
    alert("You selected " + document.forms[0].pdel[i].value);
    }
    }
    }

    // add code here, to show which option was selectd in the Select payby (payment method)
    if (choose[0] == true ){
    alert("you chose check");
    }

    else if (payby == "money order" ){
    alert("you chose money order");
    }

    else if (payby == "visa" ){
    alert("you chose visa");
    }

    else if (document.forms[0].pdel[i].checked) {
    var del = document.forms[0].pdel[i].value;
    alert("Delivery method: " + del + "\nPayment Method: " + payby );
    makeWin();}


    } // end of function seeForm()
    //-->
    </script>


    <td><SELECT name="payby" >
    <script language="JavaScript">
    <!-- // this will execute when the page is loaded, and build the select statement

    for( var i=0; i < choose.length; i++ ) // a loop, will execute for each entry in array choose
    {
    document.write("<OPTION>"+choose[i]); // "write" into the Select statement, the HTML to create an Option for this entry in array choose
    }

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    Code:
    alert( "For PayBy, you selected: " +
            document.forms[0].payby.options[document.forms[0].payby.selectedIndex].text );
    No "if" tests wanted or needed. No loop wanted or needed.

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thanks

    Thank you, it works perfectly now
    there were no references anywhere about how to do this online.
    Last edited by ryukenblaze; 02-23-2009 at 10:23 PM. Reason: unfinished thought


  •  

    Tags for this Thread

    Posting Permissions

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