Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
How to use in Javascript the value of a variable obtained in a jQuery block

I've written a form that contains HTML select served by jQuery. The rest of HTML elements is served by pure Javascript. I want to get in Javascript part the value obtaied from jQuery block. Here is a simple code which covers the subject:

<!DOCTYPE html><html>
<head><meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
  $("#button").click(function() {
     var value = $("#city").val();
     alert(value);
  })
});
//how to get value from jQuery block above ? ?
var pure_value = value; 
. . . . . . . . . . . . //the next code using value 
</script>
</head>
<body>    Select City:
    <select id="city" name="city">
        <option value="delhi"> Delhi </option>
        <option value="mumbai"> Mumbai </option>
        <option value="chennai"> Chennai </option>
    </select>
    <button id="button"> Fetch Value </button>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

var value will only have a city value when the user clicks the button, so it does not make sense to try to get the value from the variable declared inside button click callback.

You have some possibilities:

  1. Ask jquery for city val again in this line: var pure_value = $("#city").val();
  2. Create a function 'code_using_value(value)' and call this function inside the button callback.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda