Ken ik niet? Is er geen makkelijke manier?
Link gekopieerd
nee niet echt denk ik..
voorbeeldje
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<script language="javascript">
function createRequestObject() {
var req;
if(window.XMLHttpRequest){
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
req = NULL;
alert('Probleem met het aanmaken van hetXMLHttpRequest object');
}
return req;
}
var http = createRequestObject();
function sendRequestSearch(iets) {
http.open('get', 'dj.php?id='+iets);
http.onreadystatechange = handleResponseSearch;
http.send(null);
}
function handleResponseSearch() {
if(http.readyState == 4 && http.status == 200){
if(http.responseText) {
document.getElementById("dj").innerHTML = http.responseText;
} else {
document.getElementById("dj").innerHTML = " ";
}
} else {
document.getElementById("dj").innerHTML = " ";
}
}
</script>
<div id="dj" ></div>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="bestdj" id="select" onchange="sendRequestSearch(this.value);">
<option value="dj 1">dj 1</option>
<option value="dj 2">dj 2</option>
<option value="other dj">other dj</option>
</select>
</label>
<div id="dj" ></div>
</form>
</body>
</html>
dj.php
<?php
header("Cache-Control: no-cache, must-revalidate");
$dj= $_GET["id"];
if ($dj == "other dj")
{
?>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="other" id="textfield" />
</label>
<p>
<label>
<input type="submit" name="button" id="button" value="Verzenden" />
</label>
</p>
</form>
<?php
}
else
{
}
?>
edit: dit zal zonder refresh als other dj word aangeklikt een invul vakje laten zien
Link gekopieerd
Kan ook zonder AJAX.
Een onchange op het selectboxje, check of de selected value 'other' is. Zo ja, maak een veldje aan via createElement() en plaats deze in de div "dj".
Link gekopieerd
online voorbeeld:
http://mirror.ikhoefgeen.nl/48691.html
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Other-demo</title>
<script type="text/javascript" charset="utf-8">
window.onload = function() {
var artist_other = document.getElementById('artist_other');
artist_other.style.display = 'none';
document.getElementById('artist').onchange = function() {
if(this.options[this.selectedIndex].value == '^other') {
artist_other.style.display = '';
} else {
artist_other.style.display = 'none';
}
}
}
</script>
</head>
<body id="">
<form action="" method="post" accept-charset="utf-8">
<p>
<label for="artist">Artiest</label>
<select id="artist" name="artist">
<option value="Editors">Editors</option>
<option value="Goose">Goose</option>
<option value="The Kooks">The Kooks</option>
<option value="Moke">Moke</option>
<option value="Voicst">Voicst</option>
<option value="The Wombats">The Wombats</option>
<option value="^other">Anders...</option>
</select>
<input type="text" name="artist_other" id="artist_other" />
</p>
<p><input type="submit" value="Continue →"></p>
</form>
</body>
</html>
Link gekopieerd
hartelijk bedankt, dat laatste ga ik even proberen in mijn formuliertje :)
Link gekopieerd