Php multiple search dropdowns - php

I'm having hard time, thinking out how can I make a PHP dropdown search for a real estate website.
So I have made the MYSQL cities and properties but I don't know how to make the categories and when you search like a Mobile Phone to come another dropdown menu and to select the phone model and to display the results in another page.
the cities list: http://prikachi.com/images.php?images/747/7206747u.jpg
the property type: http://prikachi.com/images/776/7206776v.jpg
p.s. sorry but I could post it like codes..

Use Ajax with PHP by onchange event.
as:
<select id='drpdwn1' onchange='getdata(this.value)'>
<option value='-1'>Please Select</option>
<option value='1'>Example1</option>
<option value='2'>Example2</option>
</select>
<select id='drpdwn2' onchange='getdata(this.value)'>
<option value='-1'>Please Select</option>
</select>
//
<script src="http://code.jquery.com/jquery-1.11.3.js" ></script>
<script>
function getdata(value){
jQuery("#drpdwn2").html("<option>Some Option</option>");
}
function getdatabyAjax(value){
$.post('URL_here',{param:value},function(data){
jQuery("#drpdwn2").html(data);
});
}
</script>
//
when user select example1, javascript getdata() will be called and by ajax, value will be redirected to drpdwn2.

Related

How to change the url of page based on selectbox values?

