|
|
|
| Здравствуйте.
Есть два поля типа селект:
<select id="first">
<option></option>
<option>Пункт1</option>
<option>Пункт2</option>
<option>Пункт3</option>
</select>
<select id="second">
<option></option>
<option>Пункт</option>
</select>
Надо сделать так, чтобы при загрузке страницы первый селект отображался, а второй - нет. Второй селект отображается только при условии, что в первом селекте выбран либо "Пункт1" либо "Пункт2".
Спасибо. | |
|
|
|
|
|
|
|
для: Mookapek
(13.08.2009 в 19:45)
| |
<select id="first" onchange="with (this) document.getElementById ('second').style.display = (selectedIndex && selectedIndex < 3) ? '' : 'none'">
<option></option>
<option>Пункт1</option>
<option>Пункт2</option>
<option>Пункт3</option>
</select>
<select id="second" style="display: none">
<option></option>
<option>Пункт</option>
</select>
|
| |
|
|
|
|
|
|
|
для: PAT
(13.08.2009 в 20:39)
| | А вы не могли бы объяснить, как работает эта строчка кода:
with (this) document.getElementById ('second').style.display = (selectedIndex && selectedIndex < 3) ? '' : 'none'?
Хочется не просто скопировать код, а понять как работает, а самому сделать это не удается. | |
|
|
|
|
|
|
|
для: PAT
(13.08.2009 в 20:39)
| | А почему не работает такой вариант:
<html>
<head>
<script>
function f1(x1)
{
if(x1.selectedIndex == 1 || x1.selectedIndex == 2)
{
document.getElementById('second').style.display = '';
}
else
{
document.getElementById('second').style.display = 'none';
}
}
<script>
</head>
<body>
<select id="first" onchange="f1(this)">
<option></option>
<option>Пункт1</option>
<option>Пункт2</option>
<option>Пункт3</option>
<option>Пункт4</option>
</select>
<select id="second" style="display: none">
<option></option>
<option>Пункт</option>
</select>
</body>
</html>
|
Вообще ничего не выводит. | |
|
|
|
|
|
|
|
для: Mookapek
(17.08.2009 в 17:58)
| |
<html>
<head>
<script>
function f1(x1)
{
if(x1.selectedIndex == 1 || x1.selectedIndex == 2)
{
document.getElementById('second').style.display = 'inline';//или block
}
else
{
document.getElementById('second').style.display = 'none';
}
}
<script>
</head>
<body>
<select id="first" onchange="f1(this)">
<option></option>
<option>Пункт1</option>
<option>Пункт2</option>
<option>Пункт3</option>
<option>Пункт4</option>
</select>
<select id="second" style="display: none">
<option></option>
<option>Пункт</option>
</select>
</body>
</html>
|
| |
|
|
|
|
|
|
|
для: Mookapek
(13.08.2009 в 19:45)
| | как-то так
function YoDude() {
var oFirst = document.getElementById('first');
var oSecond = document.getElementById('second');
if(oFirst .selectedIndex == 0) {
oSecond.selectedIndex = 0;
oSecond.disabled = true;
}
else {
if(oFirst .selectedIndex < 3) {
oSecond.disabled = false;
}
}
}
<select id="first" onchange="YoDude();">
<option value="0"></option>
<option value="1">Пункт1</option>
<option value="2">Пункт2</option>
<option value="3">Пункт3</option>
</select>
<select id="second" disabled="disabled">
<option value="0"></option>
<option value="1">Пункт</option>
</select>
|
| |
|
|
|