php - How to prevent the set of a get variable? -
i have question. let me explain example. have piece of code:
<form action="vehicles.php" method="get"> <span>marca: <select name="brand"> <option value="null" selected="selected"></option> <option value="volkswagen">volkswagen</option> <option value="renault">renault</option> <option value="peugeot">peugeot</option> <option value="fiat">fiat</option> </select> </span> <span>modelo: <select name="model"> <option value="null" selected="selected"></option> <option value="206">206</option> <option value="suran">suran</option> <option value="passat">passat</option> <option value="punto">punto</option> </select> </span> <input type="submit"> </form>
is way prevent assignment of variables if option selected "null" one?
if, example, select brand="renault" , model="null" url is
http://mywebpage.com/vehicles.php?brand=renault&model=null
but should be
http://mywebpage.com/vehicles.php?brand=renault
i know how unset variables "null" value after form submission php. way before submission , after variables setted "null". cleaner url, free of "variable=null" results.
p/d: don't have native english speaking feel free edit question. wish understand me.
i afraid might need javascript achieve want.
take @ code:
<form action="vehicles.php" id="carform" method="get"> <span>marca: <select name="brand" id="brand"> <option value="none" selected>-</option> <option value="volkswagen">volkswagen</option> <option value="renault">renault</option> <option value="peugeot">peugeot</option> <option value="fiat">fiat</option> </select> </span> <span>modelo: <select name="model" id="model"> <option value="none" selected="selected">-</option> <option value="206">206</option> <option value="suran">suran</option> <option value="passat">passat</option> <option value="punto">punto</option> </select> </span> <input type="button" value="submit" onclick="submitformfilter();" /> </form>
javascript : code this:
<script> function submitformfilter(){ var myform = document.getelementbyid("carform"); var carbrand = document.getelementbyid("brand"); var carmodel = document.getelementbyid("model"); if(carbrand.value === "none" || null){ carbrand.parentnode.removechild(carbrand); } if(carmodel.value === "none" || null){ carmodel.parentnode.removechild(carmodel); } myform.submit(); } </script>
you can try here.
Comments
Post a Comment