You are here: Initialisation Select avec Ajax (php) « PHP Programming Language « IT news, forums, messages
Initialisation Select avec Ajax (php)

Posted by VooDoo on 08/06/07 14:51

Hello,
I have a little script that display or hide input field depending on the
choice of a select.
It is working fine, but i can not initialise the default value of the select
and have it display the correct input box...

main file:
[CODE]<script language="JavaScript" src="modules/metro/combos.js"
type="text/javascript"> </script>
....
<select name="Ctrltype" id="Ctrltype" onChange="newmenuderoulant(this,'<?php
echo $IdEquipCtrl; ?>')">
<option>--select--</option>
<option value="Lab"<?php if ($rowcontrol[Ctrltype]=="Lab") {echo "
selected";} ?>>Lab (Min-Max)</option>
<option value="Maintenance"<?php if
($rowcontrol[Ctrltype]=="Maintenance") {echo " selected";} ?>>Maintenance
(?)</option>
</select>
.....
<td> <div id="combo2"></div> </td>[/CODE]

The ajax looks working fine, display is ok, when you switch the select to
one value to another, but not at the first call of the page...

Is the error coming from this line:
http.onreadystatechange = displaylist2; ??????

ajax file combos.js :
[CODE]function creerConnexion() {
var connexion;
connexion = window.XMLHttpRequest
? new XMLHttpRequest() :
new ActiveXObject("Microsoft.XMLHTTP");
return connexion;
}

var http = creerConnexion();

function newmenuderoulant(objselect,idctrl) {

var Ctrltype =objselect.options[objselect.selectedIndex].value;
//alert(Ctrltype);
if (idctrl!=null)
http.open('get', 'modules/metro/ajax.php?Ctrltype='+Ctrltype+'&am
p;idctrl='+idctrl);
else http.open('get', 'modules/metro/ajax.php?Ctrltype='+Ctrltype);

http.onreadystatechange = displaylist2;
http.send(null);

}

function displaylist2(){
if(http.readyState == 4){
var response = http.responseText;
document.getElementById("combo2").innerHTML=response;
}
else
{
/*alert('Etape '+http.readyState);*/
}
}[/CODE]

in the ajax.php file i just create the html for the field that goes in the
div id combo2 ...

Thanks for your support!
++
VooDoo

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация