Initialisation Select avec Ajax (php)



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


.



Relevant Pages

  • Re: Initialisation Select avec Ajax (php)
    ... VooDoo wrote: ... I have a little script that display or hide input field depending on the choice of a select. ... but i can not initialise the default value of the select and have it display the correct input box... ... connexion = window.XMLHttpRequest ...
    (comp.lang.php)
  • Re: Initialisation Select avec Ajax (php)
    ... I have a little script that display or hide input field depending on the ... but i can not initialise the default value of the select ...
    (comp.lang.php)
  • Re: Display a block of text in Firefox & Safari
    ... in FireFox and Safari it appears as a narrow ... There seems to be a needless reliance on the global variable 'NumberOfQuestionsShown', I've suggested a different strategy below that should be easier to maintain - it uses a single class to hide/show questions so the script doesn't need to know how many questions there are nor do they need to be consecutively numbered. ... var questionNum; ... Instead of going through all questions, how about giving them all the same style, then just modify the style to change display from 'none' to ''. ...
    (comp.lang.javascript)
  • Great background color slider but needs a small modification (help pls)
    ... In searching for a good background color chooser I came across this ... figure out how to display the value of cCol in a box. ... What is missing is a text box that displays the currently set ... var sPosition; ...
    (comp.lang.javascript)
  • Re: change images
    ... Use visibility:hidden instead of display. ... var htmlSnippets = new Array; ... function showMe(optionNumber, owner) { ... What is the purpose of the body positioning? ...
    (comp.lang.javascript)