I have a question about the type of words detected by the parameters

1

I noticed something interesting for me that I'm new and it's that I was doing a function in javascript to call it and use it with the event onclick , then when putting the event in the HTML code and put onclick="function("mibg")" a parameter with any name. the code gives me an error that the parameter mibg does not exist, but if instead I give it another word like this , if it works.

Then I would like to know if it only detects a word like parameters the events or why this happens ?. thank you very much

    <html>
    <head>
        <meta charset="utf-8">
        <title>Calculadora Personal </title>
    <link rel="stylesheet" href="css/calculadora_personal.css">
    </head>
<body id="todo">
    <div>
    <center>
    <table border="0" width="250px" height="60" id="operaciones">
     <tr>
       <td height="50px" colspan="4"><label for="operador"></label>
       <input type="text" name="operador" id="pantalla" value=""></td>    
    </tr>
    <tr>
        <td class="cuadros"><input type="button" value="1" name="boton" class="boton" onclick="ingresa_dato(this)"></td>
        <td class="cuadros"><input type="button" value="2" name="boton" class="boton" onclick="ingresa_dato(this)"></td>
        <td class="cuadros"><input type="button" value="3" name="boton" class="boton" onclick="ingresa_dato(this)"></td>
        <td class="cuadros"><input type="button" value="+" name="boton" class="boton" onclick="operaciones(this)"></td>
    </tr>
     <tr>
        <td class="cuadros"><input type="button" value="4" name="boton" class="boton" onclick="ingresa_dato(this)"></td>
        <td class="cuadros"><input type="button" value="5" name="boton" class="boton" onclick="ingresa_dato(this)"></td>
        <td class="cuadros"><input type="button" value="6" name="boton" class="boton" onclick="ingresa_dato(this)"></td>
        <td class="cuadros"><input type="button" value="-" name="boton" class="boton" onclick="operaciones(this)"></td>
    </tr>
    <tr>
        <td class="cuadros"><input type="button" value="7" name="boton" class="boton" onclick="ingresa_dato(this)"></td>
        <td class="cuadros"><input type="button" value="8" name="boton" class="boton" onclick="ingresa_dato(this)"></td>
        <td class="cuadros"><input type="button" value="9" name="boton" class="boton" onclick="ingresa_dato(this)"></td>
        <td class="cuadros"><input type="button" value="*" name="boton" class="boton" onclick="operaciones(this)"></td>
    </tr>
    <tr>
        <td class="cuadros"><input type="button" value="clr" name="boton" class="boton" onclick=""></td>
        <td class="cuadros"><input type="button" value="0" name="boton" class="boton" onclick="ingresa_dato(this)"></td>
        <td class="cuadros"><input type="button" value="=" name="boton" class="boton" onclick="resultado('res')"></td>
        <td class="cuadros"><input type="button" value="/" name="boton" class="boton" onclick="operaciones(this)"></td>
    </tr>
    </table>
    </center>
        </div>
    <script src="js/Calculadora_personal.js"></script>
    </body>
</html>

    var valor = document.getElementById("pantalla");

function ingresa_dato(obj){

    valor.value += obj.value;
    console.log(obj.value);
}

function operaciones(ope) {

    var operacion = 

    valor.value += ope.value;

    console.log(valor.value);

}

function resultado(resultado){



}
    
asked by maxwell salazar 06.08.2018 в 02:51
source

1 answer

1

I'll give you an example so you can better understand how you should handle the use of the function you indicate

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<button onclick="saludos('alfredo')">Hola</button>
<script>
    function saludos(name){
      alert(name);
    }
</script>
</body>
</html>
  

Single quotes are necessary because the interpreter knows that   is going to wait for example an value that is entered in chain format   text

     

On the other hand, if the value is numeric or a browser object is not   must go in quotes, I invite you in my example to install   "alfredo" for 2 so are quotes and the same will work

  

Now for that parameter to work and be read, you have to   assign to a variable in the body of the function, in my example it   I put name, by doing that the interpreter knows that he must wait for a value   dynamic that at the moment of making a click name will be exchanged for   a text string that now says "alfredo"

EXAMPLE WITH A NUMERICAL VALUE

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<button onclick="saludos(2)">Hola</button>
<script>
    function saludos(numero){
      alert(numero);
    }
</script>
</body>
</html>

EXAMPLE WITH THE WINDOW OBJECT

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<button onclick="saludos(window)">Hola</button>
<script>
    function saludos(element){
      alert(element);
    }
</script>
</body>
</html>
    
answered by 06.08.2018 / 03:03
source