Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-23-2009, 06:20 AM   PM User | #1
ryukenblaze
New Coder

 
Join Date: Feb 2009
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
ryukenblaze is an unknown quantity at this point
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
}
ryukenblaze is offline   Reply With Quote
Old 02-23-2009, 06:52 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,178
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 02-23-2009, 10:21 PM   PM User | #3
ryukenblaze
New Coder

 
Join Date: Feb 2009
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
ryukenblaze is an unknown quantity at this point
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
ryukenblaze is offline   Reply With Quote
Reply

Bookmarks

Tags
array, display, javascript, select

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:06 PM.


Advertisement
Log in to turn off these ads.