Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8277827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:48:27+00:00 2026-06-08T08:48:27+00:00

<input type=text name=importo_estratto /> <input type=text name=numeri_giocati /> <input type=submit id=submit name=submit /> $(document).ready(function()

  • 0
    <input type="text" name="importo_estratto" />
    <input type="text" name="numeri_giocati" />
    <input type="submit" id="submit" name="submit" />
$(document).ready(function() {
    $('input[name=submit]').click(function() {
        var importo_estratto = $('input[name=importo_estratto]').val();
        var numeri_giocati = $('input[name=numeri_giocati]').val();

        // ESTRATTO
        if (importo_estratto != '') {
            switch(numeri_giocati) {
                case 1: paga = 11.23; break;
                case 2: paga = 5.62; break;
                case 3: paga = 3.74; break;
                case 4: paga = 2.81; break;
                case 5: paga = 2.25; break;
                case 6: paga = 1.87; break;
                case 7: paga = 1.60; break;
                case 8: paga = 1.40; break;
                case 9: paga = 1.25; break;
                case 10: paga = 1.12; break;
            }

            /*if (numeri_giocati == 1) {
                var paga = 11.23;
            } else if (numeri_giocati == 2) {
                var paga = 5.62;
            } else if (numeri_giocati == 3) {
                var paga = 3.74;
            } else if (numeri_giocati == 4) {
                var paga = 2.81;
            } else if (numeri_giocati == 5) {
                var paga = 2.25;
            } else if (numeri_giocati == 6) {
                var paga = 1.87;
            } else if (numeri_giocati == 7) {
                var paga = 1.60;
            } else if (numeri_giocati == 8) {
                var paga = 1.40;
            } else if (numeri_giocati == 9) {
                var paga = 1.25;
            } else if (numeri_giocati == 10) {
                var paga = 1.12;
            }*/

            alert(paga);
        } else {
            var tot_estratto = 0;
        }
        return false;
    });
});

I need your help.
I don’t know why, but the IF works and the SWITCH not.
The alert outputs “undefined” instead of the value “paga”, but everything seems to be ok for me.

Can someone help me, please?
Thank you very much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:48:29+00:00Added an answer on June 8, 2026 at 8:48 am

    Algorithmic Solution

    Nobody has noticed that, with the stated values of paga, an algorithmic solution is available.

    For numeri_giocati > 0, the value of paga is given by the formula:

    • paga = 11.23 / numeri_giocati

    Here’s my verification that the algorithm gives the correct values (to 2 decimal places over the range numeri_giocati = 1 to 10).

    The algorithm can be implemented with a javascript function genPaga(seme, n), where seme is the seed (or scalar) value 11.23, and n is a positive integer.

    The code in the question thus becomes :

    $(document).ready(function() {
        function genPaga(seme, n) {
            return (seme / n).toFixed(2);
        }
    
        $('input[name=submit]').click(function() {
            var importo_estratto = $('input[name=importo_estratto]').val();
            var numeri_giocati = parseInt($('input[name=numeri_giocati]').val(), 10);
            var paga, tot_estratto;//??
            if (importo_estratto != '' && !isNaN(numeri_giocati) && numeri_giocati >= 1) {
                paga = genPaga(11.23, numeri_giocati);
            } else {
                tot_estratto = 0;
            }
            return false;
        });
    });
    

    The advantage of this approach is that you’re not limited to the range of values hard-coded in a switch/case statement. Say one day you wish to cater for numeri_giocati = 11, 12, 13 etc. The algorithm will handle that automatically. The function genPaga() is also available to be called elsewhere in the code if necessary.

    The limitation is that you are bound by the algorithm. If an algorithm were not available (or could not be deduced), then a switch/case may be the only alternative.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<form action = settings.php method = post> Student ID*: <input type = text name
Here's an example of what I mean: I have an array: array('type'=>'text', 'class'=>'input', 'name'=>'username',
I have an input type file element: <input type=file name=val1 /> And jquery: $(input[name='val1']).off(click);
Hi in my input type text I want to call URL if user enters
I have an input of type text , from which I have already entered
I have the following HTML: <input type=email id=email> I want to type text into
I have an INPUT element of the TEXT type and I want to perform
How can I format a users text field input as they type and insert
I just wanted to ask. I have text input to allow users to type
To be specific, I'm talking about avoiding this type of code: <input type='text' id='title_33'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.