Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 23.09.2012, 23:21
Новичок на форуме
Отправить личное сообщение для hurtmind Посмотреть профиль Найти все сообщения от hurtmind
 
Регистрация: 23.09.2012
Сообщений: 1

Как выбрать параметр в select по умолчанию?
Прикрутил к сайту выбор регион>>страна>>город следующим образом:

<?php
<script type='text/javascript' src='city_state.js'></script>
?>

<div id="widget">
Select region: <select onchange="set_country(this,country,city_state)" size="1" name="region">
<option value="" selected="selected">No matter</option>
<option value=""></option>
<script type="text/javascript">
setRegions(this);
</script>
</select>
Country: <select name="country" size="1" disabled="disabled" onchange="set_city_state(this,city_state)"></select>
City/State: <select name="city_state" size="1" disabled="disabled" onchange="print_city_state(country,this)"></select>
<div id="txtregion"></div>
<div id="txtplacename"></div>
</div>


city_state.js выглядит так:

var countries = Object();

countries['Africa'] = '|Algeria|Angola|Benin|Botswana|Burkina Faso|Burundi|Cameroon|Cape Verde|Central African Republic|Chad|Comoros|Congo, Dem.|Congo, Rep.|Djibouti|Egypt|Equatorial Guinea|Eritrea|Ethiopia|Gabon|Gambia|Ghana|Guinea|Guinea-Bissau|Kenya|Lesotho|Liberia|Libya|Madagascar|Malawi|Mali|Mauritania|Mauritius|Morocco|Mozambique|Namibia|Niger|Nigeria|Rwanda|Sao Tome/Principe|Senegal|Seychelles|Sierra 

// и так далее...
////////////////////////////////////////////////////////////////////////////

var city_states = Object();

//Africa
city_states['Algeria'] = '|Algiers||Adrar|Ain Defla|Ain Temouchent|Alger|Annaba|Batna|Bechar|Bejaia|Biskra|Blida|Bordj Bou Arreridj|Bouira|Boumerdes|Chlef|Constantine|Djelfa|El Bayadh|El Oued|El Tarf|Ghardaia|Guelma|Illizi|Jijel|Khenchela|Laghouat|Mascara|Medea|Mila|Mostaganem|M\'Sila|Naama|Oran|Ouargla|Oum el Bouaghi|Relizane|Saida|Setif|Sidi Bel Abbes|Skikda|Souk 

// и так далее...
////////////////////////////////////////////////////////////////////////////


//Asia
city_states['Bangladesh'] = '|Dhaka||Barisal|Chittagong|Khulna|Rajshahi|Sylhet';
city_states['Bhutan'] = '|Thimphu||Bumthang|Chhukha|Chirang|Dagana|Gasa|Geylegphug|Ha|Lhuntshi|Mongar|Paro|Pemagatsel|Punakha|Samchi|Samdrup Jongkhar|Shemgang|Tashigang|Tongsa|Wangdi Phodrang|Yangtse';
city_states['Brunei'] = '|Bandar Seri Begawan||Belait|Brunei/Muara|Temburong|Tutong';
city_states['Burma (Myanmar)'] = '|Rangoon||Ayeyarwady|Bago|Chin|Kachin|Kayin|Kayah|Magway|Mandalay|Mon|Rakhine|Sagaing|Shan|Tanintharyi|Yangon';
city_states['Cambodia'] = '|Phnom Penh||Banteay Mean Cheay|Batdambang|Kampong Cham|Kampong Chhnang|Kampong Spoe|Kampong Thum|Kampot|Kandal|Kaoh Kong|Keb|Kracheh|Mondol Kiri|Otdar Mean Cheay|Pailin|Pouthisat|Preah Seihanu (Sihanoukville)|Preah Vihear|Prey Veng|Rotanah Kiri|Siem Reab|Stoeng Treng|Svay Rieng|Takev';
city_states['China'] = '|Beijing||Anhui|Chongqing|Fujian|Gansu|Guangdong|Guangxi|Guizhou|Hainan|Hebei|Heilongjiang|Henan|Hubei|Hunan|Jiangsu|Jiangxi|Jilin|Liaoning|Nei 

// и так далее...
////////////////////////////////////////////////////////////////////////////


