Estoy tratando de actualizar los parámetros de URL en función de la entrada seleccionada del formulario.
<form method="get" action="current.php" id="header-form"> <input type="hidden" name="location" value="location"> <input type="checkbox" name="type[]" class="type" value="opt1"> option1 <input type="checkbox" name="type[]" class="type" value="opt2"> option2 <input type="checkbox" name="type2[]" class="type1" value="new1"> new1 <input type="checkbox" name="type2[]" class="type1" value="new2"> new2 </form>jquery
Al seleccionar la casilla de verificación, quiero agregar los valores a la URL
mi jquery
<script type="text/javascript"> $(document).ready(function() { $(".type").change(function () { $("#header-form").trigger("submit"); }); $(".type1").change(function() { $("#header-form").trigger("submit"); }); }); </script>Si selecciono la opción 1, funciona bien y si trato de seleccionar la opción 2, elimina la opción 1 de la URL.
Si selecciono la opción 1 y la opción 2
La URL debe ser -> http://localhost.current.php?type=option1&option2
Y si selecciono todos los valores opción 1 y opción 2 y nuevo 1 y nuevo 2
La URL debe ser -> http://localhost.current.php?type=option1&option2?type1=new1&new2
Y si selecciono la opción de valores 1 y nuevo 1 y nuevo 2
La URL debe ser -> http://localhost.current.php?type=option1?type1=new1&new2
Debe conservar los datos del envío anterior.
haz esto con PHP:
<form method="get" action="current.php" id="header-form"> <input type="hidden" name="location" value="location"> <input type="checkbox" name="type[]" <?php if(isset($_GET['type']) && in_array('opt1', $_GET['type'])): ?>checked<?php endif; ?> class="type" value="opt1"> option1 <input type="checkbox" name="type[]" <?php if(isset($_GET['type']) && in_array('opt2', $_GET['type'])): ?>checked<?php endif; ?> class="type" value="opt2"> option2 <input type="checkbox" name="type2[]" <?php if(isset($_GET['type2']) && in_array('new1', $_GET['type2'])): ?>checked<?php endif; ?> class="type1" value="new1"> new1 <input type="checkbox" name="type2[]" <?php if(isset($_GET['type2']) && in_array('new2', $_GET['type2'])): ?>checked<?php endif; ?> class="type1" value="new2"> new2 </form>