Değişiklikler sayfasına yapılmış ise PHP tespit edemez, bunun için JavaScript kullanmak zorunda olacak.
If you are using a HTML select element and you want to create the content dynamically it could look something like this:
HTML
<select id="computerAge">
<option>2 years</option>
<option>3 years</option>
</select>
<div id="dynamicContent">
</div>
Javascript
var computerAge = document.getElementById('computerAge');
var dynamicContent = document.getElementById('dynamicContent');
computerAge.onchange = function()
{
// Get a list of the current dynamic content
var contents = document.getElementById('content').document.getElementsByTagname('p');
// Remove current dynamic content
for(i = 0; i < contents.length; i++)
{
dynamicContent.removeChild(contents[i]);
}
// Create new dynamic content
var dynamicP = document.createElement('p');
if(computerAge.value == '2 years')
{
dynamicP.innerHTML = 'Content for 2 year old computer';
dynamicContent.appendChild(dynamicP);
}
elseif(computerAge.value == '3 years')
{
dynamicP.innerHTML = 'Content for 3 year old computer';
dyanmicContent.appendChild(dynamicP);
}
}
Yoksa dinamik unsurları oluştururken değilseniz:
HTML
<select id="computerAge">
<option>2_years</option>
<option>3_years</option>
</select>
<div id="content">
<div id="2_years" style="display: none">
<p>Content for 2 year old computer</p>
</div>
<div id="3_years" style="display: none">
<p>Content for 3 year old computer</p>
</div>
</div>
Javascript
function init()
{
// Get the select element
var select = document.getElementById('computerAge');
select.onchange = function()
{
// Get the elements which could be the dynamic content
var content = document.getElementById('content')
var contents = content.getElementsByTagName('div');
// Iterate over contents; make selected visible and hide others
for(i = 0; i < contents.length; i++)
{
if(contents[i].id == select.value)
{
contents[i].style.display = 'block';
}
else
{
contents[i].style.display = 'none';
}
}
}
}
window.onload = init;