Dependent drop down in jquery mobile not working - jquery-mobile

I am creating a dependent drop down list of states & city in jquery mobile. which is not working for me. I am unable to hide the 2nd drop down too. The code i am using is:
The html:
<select name="selectmenu5" id="selectmenu5">
<option value="0">Select State</option>
<option value="1">Andaman and Nicobar</option>
<option value="2">Andhra Pradesh</option>
</select>
<select name="selectmenu4" id="selectmenu4">
<option class="city" id="1">Select City</option>
<option class="city" id="2">option 2</option>
<option class="city" id="3">Option 3</option>
</select>
and the js:
$(document).ready(function() {
$("#selectmenu4").hide();
$("#selectmenu5").live("change",function() {
$("#selectmenu4").show();
switch($("#this").val()){
case "1":
$(".city").hide().parent().find("#1").show();
break;
case "2":
$(".city").hide().parent().find("#2").show();
break;
}
});
});

Is this what you want? jsFiddle: http://jsfiddle.net/WXbbj/40/
Create all the selects:
<select name="selectmenu5" id="selectmenu5">
<option value="0">Select State</option>
<option value="1">Andaman and Nicobar</option>
<option value="2">Andhra Pradesh</option>
<select class='cityList' name="selectmenu1" id="selectmenu1">
<option class="city" id="0">Select City</option>
<option class="city" id="1">city1</option>
<option class="city" id="2">city2</option>
</select>
<select class='cityList' id="selectmenu2">
<option class="city" id="0">Select City</option>
<option class="city" id="1">city3</option>
<option class="city" id="2">city4</option>
</select>
Basically i use css to hide the "selectmenu" :
#selectmenu1,#selectmenu2{
display:none;
}
And this is the jquery function to show only the right options:
$(document).ready(function() {
$("#selectmenu5").on("change",function() {
$(".cityList").hide();
$("#selectmenu"+$(this).val()).show();
}); });

Related

Cascade drop-down in MVC View without ajax?

I created one View Model with two Entities. I am passing this view model to my MVC Razor view which have two html drop-downs for each entity respectively.
<select class="form-control" id="Employees" name="Employees">
#foreach (var employee in Model.Employees)
{
<option value="#employee.Id"> #employee.name </option>
}
</select>
<select class="form-control" id="Tasks" name="Tasks">
#foreach (var task in Model.Tasks)
{
<option value="#task.Id"> #task.name </option>
}
</select>
Employee table is the parent of Task table. What I want is getting all the tasks which are related to particular employee only. e.g. In Employee drop-down I select John, then in Tasks drop-down I should get all the tasks which are relative to John. I know how to do this with ajax. I am looking for some other solution.
Is it possible to do something like this:
#foreach (var task in Model.Tasks.Where(x=>x.employeeId == 'Selected in previous dropdown'))
{
<option value="#task.Id"> #task.name </option>
}
Html block
<select id="Employees">
<option value="">Select Employee</option>
<option value="1">Employee1</option>
<option value="2">Employee2</option>
</select>
<select id="Tasks">
<option value="">Select Task</option>
<option value="1" data-employee="1">Employee1Task1</option>
<option value="2" data-employee="1">Employee1Task2</option>
<option value="3" data-employee="1">Employee1Task3</option>
<option value="1" data-employee="2">Employee2Task1</option>
<option value="2" data-employee="2">Employee2Task2</option>
<option value="3" data-employee="2">Employee2Task3</option>
</select>
Script scetion
<script>
$(document).ready(function () {
//on page ready hide all task option
$("#Tasks").find('option').hide();
// set task as empty
$("#Tasks").val('');
// onchange of employee Drop down
$("#Employees").on('change', function () {
var selectedEmployee = $("#Employees").val();
if (selectedEmployee != '') {
$("#Tasks").find('option').hide();
$("#Tasks option[value='']").show();
$('*[data-employee="' + selectedEmployee + '"]').show();
}
else {
// if employee not selected then hide all tasks
$("#Tasks").find('option').hide();
$("#Tasks").val('');
}
});
});
</script>
Please populate country and state drop down list using MVC way by for each loop and use above script. The mandatory case is you have to render all cascade options
<select class="form-control" id="Employees" name="Employees">
#foreach (var employee in Model.Employees)
{
<option value="#employee.Id"> #employee.name </option>
}
</select>
<select class="form-control" id="Tasks" name="Tasks">
#foreach (var task in Model.Tasks)
{
<option value="#task.Id" data-employee="#task.EmployeeId"> #task.name </option>
}
</select>

