How do I get a user's input into an array?

I’m adding the ability for the user to input his own values into 6 input fields, some or all of which may be left blank. I have already an array populated (thanks to Paul Wilkins) with default values. How do I get the user’s values into that array so the calculations will be performed on it?

I got this far, but was unable to understand the problems brought up by

User input:

                            Alternate spur values:
                            <input class="display3" type="number" size="14" value="" name="spur1"><br>
                            <input class="display3" type="number" size="14" value="" name="spur2"><br>
                            <input class="display3" type="number" size="14" value="" name="spur3"><br>
                            <input class="display3" type="number" size="14" value="" name="spur4"><br>
                            <input class="display3" type="number" size="14" value="" name="spur5"><br>
                            <input class="display3" type="number" size="14" value="" name="spur6"><br>

Javascript array:

            function gearSpurs(ratio) {
            var form = document.getElementById('formGearRatio');
            var spur1 = form.elements.spur1.value,
                spur2 = form.elements.spur2.value,
                spur3 = form.elements.spur3.value,
                spur4 = form.elements.spur4.value,
                spur5 = form.elements.spur5.value,
                spur6 = form.elements.spur6.value;

            var userSpurs[spur1, spur2, spur3, spur4, spur5, spur6];

                var spurs = [];

                // establish the array of spurs to calculate
                switch (ratio) {
                    case 'sc10_4x4':
                    spurs = ['58', '60', '62', '93'];
                    case 'sc10':
                    spurs = ['75', '78', '81', '84', '87'];
                    case 'sc8':
                    spurs = ['50', '52', '54'];
                    case 'b44':
                    spurs = ['72', '75', '78', '81', '84'];
                    case 'b4t4':
                    spurs = ['72', '75', '78', '81', '84', '87'];
                    case 'gt2':
                    spurs = ['54', '55', '56'];
                    case 'userSpurs':
                    spurs = [spur1, spur2, spur3, spur4, spur5, spur6];
                    spurs = ['72', '75', '78', '81', '84', '87'];
                return spurs;


make that form’s action go to a php page.

EX: <form action=“action.php” method=“post” >

Have the php code simply put all the values in separate variables.

$spur1 = $_POST[‘spur1’];
$spur2 = $_POST[‘spur2’];

Now that you have this set up in php, make the html section. This will work because php renders/compiles before the page is loaded, so the javascript just sees the variables as straight up text or strings, and acts like you just typed them directly in there.

<script type=“text/javascript”>

var spur = new Array();
spur[0] = <?php echo $spur1; ?>;
spur[1] = <?php echo $spur2; ?>;
//After all this, you now have an array to use in javascript as you please.


This may be too much in a different direction than you wanted, or you may not even have php running on the server you’re using, so don’t assume this is the only way to do this. This is just the way I would suggest you go, if you have php of course.

Thanks for the help, but I can’t use PHP for this application. I don’t see how to get the values of the array from within a Switch context so it fits in with the rest of the Switch statement.

This issue has been solved.