Entradas

Mostrando entradas de abril, 2024

MOSTRAR DATO DE TEXTO SELECT OPTION EN PROPIEDAD VALUE Y TEXT

  1. Selecting the existing selected option and modifying its value and text: JavaScript $(document).ready(function() {   $("#mostrarDato").click(function() {     const nuevoValor = "aquivatexto";     const nuevoTexto = "Nuevo texto";     // Get the currently selected option     const selectedOption = $("#miSelect option:selected");     // Modify its value and text     selectedOption.val(nuevoValor).text(nuevoTexto);   }); }); Usa el código con precaución. Here, clicking the button with the ID "mostrarDato" triggers the function. It defines the new value (nuevoValor) and new text (nuevoTexto) you want to set. Then, it selects the currently selected option using $("#miSelect option:selected") and applies the val() and text() methods with the desired values. 2. Creating a new option with selected, value, and text: JavaScript $(document).ready(function() {   $("#mostrarDato").click(function() {     co...

CONVERTIR CODIGO A JQUERY AJAX GET EJEMPLO SELECT OPTION

  hacer este codigo con el metodo ajax get de jquery <!DOCTYPE html><html lang="es-ES"><head> <meta charset="utf-8"> <title>Json & Jquery</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> </head> <body> <h1>Json & Jquery</h1> <select id="usuarios"></select>  <script type="text/javascript"> $(document).on('ready',function (){ $.getJSON('usuarios.json', function(data) { $.each(data, function(key, value) { $("#usuarios").append('<option name="' + key + '">' + value + '</option>'); }); // close each() });  }); </script> </body></html> Mostrar versiones I'd be glad to provide the code using jQuery's AJAX GET method to fetch data from a JSON file and populate a dropd...

AGREGAR O VER EL VALOR CON JQUERY DENTRO DE SELECT OPTION SELECTBOX

  Tengo el siguiente codigo como puedo agregar o ver el valor con jquery dentro de  <select id="rub" class="form-control">       <option value="1">1</option> </select>   Usando funcion find  y  prop al value selected como seria el codigo Agregar o ver el valor con jQuery dentro de un select Para agregar un valor al select usando la función find y prop de jQuery, puedes usar el siguiente código: JavaScript // Seleccionamos el elemento select const $select = $('#rub'); // Creamos un nuevo elemento option const $option = $('<option>').val('2').text('2'); // Agregamos el nuevo option al final del select $select.find('option:last').after($option); // Seleccionamos el nuevo option $option.prop('selected', true); Usa el código con precaución. Este código primero selecciona el elemento select con el ID rub usando $('#rub'). Luego, crea un nuevo elemento option con el valor 2 y el...