Javascript does not recognize "Certain chains"?

0

I have a button (MODIFY) that when you press it puts in an input type = text the input value of a form.

It does fine with normal numbers , but not with numbers 1B: 3B: 3B: 4B: 5B: 6B or with 1C-3C-3C-4C-5B -6B It does not even enter the javascript function to say alert ("hello"); but if they are numbers "80" - "5" it does well.

@foreach($datos_usuario as $value) 
            <tr>
            <form action="Borrar_mac" id="idformac_usu" name="formac_usu" method="POST" >
                {!! csrf_field(); !!}
                <td><input type="text" name="txtdireccion_mac" readonly="readonly" value="{!! $value->Direccion_mac !!}" readonly></td>
                <td><input type="text" name="txt_descripcion" readonly="readonly" value="{!! $value->Descripcion !!}"  readonly></td>
                <td><input type="text" name="txtfecha" readonly="readonly" value=" {!! $value->Fecha !!} "  readonly></td>

           AQUÍ--->     <td><input type="button" name="modificar" onclick="cambiarMac({!! $value -> Direccion_mac !!})" value="Modificar Mac" ></td>
                <td><input type="submit" name="btn_borrar" value="Borrar Mac"></td>

            </form>
        </tr>   
        @endforeach   
  </table>

   <!--    Modificar    -->     

    <div id='formulario_cambio_mac'>
        <form action='cambiar_datos_mac' id="idform_cambiar" method='POST'>
        </form>
    </div>

Javascript

 function cambiarMac(mac){
                alert("entro");
                var txt1 = '{!! csrf_field(); !!}';
                txt1 += "<input type='hidden' name='identificador_mac' id='id_identificadormac' value=''>";
                txt1 += "<label for='nueva_mac'>Modifica la Mac <input type='text' name='nuevatxtmac' id='id_cambiar_mac' value='' onblur='comprobar_formato_mac(this,mod);' required></label><br/>";
                txt1 += "<label for='nueva_descripcion'>Escribe la Descripcion  <input type='text' name='txtdescripcion' id='iddescripcion' value='' required></label><br/>";
                txt1 += "<input type='submit' name='btn_enviar' value='Cambiar Mac'>";
                txt1 += "<input type='button' name='btn_no_hacer' onclick='No_realizar();' value='No realizar'>";

                document.getElementById("idform_cambiar").innerHTML = txt1;
                document.getElementById('id_identificadormac').value = mac;
                document.getElementById('id_cambiar_mac').value = mac;
            }
    
asked by EduBw 02.12.2017 в 19:31
source

1 answer

1

I understand that the problem is when passing the values from php in:

onclick="cambiarMac({!! $value -> Direccion_mac !!})"

if you pass a numeric value such as 48 it would look like:

onclick="cambiarMac(48)"

leaving a valid javascript instruction that calls the function cambiarMac with a numeric argument 48 .

But if you pass a value like the one you mention for example 1B:3B:3B:4B:5B:6B , it would be:

onclick="cambiarMac(1B:3B:3B:4B:5B:6B)"

what javascript will not recognize as a valid value. If the value is not always going to be numeric you should pass it as a string (adding quotation marks):

onclick="cambiarMac('{!! $value -> Direccion_mac !!}')"

in this way it would look like

onclick="cambiarMac('1B:3B:3B:4B:5B:6B')"

which will be interpreted as a valid value.

    
answered by 02.12.2017 / 19:38
source