//Australia-Oceania
city_states['Australia'] = '|Canberra||Australian Capital Territory|New South Wales|Northern Territory|Queensland|South Australia|Tasmania|Victoria|Western Australia';
city_states['Fiji'] = '|Suva||Central|Eastern|Northern|Rotuma|Western';
city_states['Kiribati'] = '|Tarawa||Abaiang|Abemama|Aranuka|Arorae|Banaba|Beru|Butaritari|Gilberts (Central)|Gilberts (Northern)|Gilberts (Southern)|Kanton|Kiritimati|Kuria|Line Islands|Maiana|Makin|Marakei|Nikunau|Nonouti|Onotoa|Phoenix Islands|Tabiteuea|Tabuaeran|Tamana|Teraina';
city_states['Micronesia'] = '|Palikir||Chuuk (Truk)|Kosrae|Pohnpei|Yap';
city_states['Nauru'] = '|Yaren||Aiwo|Anabar|Anetan|Anibare|Baiti|Boe|Buada|Denigomodu|Ewa|Ijuw|Meneng|Nibok

// и так далее...
////////////////////////////////////////////////////////////////////////////

function setRegions()
{
	for (region in countries)
		document.write('<option value="' + region + '">' + region + '</option>');
}

function set_country(oRegionSel, oCountrySel, oCity_StateSel)
{
	var countryArr;
	oCountrySel.length = 0;
	oCity_StateSel.length = 0;
	var region = oRegionSel.options[oRegionSel.selectedIndex].text;
	if (countries[region])
	{
		oCountrySel.disabled = false;
		oCity_StateSel.disabled = true;
		oCountrySel.options[0] = new Option('No matter','');
		countryArr = countries[region].split('|');
		for (var i = 0; i < countryArr.length; i++)
			oCountrySel.options[i + 1] = new Option(countryArr[i], countryArr[i]);
		document.getElementById('txtregion').innerHTML = region;
		document.getElementById('txtplacename').innerHTML = '';
	}
	else oCountrySel.disabled = true;
}

function set_city_state(oCountrySel, oCity_StateSel)
{
	var city_stateArr;
	oCity_StateSel.length = 0;
	var country = oCountrySel.options[oCountrySel.selectedIndex].text;
	if (city_states[country])
	{
		oCity_StateSel.disabled = false;
		oCity_StateSel.options[0] = new Option('No matter','');
		city_stateArr = city_states[country].split('|');
		for (var i = 0; i < city_stateArr.length; i++)
			oCity_StateSel.options[i+1] = new Option(city_stateArr[i],city_stateArr[i]);
		document.getElementById('txtplacename').innerHTML = country;
	}
	else oCity_StateSel.disabled = true;
}

function print_city_state(oCountrySel, oCity_StateSel)
{
	var country = oCountrySel.options[oCountrySel.selectedIndex].text;
	var city_state = oCity_StateSel.options[oCity_StateSel.selectedIndex].text;
	if (city_state && city_states[country].indexOf(city_state) != -1)
		document.getElementById('txtplacename').innerHTML = city_state + ', ' + country;
	else document.getElementById('txtplacename').innerHTML = country;
	}


Выбранные пользователем параметры записываю в базу:

$result5 = mysql_query("UPDATE users SET region='$region', country='$country', city_state='$city_state' WHERE email='$email'",$db);


достаю так:

$result2 = mysql_query("SELECT * FROM users WHERE email='$email'",$db);
$myrow2 = mysql_fetch_array($result2);
$reg = $myrow2['region'];
$coun = $myrow2['country'];
$city = $myrow2['city_state'];


ВОПРОС: как при загрузке формы, поумолчанию были выбраны регион, страна и город пользователя. Буду сильно благодарен за помощь ?
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
checkbox, radio и select c option Hekumok Общие вопросы Javascript 8 12.04.2016 17:51
Открытие div блока при первом визите на сайт Nushaba Общие вопросы Javascript 28 20.12.2013 21:24
Как использовать sprit'ы? Hekumok Общие вопросы Javascript 17 10.08.2012 11:24
Как правильно послать XML в POST запросе LowCoder AJAX и COMET 10 15.07.2009 23:20
Как вывести на экран значение функции SELECT MAX(id) Владдд Серверные языки и технологии 3 25.01.2009 16:07