linkedin facebook linkedin facebook nod32

Tug`ulgan kunni select tegi orqali html da kiritish

Muallif: Mengliyev Sh.

Qo`shilgan sana: 2017-01-19

Tug`ulgan kunni select tegi orqali html da kiritish

Php tilida formaga tug`ulgan kunda kun, oy va yil orqali kiritishni o`rganamiz buning uchun index.php fayl hosil qilib oling.

Usul 1. Index.php faylni hosil qiladi.

<P>Tug`ulgan yil<br>
<select name='day' id='day'>
<option selected='selected' disabled='disabled'>Kun</option>
<?php
for($day = 1; $day <= 31; $day++){
echo "<option value=\"". $day ."\">$day</option>\n"; }
?>
</select>
<select name='month' id='month'>
<option selected='selected' disabled='disabled'>Oy</option>
<?php
for($month = 1; $month <= 12; $month++){
switch($month){
case 1: $month_name = "Yanvar"; break;
case 2: $month_name = "Fevral"; break;
case 3: $month_name = "Mart"; break;
case 4: $month_name = "Aprel"; break;
case 5: $month_name = "May"; break;
case 6: $month_name = "Iyun"; break;
case 7: $month_name = "Iyul"; break;
case 8: $month_name = "Avgust"; break;
case 9: $month_name = "Sentyabr"; break;
case 10: $month_name = "Oktyabr"; break;
case 11: $month_name = "Noyabr"; break;
case 12: $month_name = "Dekabr"; }
echo "<option value=\"". $month."\"> $month_name</option>\n"; }
?>
</select>
<select name='year' id='year'>
<option selected='selected' disabled='disabled'>Yil</option>
<?php
for($year = date("Y") - 80; $year <= date("Y"); $year++){
echo "<option value=\"". $year ."\">$year</option>\n";}
?>
</select>

Usul 2. php va javascript orqali hosil qilinadi. Index.php faylini hosil qiling.

<?php

$dayOptions = '<option value="0" id="day_option">Kun:</option>';
$yearOptions = '<option value="0" id="year_option">Yil:</option>';


for($day=1; $day<=31; $day++)
{
$dayOptions .= "<option value=\"{$day}\">{$day}</option>\n";
}
for($year=2017; $year>=1937; $year--)
{
$yearOptions .= "<option value=\"{$year}\">{$year}</option>\n";
}
?>



<script type="text/javascript">
function updateDays()
{
//O`zgaruvchilarni kun va yil bilan kiritish

var daySel = document.getElementById('day');
var yearSel = document.getElementById('year');
var monthVal = monthSel.value;
var yearVal = yearSel.value;

//Bir yil ichida 12 oyning kiritib olish
var daysInMonth = 31;
if (monthVal==2)
{
daysInMonth = (yearVal%4==0 && (yearVal%100!=0 || yearVal%400==0)) ? 29 : 28;
}
else if (monthVal==4 || monthVal==6 || monthVal==9 || monthVal==11)
{
daysInMonth = 30;
}


if(daySel.options.length > daysInMonth)
{ //Remove excess days, if needed
daySel.options.length = daysInMonth;
}
while (daySel.options.length != daysInMonth)
{
daySel.options[daySel.length] = new Option(daySel.length+1, daySel.length+1, false);
}

return;
}

</script>
<P>Tug`ulgan yil<br>
<select name="day" id="day">
<?php echo $dayOptions; ?>
</select>

<select name="month" size="1" id="month">
<option value="Oy" selected>Oy</option>
<option value="Yanvar">Yanvar</option>
<option value="Fevral">Fevral</option>
<option value="Mart">Mart</option>
<option value="Aprel">Aprel</option>
<option value="May">May</option>
<option value="Iyun">Iyun</option>
<option value="Iyul">Iyul</option>
<option value="Avgust">Avgust</option>
<option value="Sentyabr">Sentyabr</option>
<option value="Oktyabr">Oktyabr</option>
<option value="Noyabr">Noyabr</option>
<option value="Dekabr">Dekabr</option>
</select>

<select name="year" id="year" onchange="updateDays();">
<?php echo $yearOptions; ?>
</select>

1658 marta o`qildi.

Parol:
Eslab qolish.


Ro`yhatdan o`tish

testing

+998915878681

Siz o`z maxsulotingizni 3D reklama ko`rinishda bo`lishini xohlaysizmi? Unda xamkorlik qilamiz.

3D Reklama


Рейтинг@Mail.ru
Рейтинг@Mail.ru

Besucherzahler
счетчик посещений