Transforms letters into numbers with a function

0

I am developing a code that consists of taking a letter and transforming it into a corresponding number (Example A-> 1, B-> 2 ...), and that letter is received through% .

I found a topic that helped me in the conversion part of these values here: Function that lists alphabet letters

However, I need to know how to perform this calculation with the letters that the user types

For the time being my code looks like this:

index.php

<html> 
<head> 
    <title> Leituras de Dados Excel </title>
</head>
    <body>
        <form action="excel.php" method="post">
            <div style="background-color:blue; height:130px; width:190px; position:absolute; top: 250px; left:600px;">
                <br>
                    <input id="1" name="coord1" type="text" class="input" style="position:relative; left:10; height:50px; width:50px; font-size:30px; text-transform: uppercase; text-align:center;" maxlength="1">
                    <input id="2" name="coord2" type="text" class="input" style="position:absolute; left:70; height:50px; width:50px; font-size:30px; text-transform: uppercase; text-align:center;"maxlength="1">
                    <input id="3" name="coord3" type="text" class="input" style="position:absolute; left:130; height:50px; width:50px; font-size:30px; text-transform: uppercase; text-align:center;"maxlength="1">
                <br>
                <br>
                <input type="submit" value="Converter" style="position:relative; left:55;">
            </div>
        </form>
    </body>
</html>

excel.php

<?php
    $coord1 = $_REQUEST['coord1'];
    $coord2 = $_REQUEST['coord2'];
    $coord3 = $_REQUEST['coord3'];

    $coordenadaFinal = $coord1."-".$coord2."-".$coord3;    
?>

<html>
<head><tile>Resultado</tile>
    <script type="text/javascript">
        function primeira(){
            function converte(letras) {
                var alfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                var codigos = [];
                for (var i in letras) {
                    codigos.push(alfabeto.indexOf(letras[i].toUpperCase()) + 1);
                }
                return codigos;
            }

            resultado = converte("l");
                for (var i in resultado) {
                    alert(resultado);

                }
        } // fim da function geral 

        function segunda(){
                    function converte(letras) {
                        var alfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                        var codigos = [];
                        for (var i in letras) {
                            codigos.push(alfabeto.indexOf(letras[i].toUpperCase()) + 27);
                        }
                        return codigos;
                    }

                    resultado = converte("l");
                        for (var i in resultado) {
                            alert(resultado);

                        }
                } // fim da function geral 

        function terceira(){
                    function converte(letras) {
                        var alfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                        var codigos = [];
                        for (var i in letras) {
                            codigos.push(alfabeto.indexOf(letras[i].toUpperCase()) + 703);
                        }
                        return codigos;
                    }

                    resultado = converte("o");
                        for (var i in resultado) {
                            alert(resultado);

                        }
                } // fim da function geral 

    </script>   
</head>
    <body>
        <div id="resposta" style="background-color:blue; height:130px; width:190px; position:absolute; top: 250px; left:600px; font-size:30px; color:white;"> 
            <p>Você inseriu:</p>
            <p><?php echo strtoupper($coordenadaFinal) ; ?></p>
            <input type="button" value="Voltar" onclick="javascript: location.href='index.php';" >
            <input type="button" value="Mostrar valor 1" onclick="primeira()" >
            <input type="button" value="Mostrar valor 2" onclick="segunda()" >
            <input type="button" value="Mostrar valor 3" onclick="terceira()" >

        </div>
    </body>

</html>

Everything is working correctly, it gets the variables that I should treat at first, and it executes input text with the values that I set correctly inside function , however I'm not able to move to the value of the function a letter that the user typed and that is stored in resultado = converte("alguma letra"); , cood1 and coord2 .

I have tried some things like: result = convert ("coord1"); result = convert (coord1); result = convert ($ _ REQUEST ['coord1']);

But I did not succeed in any of them ... Thanks in advance:)

    
asked by anonymous 30.11.2016 / 19:12

0 answers