I have php search filter page in which i used different fields..One of them is Age of youngest driver field which have 2 values like 21-24 and 25+ ..Basically i only want to keep the selected values in the select box even after search so user know what he searched for ..What happen now when i select 25+ from the field and click on search it goes back to 21-24 . But As page is connected top database so it picks values from database which i enter like the database screenshot below Please check and let me know if it have any solution
<select class="half" id="form_frame" name="" onsubmit="getData(this);"/>
<option id="value1" value="21-24" selected="selected">21-24</option>
<option id="value2" value="25+">25+</option>
</select>
When i slect all values from the field and selct 25+ from driver age field then url is
http://localhost/Vehicle2/?car_type=0&pickup=0&return=0&residence_two=International&driver_age=25%2B&passengers=No.+of+Passengers&search=
http://localhost/Vehicle2/?car_type=0&pickup=0&return=0&residence_two=International&driver_age=21-24&passengers=No.+of+Passengers&search=
I want driverage=21-24 instead of driver_age
Apply onchange event in javascript like as follows if you are using jquery
jQuery(function () {
jQuery("#form_frame").change(function () {
var id = jQuery(this).val();;
location.href = "http://localhost/php-page/option"+id+"="+id
})
})
Simple use change event handler for selectbox
$(document).on('change','#form_frame',function(){
//window.location.href="http://localhost/php-//page/option"+$(this).//val()+"="$(this).val();
console.log("http://localhost/phppage/option"+$(this).val()+"="+$(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="half" id="form_frame" name="">
<option value="10" selected="selected">10</option>
<option value="11">11</option>
</select>

PHP Echo into textbox based on dropdown value

Im working on a small web application that follows a basic MVC pattern. currently i have data being pulled from a database into an array and im echoing out that value into one textbox (for now)
<input type="text" name="txtGasConRes" id="gasConRes" value="<?php echo $typical; ?>" disabled/>
The $typical value is being retrieved from my Model class into my Controller class and then echoed into the textbox for gas. I have a very similar textbox for Electricity.
My dropdown is as follows:
<select name="heatingType" id="heatingType" required>
<option value="" disabled selected>Select Your Option</option>
<option value = "Gas">Gas</option>
<option value = "Electricity">Electricity</option>
<option value = "Other">Other</option>
</select>
I was wondering if theres a way to determine where to echo the $typical value. So for example, If the user selected Gas as their heating type, then once the form was submitted it, the value would appear in the Gas textbox. If the user selected Electricity from the dropdown then the value would be echoed out into the Electricity textbox.
Any information will be appreciated.
Thanks!
This is definitely a job for JavaScript or jQuery if you prefer. You need to setup a handler to detect a change event on the select input. Once the user selects a value, then you can update the text field with text based on what the user has selected.
Not tested but something like this should work.
var select = document.getElementById('heatingType');
function updateTextField(selectedValue) {
switch(selectedValue){
case 'Gas':
return 'some text that you want in the text field';
break;
// etc.
}
}
select.addEventListener('change', function(){
var selectedValue = this.value,
textField = document.getElementById('gasConRes');
textField.value = updateTextField(selectedValue);
});
Create javascript function and put function in select box onchange event.(following code is working)
<script>
function heatingType(obj){
alert(obj.options[obj.selectedIndex].value); //if you want to show in alart
//or put in a variable
$x=obj.options[obj.selectedIndex].value;
}
</script>
<select name="heatingType" id="heatingType" onChange="heatingType(this)" required>
<option value="" disabled selected>Select Your Option</option>
<option value = "Gas">Gas</option>
<option value = "Electricity">Electricity</option>
<option value = "Other">Other</option>
</select>

ckeditor value equals result of dropdown

I'm wanting to have a dropdown on my form, the options will be titles to content in my database, I want the content to show in a ckeditor when delected.
I'm looking to do something like the below with jquery and need a little help.
if 'dropdown' value is not 'please select'
CKeditor value equals php variable from database.
end statement
I'm fairly happy getting the variables in php so just need some jquery to change the ckeditor value dependant on the dropdown not being defaulted.
Hope this makes sense and thanks in advance for any responses.
html:
<select name="select" id="select">
<option value="">Select</option>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
<option value="option4">Option 4</option>
<option value="option5">Option 5</option>
</select>
<div id="result" style="border:1px solid #000;padding:10px;color:#ff0000;display:none;"></div>
jQuery dont forget to include the jquery file
$(document).ready(function(){
$('#select').change(function() {
var option = $(this).val();
$.get('select.php', {select:option}, function(data) {
$('#result').html(data).hide().fadeIn(1000);
});
});
});
your php file (select.php)
if(!empty($_GET['select'])) {
//call database and bring back the content for this selection and echo it
}
First you would need to populate the "option" elements of your select box using php, which I believe you said you are comfortable with.
Then, using jQuery:
$(document).ready(function(){
$('#myCKEditorTextArea').text($('#mySelectBox').val());
});
for pre-population on page load, or:
$('#mySelectBox').change(function(){
$('#myCKEditorTextArea').text($(this).val());
});
for population when the user changes the select box value.

Help with a jquery country/state list

Is there a better way to do this jquery code?
Currently I have to use PHP to insert the starting position of the jquery code.
The code is for a country/state list.
If a user picks USA then a state dropdown list is below it, if any other country is selected, then it will show a different text input box and hide the dropdown list.
Now if a user has a country saved into the database already and they are on a page to edit this value, then I have to use PHP to show which should be shown first, either the USA states or the state input.
When a user signs up, by default the USA state list is shown, only if they choose a non usa country if the state list changed to a state input instead.
Hope I made sense. the ultimate goal is to somehow make it completely javascript/jquery and not rely on PHP to set anything
country dropdown list
<select name="country" id="country" class="textarealong signup_good"/>
<option value=1001>Choose a Country</option>
<option value=238>Zimbabwe</option>
...
</select>
USA state dropdown list
<select name="usstate" id="usstate" class="textarealong signup_good"/>
<option value=1001>Choose a State</option>
<option value=238>Florida</option>
...
</select>
NON-USA state INPUT box
<input type="text" id="othstate" name="othstate" id="othstate" value="" class="textarealong signup_good" maxlength="100">
<?PHP
//fix jquery country/state list based on there current saved country/state
if($_SESSION['member_info']['country'] == 224){
//$jquerycountry = "$('#othstate').hide().attr(\"disabled\", \"disabled\");";
$jquerycountry = "$('#othstate').hide().val('');";
}else{
$jquerycountry = "$('#usstate').hide().attr(\"disabled\", \"disabled\");";
}
?>
<script>
$(document).ready(function() {
locationlist();
});
function locationlist() {
<?PHP echo $jquerycountry; // includes country jquery code from above ?>
$('#country').change(function () {
var val = $(this).val();
if (val == 224) {
$('#usstate').val('').show().removeAttr("disabled");
$('#othstate').hide().val('');
} else {
$('#usstate').val('').hide().attr("disabled", "disabled");
$('#othstate').show().removeAttr("disabled");
}
});
}
</script>
Maybe this could be a fine solution for you:
HTML selection and input fields:
<select name="country" id="country" class="textarealong signup_good"/>
<option value=1001>Choose a Country</option>
<option value=238>Zimbabwe</option>
<option value=239>Rwanda</option>
</select>
USA state dropdown list
<select name="usstate" id="usstate" class="textarealong signup_good"/>
<option value=1001>Choose a State</option>
<option value=238>Florida</option>
</select>
<input id="otherstate"/>
Then the jQuery part with some 'ready'-magic: hide the otherstate field and trigger the change event on loading like Greg mentioned already. This makes sure, that if a country was already selected on page load the right form field will be selected:
<script type="text/javascript">
$(document).ready(function () {
$("#otherstate").hide();
$("#country").trigger("change");
});
$("#country").change(function () {
if ($("#country").val() != '1001') {
$("#usstate").hide();
$("#otherstate").show();
} else {
$("#usstate").show();
$("#otherstate").hide();
}
});
</script>
Hopes this will help you! ;)
Could you just do this in ready()?
loctionlist();
$('#country').trigger('change');
(Coming at it from a different angle entirely:)
With all the options/possibilities you're describing here, it might be wise to scrap all the drop-downs and just use an autocomplete text field.

PHP Combo Box AJAX Refresh

I have a PHP page that currently has 4 years of team positions in columns on the page. The client wants to select the players in positions and have first, second and thrid choices. Currently the page shows 4 columns with sets of combos for each position. Each combo has a full set of players in it and the user chooses the player he wants from the combos. On submit the player positions are stored in the database.
However, the client now wants to change the page so that when he selects a player in a year and position then the player is removed from the combo and can no longer be selected for that year. I've used a bit of AJAX but was wondering if anyone had any thoughts/suggestions. The page is currently quite slow so they want it speeded up as well.
The page layout is currently like this
POISTION YEAR1 YEAR2 YEAR3 YEAR4
1 COMBOC1 COMBOC1 COMBOC1 COMBOC1
COMBOC2 COMBOC2 COMBOC2 COMBOC2
COMBOC3 COMBOC3 COMBOC3 COMBOC3
2 same as above
COMBOC1, 2 and 3 all currently have the same players - when a player is selected it needs to be removed for all combos below it. I was thinking of starting by changing the page design and having text boxes for the players and a single player select under each year like this:
POISTION YEAR1 YEAR2 YEAR3 YEAR4
1 <PLAYER><POSITION><CHOICE> ...
[TEXT BOX CHOICE1]
[TEXT BOX CHOICE2]
[TEXT BOX CHOICE3]
2 ...
Then I only have 1 combo box for each year to worry about - I do however have the same problem of refreshing the combo box and removing the player that has been selected, and I'd prefer to do it withough a page submit.
Sorry for the long posting - cheers
If I am understanding your question correctly, what you want to do is remove options from subsequent select boxes depending on what is selected in the previous years' select boxes. You should not have to submit any forms to do this - you should be able to do it purely in javascript. This code should help get you started:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".year").change(function () {
var name = $(this).attr("name");
var checkYearNum = name.substr(4);
var value = $(this).val();
var removeFromLaterYears = function (index) {
var yearNum = $(this).attr("name").substr(4);
if (yearNum > checkYearNum) {
var selector = "[value='" + value[0] + "']";
$(this).children(selector).remove();
}
}
$(".year").each(removeFromLaterYears);
});
});
</script>
</head>
<body>
<form>
<fieldset>
<select class="year" name="year1">
<option value="">Select...</option>
<option value="player1">Player 1</option>
<option value="player2">Player 2</option>
<option value="player3">Player 3</option>
</select>
<select class="year" name="year2">
<option value="">Select...</option>
<option value="player1">Player 1</option>
<option value="player2">Player 2</option>
<option value="player3">Player 3</option>
</select>
<select class="year" name="year3">
<option value="">Select...</option>
<option value="player1">Player 1</option>
<option value="player2">Player 2</option>
<option value="player3">Player 3</option>
</select>
</fieldset>
</form>
</body>
</html>
Basically, all this is doing is using JQuery to set an event that, when one of the selection boxes changes, removes the selection with the same value from any following selection boxes that have a year number (defined in the "name" attribute of each select box) that is greater than the year number of the selection box that was changed.
In addition to this, you will need to keep track of which selections have been removed from which selection boxes so that they can be re-added if the player is unselected.
Since you were talking about combo boxes as well, I assume you have a text input field in addition to the select boxes, but you can use the same principle with those.
If you're not familiar with JQuery you might want to get to know it - it makes stuff like this a lot easier. This would be a good place to start: http://docs.jquery.com/How_jQuery_Works. Hope this helps.

Categories