How to Dynamically Assign DropDown Value in MVC 5 View

I have a Model that contains basic address information:
public class AddressModel()
{
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
}
When passing it into a form in my View, I am placing the values into a textbox, except for the State, which is a dropdown box that is hardcoded to contain the states in America:
<form>
<div class="container-fluid">
<div class="col-md-3">
<div class="form-group">
<!-- First Name -->
<label for="first_name_id" class="control-label">First Name</label>
<input type="text" class="form-control" id="first_name_id" name="first_name" placeholder="First Name" value="#Html.ViewData.Model.Patient.FirstName.First().ToString().ToUpper()#Html.ViewData.Model.FirstName.Substring(1).ToLower()">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<!-- Last Name -->
<label for="last_name_id" class="control-label">Last Name</label>
<input type="text" class="form-control" id="last_name_id" name="last_name" placeholder="Last Name" value="#Html.ViewData.Model.Patient.LastName.First().ToString().ToUpper()#Html.ViewData.Model.LastName.Substring(1).ToLower()">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<!-- Street 1 -->
<label for="street1_id" class="control-label">Street Address 1</label>
<input type="text" class="form-control" id="street1_id" name="street1" placeholder="" value="#Html.ViewData.Patient.BillingAddress1">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<!-- Street 2 -->
<label for="street2_id" class="control-label">Street Address 2</label>
<input style="margin-left: 0px" type="text" class="form-control" id="street2_id" name="street2" placeholder="Apartment, Suite, etc." value="#Html.ViewData.Patient.BillingAddress2">
</div>
</div>
</div>
<div class="container-fluid">
<div class="col-md-4">
<div class="form-group">
<!-- City-->
<label for="city_id" class="control-label">City</label>
<input type="text" class="form-control" id="city_id" name="city" placeholder="" value="#Html.ViewData.Model.BillingCity">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<!-- State Dropdown-->
<label for="state_id" class="control-label">State</label>
<select class="form-control" id="state_id">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<!-- Zip Code-->
<label for="zip_id" class="control-label">Zip Code</label>
<input type="text" class="form-control" id="zip_id" name="zip" placeholder="" value="#Html.ViewData.Model.BillingZip">
</div>
</div>
</div>
</form>
Is there a way to assign the value/option of the drop down in this current format? I can't seem to figure out a way to set the value this way. Do I use the HTML Helper Method for dropdowns, given the list of states? Currently the Value is always set to Alabama.
Each Option element has a "Selected" property, like
<option value="CA" selected="selected">California</option>
You could also set in javascript like
document.getElementById("state_id").value = "CA";
I am not sure what dictates what the default value needs to be. Is there an event, like changing the text in another textbox, or a value available, like a CustomerID, that determines which Option element should be defaulted? Let me know...

How to dynamically filter a select2 listing based on option class

