reset password
Author Message
smahbub2
Posts: 12
Posted 21:52 May 13, 2015 |

Hey, can anyone help me fix my html code. I have the first name and last name portion of the lab finished, but I can't fix the part of the lab where I need people to submit the row number and column number. The row is fine, but I can't fix the column section of it. If anyone could check and help me fix it, I'd be really grateful. Here it is:

 

<p>Please input a number between 2 and 15:</p>

            <input id="rownumb" type="number">

            <button type="button" onclick="rowFunction()">Submit</button>

            <p id="numberofrows"></p>
            
            <hr width="100%">
            
        <p>Please input a number between your ROW# and 20:</p>

            <input id="colnumb" type="number">

            <button type="button" onclick="colFunction()">Submit</button>

            <p id="numberofcolumns"></p>

            <script>{
                function rowFunction() {
                var x, text;
                x = document.getElementById("rownumb").value;
                if (isNaN(x) || x < 2 || x > 15) {
                text = "Your input is either too high or too low. Please input a value between 2 and 15.";
                } else {
                text = ("Input OK, your ROW# is " + x );
                }
                document.getElementById("numberofrows").innerHTML = text;
                }

                function colFunction() {
                var y, text;
                y = document.getElementById("colnumb").value;
                if (isNaN(y) || y < x || y > 20) {
                text = "Your input is either too high or too low. Please input a value between your ROW# and 20.";
                } else {
                text = ("Input OK, your COLUMN# is " + y );
                }
                document.getElementById("numberofcolumns").innerHTML = text;
                }
                }

            </script>    

Last edited by smahbub2 at 23:00 May 14, 2015.
cesar714
Posts: 30
Posted 22:23 May 13, 2015 |

The reason it is not working is because you created functions. A variable only exists inside its function. In the column function you are using the variable x, in the column function this variable does not exist. In order for your code to work you must carry the variable along with its value to the column function from your row function.

 

Also, on your if statement I don't think he wants an if statement that determines whether the value is too low and/or too high. I think he is asking for and if statement that determines whether one value is too low and a separate one where the value is too high

 

I think this is what he means. For example,

if(less than){}

else if(greater than){}

For example,

I don't think he means. For example, 

if(less than or greater than){}

smahbub2
Posts: 12
Posted 23:02 May 14, 2015 |

Thank you for your help. It was the functions, I got rid of it and did separate var elements and now it's working.

cesar714
Posts: 30
Posted 04:17 May 15, 2015 |

No problem glad to help. Goodluck.