0

al poner algo en data= en la etiqueta img, te convierte a código de barras.

como hago que lo que tenga el input se pase a ese data?

hice un script pero no tengo ni idea de como pasarlo.

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
	
<body>
 <table>
 	<div id="h">
	<tr>
		<td style='padding:10px; text-align:center; font-size:15px; font-family:Arial,Helvetica;'>
			<br/>
		</td>
		<td>
			<label>Ingrese el documento que desea convertir</label>
            <input type="text" name="texto" id="texto">
			<img src='https://barcode.tec-it.com/barcode.ashx?data=&code=Code128&multiplebarcodes=false&translate-esc=false&unit=Fit&dpi=96&imagetype=Gif&rotation=0&color=%23000000&bgcolor=%23ffffff&qunit=Mm&quiet=0' alt='Barcode Generator TEC-IT'/>
			<button onclick="convertir()">convertir</button>
		</td>
	</tr>
	</div>
</table>
<script type="text/javascript">
		function convertir() {
			alert("Hello World!");
			var conv = document.getelementbyid('texto').value;

		}
	</script>
</body>

</html>

2
  • que tal si cambias el getelementbyid por getElementById el 12 sep. 2019 a las 16:48
  • Como dice Jack, JavaScript es sensible a mayúsculas y minúsculas.
    – Roxgüel
    el 12 sep. 2019 a las 17:09

2 respuestas 2

1

Lo que necesitas hacer es escribir bien la propiedad getElementById, y con eso tomara el valor de tu input.

Lo que después necesitas hacer es asignarle un id o una clase a tu imagen para poder asignarle un nuevo atributo src al dar click en el boton.

Y por ultimo solo concaternarle el valor de tu input al valor del src que le vas a dar a la imagen, por ejemplo:

<!DOCTYPE html>
<html>

<head>
    <title></title>
</head>

<body>
    <table>
        <div id="h">
            <tr>
                <td style='padding:10px; text-align:center; font-size:15px; font-family:Arial,Helvetica;'>
                    <br/>
                </td>
                <td>
                    <label>Ingrese el documento que desea convertir</label>
                    <input type="text" name="texto" id="texto">
                    <img id="myImg" src="https://barcode.tec-it.com/barcode.ashx?data=&code=Code128&multiplebarcodes=false&translate-esc=false&unit=Fit&dpi=96&imagetype=Gif&rotation=0&color=%23000000&bgcolor=%23ffffff&qunit=Mm&quiet=0" alt='Barcode Generator TEC-IT' />
                    <button onclick="convertir()">convertir</button>
                </td>
            </tr>
        </div>
    </table>
    <script type="text/javascript">
        function convertir() {
            var conv = document.getElementById('texto').value;
            var src = document.getElementById("myImg").src = "https://barcode.tec-it.com/barcode.ashx?data=" + conv + "&code=Code128&multiplebarcodes=false&translate-esc=false&unit=Fit&dpi=96&imagetype=Gif&rotation=0&color=%23000000&bgcolor=%23ffffff&qunit=Mm&quiet=0";
        }
    </script>
</body>

</html>

Espero y te sirva.

0

Tienes que acceder al atributo SRC de la imagen , que hice: agregue un id a la imagen para poder acceder al src de esta y luego lo cambie.

Tenias mal el getelementbyid, cambien la funcion por un evento click en el botón.

Revisa el snippet

$("#btnConvert").click(function(){
  	var conv = document.getElementById('texto').value;
    console.log(conv);
    $("#srcImg").attr("src","https://barcode.tec-it.com/barcode.ashx?data="+conv+"&code=Code128&multiplebarcodes=false&translate-esc=false&unit=Fit&dpi=96&imagetype=Gif&rotation=0&color=%23000000&bgcolor=%23ffffff&qunit=Mm&quiet=0");

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
	
<body>
 <table>
 	<div id="h">
	<tr>
		<td style='padding:10px; text-align:center; font-size:15px; font-family:Arial,Helvetica;'>
			<br/>
		</td>
		<td>
			<label>Ingrese el documento que desea convertir</label>
            <input type="text" name="texto" id="texto">
            <br>
			<img src='https://barcode.tec-it.com/barcode.ashx?data=&code=Code128&multiplebarcodes=false&translate-esc=false&unit=Fit&dpi=96&imagetype=Gif&rotation=0&color=%23000000&bgcolor=%23ffffff&qunit=Mm&quiet=0' id="srcImg" alt='Barcode Generator TEC-IT'/>
			<button id="btnConvert">convertir</button>
		</td>
	</tr>
	</div>
</table>
</body>

</html>

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.