PHP ver gevorderde |
|
Hallo,
Ik haal een string in het formaat "xx|xx|xx" op mbv AJAX.
Vervolgens explode ik die in javascript (split) en wil ik deze toewijzen aan een aantal inputs, in firefox gaat dit perfect maar in internet explorer krijgen de velden de waarde "undefined".
Javascript:
function $(id) {
return document.getElementById(id);
}
function process() {
if ( window.XMLHttpRequest ) {
var xhr = new XMLHttpRequest();
} else if ( window.ActiveXObject ) {
var xhr = new ActiveXObject('MSXML2.XMLHTTP');
} else {
$('result').innerHTML = 'Ajax not supported';
return;
}
xhr.onreadystatechange = function() {
if ( (xhr.readyState == 4) && (xhr.status == 200) ) {
response = xhr.responseText;
listOptions();
}
}
xhr.open('GET', 'process.php?year=' + $('year').value + '&t=' + new Date().getTime(), true);
xhr.send(null);
function listOptions() {
options = response.split('|');
$('id').value = options[0];
$('name').value = options[1];
$('price').value = options[2];
$('number').value = options[3];
}
}
function $(id) { return document.getElementById(id); } function process() { if ( window.XMLHttpRequest ) { var xhr = new XMLHttpRequest(); } else if ( window.ActiveXObject ) { var xhr = new ActiveXObject('MSXML2.XMLHTTP'); } else { $('result').innerHTML = 'Ajax not supported'; return; } xhr.onreadystatechange = function() { if ( (xhr.readyState == 4) && (xhr.status == 200) ) { response = xhr.responseText; listOptions(); } } xhr.open('GET', 'process.php?year=' + $('year').value + '&t=' + new Date().getTime(), true); xhr.send(null); function listOptions() { options = response.split('|'); $('id').value = options[0]; $('name').value = options[1]; $('price').value = options[2]; $('number').value = options[3]; } }
HTML:
<form name="holder" id="holder">
<input type="text" id="id" value=""/>
<select id="year" onchange="process()">
<option>Select a year</option>
<option>2002</option>
<option>2003</option>
<option>2004</option>
</select>
<input type="text" id="name" value=""/>
€<input type="text" id="price" value=""/>
<input type="text" id="number" value=""/>
<input type="button" value="Submit" />
</form>
<form name="holder" id="holder"> <input type="text" id="id" value=""/> <select id="year" onchange="process()"> <input type="text" id="name" value=""/> €<input type="text" id="price" value=""/> <input type="text" id="number" value=""/> <input type="button" value="Submit" />
Heeft iemand enig idee?
Mvg,
Jarno
Koen schreef: Code tags, daar moet je dan zo lang voor op dit forum zitten...
|