0

I'm very novice at programming and haven't had any luck in finding a tutorial useful for what I want to do.

I am creating a form that will have 2 drop down selections and then one input box which will produce a price depending on the 2 selections.

For the first drop down it will be a type of event. The second will be a selection of adult, child, or student (each selection has its own set ID). Then I want to produce prices dynamically that will appear in a text box based on the user's selections so something sort of like the following (I'm still figuring out JavaScript so bear with me this will be a poor example):

while eventid == 2
{
    if registration == adult;

        price == 45;

}

Any help would be appreciated.

4

2 に答える 2

1

基本を突き止める必要があるというコメントに同意します-あなたがやろうとしていることとJavaScript自体について。

しかし、これを言って、あなたが説明したことに基づいて、ループはまったく必要ないと思います。イベント タイプは、変更されるまで繰り返される一連のアクションの一時的な条件のようには聞こえません。これは、ループの古典的な基準です。

必要なものは次のようになります。

if (eventid == 2) {
    if (registration == 'adult') {
        price = 45;
    } else if (registration == 'child') {
        price = 15; // or whatever
    }// else if... // more registration conditions
} else if (eventid == 3) { // or whatever
    if (registration == 'adult') {
        price = 55; // or whatever
    } else if (registration == 'child') {
        price = 20; // or whatever
    }// else if... // more registration conditions
}// else if... // more eventid conditions  
于 2013-05-13T03:00:14.263 に答える
0

ループが必要だとは思いません。探しているロジックは、「登録が大人でイベント ID が 2 の場合、価格を 45 に設定する」のような if ステートメントだけだと思います。それで:

if(eventid == 2){
    if(registration == 'adult')
        price = 45;
    if(registration == 'child')
        price = 35;
}

目的に応じて、使用する論理構造の組み合わせはいくつでもある可能性があります。イベント ID がたくさんある場合は、switch ステートメントが思い浮かびます。

于 2013-05-13T02:55:10.170 に答える