Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i created a html dropdownlist code as :
HTML
<select name="DropDownList1" id="DropDownList1">
<option value="select you location"> select your location</option>
<option value="cairo">Cairo</option>
<option value="alexanderia">Alexanderia</option>
<option value="aswan">Aswan</option>
<option value="port said">Port Said</option>
</select>

and also created a html button code as:
HTML
<button type="button" name="resturantpreview" type="submit" value="chefpreview">resturantpreview</button>


when the user select his location from dropdownlist save my selected value in a jquery

my jquery to get the selected value code as:
JavaScript
jQuery(document).ready(function($){

$('#DropDownList1').on('change',(function(e){
    var optionSelected = $("option:selected", this);
    var valueSelected = this.value;

    wp.ajax.post( 'update_location', {
                'location': valueSelected
    } )
    .done( function( response ) {
        $('#location').html(response);
    } )
    .fail( function() {
        alert( "error" );
    } );

}));
});


What I have tried:

when the user select his location from dropdownlist
retrive my selected value from dropdownlist
when the user click on my button redirect him to a custom page
change my page title with www.myurl/(location_"selected value") which preview all chefs or all restaurants in the selected location
Posted
Updated 12-Jun-19 12:17pm
v3
Comments
Richard MacCutchan 12-Jun-19 11:49am    
It is not necessary to put text in bold.
Moamen Khedr 12-Jun-19 11:56am    
thanks

1 solution

If you keep using AJAX for these, you can
use JavaScript Window Location[^]
window.location = "location_" + response


Other method would be
use post or get, this case post is better, request to php server, php server redirect to your targeted location
<form method="post" action="update_location" name='changeLocation'>
 <select onchange="document.changeLocation.submit()" name="...">
 ...
 </select>
<form>


in php
<?php
header("Location: location_".$path);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900