I have a dropdown select of optional 'opportunities' (id="opportunities" in the example below) which I enhance using the select2 jquery plugin, and wish to dynamically filter this list in order to reduce the possible options presented to a user using a 2nd select dropdown (id="group-select" in the example below),
<label>
Select an opportunity<br>
<select id="opportunities" style="width:300px;" multiple="multiple" name="selected-opps" value="">
<optgroup label="Class A">
<option class="group-1" value="1a">Opportunity 1a</option>
<option class="group-2" value="2a">Opportunity 2a</option>
</optgroup>
<optgroup label="Class B">
<option class="group-1" value="1b">Opportunity 1b</option>
<option class="group-2" value="2b">Opportunity 2b</option>
</optgroup>
<optgroup label="Class C">
<option class="group-1" value="1c">Opportunity 1c</option>
<option class="group-2" value="2c">Opportunity 2c</option>
</optgroup>
</select>
</label>
<select id="group-select">
<option value="">Select a group</option>
<option value="group-1">group 1</option>
<option value="group-2">group 2</option>
</select>
</div>
<div id="select-opportunity"></div>
<script type="text/javascript">
(function( $ ) {
'use strict';
var opportunities = $('select#opportunities').select2({
dropdownParent: $('#select-opportunity')
});
})( jQuery );
</script>
I wish to be able to make a selection in the 2nd select, say 'group 1' and would like the select2 list to contain only 'group-1' items as per the option in the first select dropdown that have the grouo-1 class attribute.
I managed to solve this using 2 optional functionality provided by the select2 plugin, namely the ability to control the way items are built and displayed using the templating functionality, and using the programmatic control exposed in the plugin. I replaced the javascript appended below the example in the question with,
<script type="text/javascript">
(function( $ ) {
'use strict';
var opportunities = $('select#opportunities').select2({
dropdownParent: $('#select-opportunity'),
templateResult: formatItem
});
function formatItem (state) {
if (!state.id) { return state.text; }
//change the id of our select2 items
state._resultId = state._resultId+'-'+state.element.className;
var $state = $(
'<span class="opportunity-item ' + state.element.className + '">' + state.text + '</span>'
);
return $state;
}
$('select#group-select').change( function() {
//hide the unwanted options
var group = $('select#group-select option:selected').val();
//clear the styling element
$('style#select2-style').empty();
if(group){
//if a group is selected we need to hide all the others
$('select#group-select option').not(':selected').each(function(){
group = $(this).val();
if(group){
$('style#select2-style').append(
'li[id$="'+group+'"]{display:none;}'
);
}
});
}
//force the select2 to referesh by opening and closing it again
opportunities.select2('open');
opportunities.select2('close');
});
})( jQuery );
</script>
<style id="select2-style"></style>
I have also added an empty <style> element at the bottom in which I dynamically create the rules required to hide the unwanted items.
The logic
The code above creates templating function formatItem that the select2 plugin will use to format the items. The item state object is passed to the function which includes the unique id for each item.
This id is modified by appending the class of the corresponding option element.
When a group option is selected in the 2nd dropdown select (#group-select) a set of styling is created and appended to the bottom <style> element to hide all the elements whose id attributes end with the class names to be hidden, for example if one seleced group-1, the code will create a style to hide group-2 items,
li[id$="group-2"] {
display:none;
}
However for this to work we need to force the select2 dropdown to refresh to pick up the new styling and the only way I found for this work was to use the programmatic control of the plugin to 'open' and immediately 'close' the select2 dropdown.
ّshort Example .
window.templateResult = function templateResult(state) {
if (state.text.indexOf('ss') == -1)
return null;///hide
if (!state.id) { return state.text; }
var $state = $(
'<span>' + state.text + '</span>'
);
return $state;
};
//Init
$("#select1").select2({
templateResult: templateResult
});
ّFull Example below.
$(document).ready(function () {
//general custom filter
window.Select2FilterFunc = function (state) { return "Default" };
//general custom templateResult
window.templateResult = function templateResult(state) {
//call custom filter
var result = Select2FilterFunc(state);
if (result != "Default")
return result;
if (!state.id) { return state.text; }
var $state = $(
'<span>' + state.text + '</span>'
);
return $state;
};
//Init
$("#select1").select2({
templateResult: templateResult
});
//Add Custom Filter when opening
$('#select1').on('select2:opening', function (evt) {
//set your filter
window.Select2FilterFunc = function (state) {
if (state.text.indexOf('ss') == -1)
return null;//hide item
else
return "Default";
};
}).on('select2:close', function (evt) {
window.Select2FilterFunc = function (state) { return "Default" };
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<select id="select1" class="js-states form-control" style="width:300px" multiple="multiple ">
<optgroup label="Alaskan/Hawaiian Time Zone">
<option value="AK" title="11111111">Alaska</option>
<option value="HI" title="2222">Hawaii </option>
</optgroup>
<optgroup label="Pacific Time Zone">
<option value="CA">California</option>
<option value="NV">Nevada</option>
<option value="OR">Oregon</option>
<option value="WA">Washington</option>
</optgroup>
<optgroup label="Mountain Time Zone">
<option value="AZ">Arizona</option>
<option value="CO">Colorado</option>
<option value="ID">Idaho</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NM">New Mexico</option>
<option value="ND">North Dakota</option>
<option value="UT">Utah</option>
<option value="WY">Wyoming</option>
</optgroup>
<optgroup label="Central Time Zone">
<option value="AL">Alabama</option>
<option value="AR">Arkansas</option>
<option value="IL">Illinois</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="OK">Oklahoma</option>
<option value="SD">South Dakota</option>
<option value="TX">Texas</option>
<option value="TN">Tennessee</option>
<option value="WI">Wisconsin</option>
</optgroup>
<optgroup label="Eastern Time Zone">
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="IN">Indiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="OH">Ohio</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WV">West Virginia</option>
</optgroup>
</select>

Fusion Tables - Pan And Zoom 'Data still loading" Error

I've been trying to learn how to have a map pan and zoom based on a query return. I have it mostly working, except I get "Data may still be loading" error, each time the map zooms in. The map is zooming to the right location.
I know I must have a syntax error somewhere, but being so new to Fusion Tables, I can't find it.
Any help would be appreciated:
CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Assembly Map</title>
<style>
#map_canvas { width: 610px; height: 400px; }
</style>
<!--Load the AJAX API-->
<script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://geoxml3.googlecode.com/svn/branches/polys/geoxml3.js"></script>
<script type="text/javascript">
google.load('visualization', '1', {'packages':['corechart', 'table', 'geomap']});
var map;
var layer;
var tableid = '16DRI3M2060Ui9S__E9uajhWrLznEJPjUpvqpfudc';
var layer2;
var tableid2 = '16DRI3M2060Ui9S__E9uajhWrLznEJPjUpvqpfudc';
function initialize() {
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(49.99775728108552, -88.70237663424376),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
layer = new google.maps.FusionTablesLayer(tableid);
layer.setQuery("SELECT 'geometry' FROM " + tableid);
layer.setMap(map);
layer2 = new google.maps.FusionTablesLayer(tableid2);
layer2.setQuery("SELECT 'geometry' FROM " + tableid2 + " WHERE Riding");
layer2.setMap(map);
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
{
function changeMap() {
var searchString = document.getElementById('searchString').value.replace("'", "\\'");
if(searchString == "") {
var query="SELECT 'geometry' FROM " + tableid;
} else {
var query="SELECT 'geometry' FROM " + tableid + " WHERE 'Riding' = '" + searchString + "'";
}
layer.setQuery(query);
zoom2query(query);
}
}
function zoom2query(query) {
// zoom and center map on query results
//set the query using the parameter
var queryText = encodeURIComponent(query);
var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + queryText);
//set the callback function
query.send(zoomTo);
}
function zoomTo(response) {
if (!response) {
alert('no response');
return;
}
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
FTresponse = response;
//for more information on the response object, see the documentation
//http://code.google.com/apis/visualization/documentation/reference.html#QueryResponse
numRows = response.getDataTable().getNumberOfRows();
numCols = response.getDataTable().getNumberOfColumns();
var kml = FTresponse.getDataTable().getValue(0,0);
// create a geoXml3 parser for the click handlers
var geoXml = new geoXML3.parser({
map: map,
zoom: false
});
geoXml.parseKmlString("<Placemark>"+kml+"</Placemark>");
geoXml.docs[0].gpolygons[0].setMap(null);
map.fitBounds(geoXml.docs[0].gpolygons[0].bounds);
/*
var bounds = new google.maps.LatLngBounds();
for(i = 0; i < numRows; i++) {
var point = new google.maps.LatLng(
parseFloat(response.getDataTable().getValue(i, 0)),
parseFloat(response.getDataTable().getValue(i, 1)));
bounds.extend(point);
}
// zoom to the bounds
map.fitBounds(bounds);
*/
}
</script>
<body onload="initialize();">
<div id="map-canvas"></div>
<div style="margin-top: 10px;">
<label><span class="style58">Select Riding</span> </label>
<select id="searchString" onChange="changeMap(this.value);">
<option value="">--Ridings--</option>
<option value="--Select--">--Select--</option>
<option value="AJAX--PICKERING">AJAX--PICKERING</option>
<option value="ALGOMA--MANITOULIN">ALGOMA--MANITOULIN</option>
<option value="ANCASTER--DUNDAS--FLAMBOROUGH--WESTDALE">ANCASTER--DUNDAS--FLAMBOROUGH--WESTDALE</option>
<option value="BARRIE">BARRIE</option>
<option value="BEACHES--EAST YORK">BEACHES--EAST YORK</option>
<option value="BRAMALEA--GORE--MALTON">BRAMALEA--GORE--MALTON</option>
<option value="BRAMPTON WEST">BRAMPTON WEST</option>
<option value="BRAMPTON--SPRINGDALE">BRAMPTON--SPRINGDALE</option>
<option value="BRANT">BRANT</option>
<option value="BRUCE--GREY--OWEN SOUND">BRUCE--GREY--OWEN SOUND</option>
<option value="BURLINGTON">BURLINGTON</option>
<option value="CAMBRIDGE">CAMBRIDGE</option>
<option value="CARLETON--MISSISSIPPI MILLS">CARLETON--MISSISSIPPI MILLS</option>
<option value="CHATHAM--KENT--ESSEX">CHATHAM--KENT--ESSEX</option>
<option value="DAVENPORT">DAVENPORT</option>
<option value="DON VALLEY EAST">DON VALLEY EAST</option>
<option value="DON VALLEY WEST">DON VALLEY WEST</option>
<option value="DUFFERIN--CALEDON">DUFFERIN--CALEDON</option>
<option value="DURHAM">DURHAM</option>
<option value="EGLINTON--LAWRENCE">EGLINTON--LAWRENCE</option>
<option value="ELGIN--MIDDLESEX--LONDON">ELGIN--MIDDLESEX--LONDON</option>
<option value="ESSEX">ESSEX</option>
<option value="ETOBICOKE CENTRE">ETOBICOKE CENTRE</option>
<option value="ETOBICOKE NORTH">ETOBICOKE NORTH</option>
<option value="ETOBICOKE--LAKESHORE">ETOBICOKE--LAKESHORE</option>
<option value="GLENGARRY--PRESCOTT--RUSSELL">GLENGARRY--PRESCOTT--RUSSELL</option>
<option value="GUELPH">GUELPH</option>
<option value="HALDIMAND--NORFOLK">HALDIMAND--NORFOLK</option>
<option value="HALIBURTON--KAWARTHA LAKES--BROCK">HALIBURTON--KAWARTHA LAKES--BROCK</option>
<option value="HALTON">HALTON</option>
<option value="HAMILTON CENTRE">HAMILTON CENTRE</option>
<option value="HAMILTON EAST--STONEY CREEK">HAMILTON EAST--STONEY CREEK</option>
<option value="HAMILTON MOUNTAIN">HAMILTON MOUNTAIN</option>
<option value="HURON--BRUCE">HURON--BRUCE</option>
<option value="KENORA--RAINY RIVER">KENORA--RAINY RIVER</option>
<option value="KINGSTON AND THE ISLANDS">KINGSTON AND THE ISLANDS</option>
<option value="KITCHENER CENTRE">KITCHENER CENTRE</option>
<option value="KITCHENER--CONESTOGA">KITCHENER--CONESTOGA</option>
<option value="KITCHENER--WATERLOO">KITCHENER--WATERLOO</option>
<option value="LAMBTON--KENT--MIDDLESEX">LAMBTON--KENT--MIDDLESEX</option>
<option value="LANARK--FRONTENAC--LENNOX AND ADDINGTON">LANARK--FRONTENAC--LENNOX AND ADDINGTON</option>
<option value="LEEDS--GRENVILLE">LEEDS--GRENVILLE</option>
<option value="LONDON NORTH CENTRE">LONDON NORTH CENTRE</option>
<option value="LONDON WEST">LONDON WEST</option>
<option value="LONDON--FANSHAWE">LONDON--FANSHAWE</option>
<option value="MARKHAM--UNIONVILLE">MARKHAM--UNIONVILLE</option>
<option value="MISSISSAUGA EAST--COOKSVILLE">MISSISSAUGA EAST--COOKSVILLE</option>
<option value="MISSISSAUGA SOUTH">MISSISSAUGA SOUTH</option>
<option value="MISSISSAUGA--BRAMPTON SOUTH">MISSISSAUGA--BRAMPTON SOUTH</option>
<option value="MISSISSAUGA--ERINDALE">MISSISSAUGA--ERINDALE</option>
<option value="MISSISSAUGA--STREETSVILLE">MISSISSAUGA--STREETSVILLE</option>
<option value="NEPEAN--CARLETON">NEPEAN--CARLETON</option>
<option value="NEWMARKET--AURORA">NEWMARKET--AURORA</option>
<option value="NIAGARA FALLS">NIAGARA FALLS</option>
<option value="NIAGARA WEST--GLANBROOK">NIAGARA WEST--GLANBROOK</option>
<option value="NICKEL BELT">NICKEL BELT</option>
<option value="NIPISSING">NIPISSING</option>
<option value="NORTHUMBERLAND--QUINTE WEST">NORTHUMBERLAND--QUINTE WEST</option>
<option value="OAK RIDGES--MARKHAM">OAK RIDGES--MARKHAM</option>
<option value="OAKVILLE">OAKVILLE</option>
<option value="OSHAWA">OSHAWA</option>
<option value="OTTAWA CENTRE">OTTAWA CENTRE</option>
<option value="OTTAWA SOUTH">OTTAWA SOUTH</option>
<option value="OTTAWA WEST--NEPEAN">OTTAWA WEST--NEPEAN</option>
<option value="OTTAWA--ORLEANS">OTTAWA--ORLEANS</option>
<option value="OTTAWA--VANIER">OTTAWA--VANIER</option>
<option value="OXFORD">OXFORD</option>
<option value="PARKDALE--HIGH PARK">PARKDALE--HIGH PARK</option>
<option value="PARRY SOUND--MUSKOKA">PARRY SOUND--MUSKOKA</option>
<option value="PERTH--WELLINGTON">PERTH--WELLINGTON</option>
<option value="PETERBOROUGH">PETERBOROUGH</option>
<option value="PICKERING--SCARBOROUGH EAST">PICKERING--SCARBOROUGH EAST</option>
<option value="PRINCE EDWARD--HASTINGS">PRINCE EDWARD--HASTINGS</option>
<option value="RENFREW--NIPISSING--PEMBROKE">RENFREW--NIPISSING--PEMBROKE</option>
<option value="RICHMOND HILL">RICHMOND HILL</option>
<option value="SARNIA--LAMBTON">SARNIA--LAMBTON</option>
<option value="SAULT STE. MARIE">SAULT STE. MARIE</option>
<option value="SCARBOROUGH CENTRE">SCARBOROUGH CENTRE</option>
<option value="SCARBOROUGH SOUTHWEST">SCARBOROUGH SOUTHWEST</option>
<option value="SCARBOROUGH--AGINCOURT">SCARBOROUGH--AGINCOURT</option>
<option value="SCARBOROUGH--GUILDWOOD">SCARBOROUGH--GUILDWOOD</option>
<option value="SCARBOROUGH--ROUGE RIVER">SCARBOROUGH--ROUGE RIVER</option>
<option value="SIMCOE NORTH">SIMCOE NORTH</option>
<option value="SIMCOE--GREY">SIMCOE--GREY</option>
<option value="ST. CATHARINES">ST. CATHARINES</option>
<option value="ST. PAUL'S">ST. PAUL'S</option>
<option value="STORMONT--DUNDAS--SOUTH GLENGARRY">STORMONT--DUNDAS--SOUTH GLENGARRY</option>
<option value="SUDBURY">SUDBURY</option>
<option value="THORNHILL">THORNHILL</option>
<option value="THUNDER BAY--ATIKOKAN">THUNDER BAY--ATIKOKAN</option>
<option value="THUNDER BAY--SUPERIOR NORTH">THUNDER BAY--SUPERIOR NORTH</option>
<option value="TIMISKAMING--COCHRANE">TIMISKAMING--COCHRANE</option>
<option value="TIMMINS--JAMES BAY">TIMMINS--JAMES BAY</option>
<option value="TORONTO CENTRE">TORONTO CENTRE</option>
<option value="TORONTO--DANFORTH">TORONTO--DANFORTH</option>
<option value="TRINITY--SPADINA">TRINITY--SPADINA</option>
<option value="VAUGHAN">VAUGHAN</option>
<option value="WELLAND">WELLAND</option>
<option value="WELLINGTON--HALTON HILLS">WELLINGTON--HALTON HILLS</option>
<option value="WHITBY--OSHAWA">WHITBY--OSHAWA</option>
<option value="WILLOWDALE">WILLOWDALE</option>
<option value="WINDSOR WEST">WINDSOR WEST</option>
<option value="WINDSOR--TECUMSEH">WINDSOR--TECUMSEH</option>
<option value="YORK CENTRE">YORK CENTRE</option>
<option value="YORK SOUTH--WESTON">YORK SOUTH--WESTON</option>
<option value="YORK WEST ">YORK WEST </option>
<option value="YORK--SIMCOE">YORK--SIMCOE</option>
</select>
</label>
</div>
<br>
<div id="map_canvas"></div>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-162157-1";
urchinTracker();
</script>
</body>
</html>
This fixes the problem:
function initialize() {
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(49.99775728108552, -88.70237663424376),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
layer = new google.maps.FusionTablesLayer(tableid);
layer.setQuery("SELECT 'geometry' FROM " + tableid);
// layer.setMap(map);
layer2 = new google.maps.FusionTablesLayer(tableid2);
layer2.setQuery("SELECT 'geometry' FROM " + tableid2 + " WHERE Riding");
layer2.setMap(map);
}

Dropdowns - selects dynamics-jquery

I'm try to do a dynamic selects with jQuery, example:
<select >
<option value=1> 1</option>
<option value=2> 2</option>
<option value=3> 3</option>
<option value=4> 4</option>
</select>
when I get value="x"
I would like to add
count=x;
for(int i=1 ; i<=count; i++){
<select > </select>
}
I have a problem with me code , this code add and add.. I dont want this
I just want add the 'x' select
http://jsfiddle.net/hqLPp/48/
If you want result on same page, then this might be useful,
this will be on your page, where you want result
<script>
function showSelectBox(str)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myresult").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","test.php?q="+str,true); // Pass value to another page Here->test
xmlhttp.send();
}
</script>
<select name='check' onchange="showSelectBox(this.value)">
<option>Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<div id="myresult">
</div>
Now On test.php Simply Call Value & put select box,
<?php
$q = $_GET['q'];
for($i=1 ; $i<=$q; $i++)
{
echo '<select > </select>';
}
?>

Resources