|
|
|
| Добрый день!
есть вот такой код:
html:
<INPUT TYPE=text id=1 VALUE="" onChange="process(this.id)">
<INPUT TYPE=text id=11 VALUE="" onChange="process(this.id)">
<INPUT TYPE=text id=111 VALUE="" onChange="process(this.id)">
<INPUT TYPE=text id=1111 VALUE="" onChange="process(this.id)">
|
js:
function process(idForml)
{
// proceed only if the xmlHttp object isn't busy
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
{
// retrieve the name typed by the user on the form
name = encodeURIComponent(document.getElementById(idForml).value);
// execute the quickstart.php page from the server
xmlHttp.open("GET", "xml.php?name=" + name, true);
// define the method to handle server responses
idForm = idForml;
xmlHttp.onreadystatechange = handleServerResponse;
// make the server request
xmlHttp.send(null);
}
else
// if the connection is busy, try again after one second
setTimeout('process()', 1000);
}
// executed automatically when a message is received from the server
function handleServerResponse()
{
// move forward only if the transaction has completed
if (xmlHttp.readyState == 4)
{
// status of 200 indicates the transaction completed successfully
if (xmlHttp.status == 200)
{
// extract the XML retrieved from the server
xmlResponse = xmlHttp.responseXML;
// obtain the document element (the root element) of the XML structure
xmlRoot = xmlResponse.documentElement;
nameArray = xmlRoot.getElementsByTagName('name');
otecArray = xmlRoot.getElementsByTagName('otec');
// get the text message, which is in the first child of
// the the document element
var d = document;
var idFormOtec = idForm + "1";
for (var i=0; i<idArray.length; i++){
d.getElementById(idForm).value = nameArray.item(i).firstChild.data;
d.getElementById(idFormOtec).value = otecArray.item(i).firstChild.data;
}
// restart sequence
setTimeout('process()', 1000);
}
// a HTTP status different than 200 signals an error
else
{
alert("There was a problem accessing the server: " + xmlHttp.statusText);
}
}
}
|
Код PHP создает правильный xml файл, поэтому писать его не буду.
Что я хочу получить: когда вносится имя в input c id=1 , то в функцию посылается id и потом в БД ищется строка с необходимым именем введенным в input, для того что бы извлечь данные об отце. После в функции handleServerResponse() в input c id=11 вносятся данные об отце (d.getElementById(idFormOtec).value = otecArray.item(i).firstChild.data;) далее посылается имя отца, в конце должно получиться древо отцовской линии.
На данный момент в input c id=11 вносятся данные, но дальше пишет, что document.getElementById(idForml) is null, не пойму как правильно передать id во вторую функцию и правильно ли будет срабатывать функция onChange.
Нашел проблему, setTimeout('process(idFormOtec)', 1000); , а как сделать что бы на id=1111 цикл завершился? | |
|
|
|
|
|
|
|
для: x][x
(17.04.2009 в 12:18)
| | >дальше пишет, что document.getElementById(idForml) is null
Вы который ребенок у своей мамы?
Первый? Второй? Третий?...
Вас мама как назвала?
Именно 1?
Или 2?
Или 3?... в зависимости от того, какой вы у неё по счёту?
Нет, она назвала вас ИМЕНЕМ, начинающимся с буквы.
Например, Васей, или Петей,.. или Абдурахманом ибн Хаттабом...
Даже если к концу своей жизни вы станете Великим самодержцем, то и тогда ваше имя будет Василий III, Петр IV,.. Абдурахман ибн Хаттаб II... но никак не 3Вася, 4Петя,.. 2Абдурахман ибн Хаттаб... тем более не просто - 3, 4 или 2.
Когда будете назначать объектам страницы нормальные ВАЛИДНЫЕ имена (т.е. начинающиеся с латинской буквы любого регистра), тогда много-много проблем у вас исчезнет. В том числе и вышеуказанная.
"Твой номер - шестнадцатый, Шарапов!"(с) | |
|
|
|
|
|
|
|
для: PAT
(17.04.2009 в 13:05)
| | >Когда будете назначать объектам страницы нормальные ВАЛИДНЫЕ имена (т.е. начинающиеся с латинской буквы любого регистра), тогда много-много проблем у вас исчезнет. В том числе и вышеуказанная.
Я просто не представляю как потом делать взаимосвязь форм с помощью имен... т.е. otec->ded->praded->... Оператор If тоже не подоидет, т.к. в дальнейшем планирую еще добавить мать, так что бы получилось древо состоящее из 4 колен,а id будут формироваться по такому принципу: если отец то к id +'1', если мать то +'2' в конце получится id=11, id=12, id=111, id=112, и т.д.
function process(idForm1, idForm2)
{
for (j=0; j<4; j++) {
idFormArray=new Array()
idFormArray [0]=idForm1;
idFormArray [1]=idForm2;
for (var i=0; i<2; i++){
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
{
name = encodeURIComponent(document.getElementById(idFormArray[i]).value);
xmlHttp.open("GET", "rss.php?name=" + name, true);
idForm = idFormArray[i];
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
}
else
setTimeout('process(idForm)', 1000);
}
}
}
function handleServerResponse()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
xmlResponse = xmlHttp.responseXML;
xmlRoot = xmlResponse.documentElement;
nameArray = xmlRoot.getElementsByTagName('name');
otecArray = xmlRoot.getElementsByTagName('otec');
matArray = xmlRoot.getElementsByTagName('mat');
var d = document;
idFormOtec = idForm + "1";
idFormMat = idForm + "2";
for (var i=0; i<idArray.length; i++){
d.getElementById(idForm).value = nameArray.item(i).firstChild.data;
d.getElementById(idFormOtec).value = otecArray.item(i).firstChild.data;
d.getElementById(idFormMat).value = matArray.item(i).firstChild.data;
}
setTimeout('process(idFormOtec, idFormMat)', 1000);
}
else
{
alert("There was a problem accessing the server: " + xmlHttp.statusText);
}
}
}
|
| |
|
|
|