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]
type="text/javascript">
....
.....
[/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);
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
Re: Initialisation Select avec Ajax (php)
am 07.08.2007 01:15:11 von Hendri Kurniawan
On Aug 7, 12:51 am, "VooDoo" wrote:
> 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...
>
-- SNIP --
>
> Thanks for your support!
> ++
> VooDoo
IMHO this is a javascript problem, and has nothing to do with PHP.
Anyway I don't really know where the problem is, coz the code that you
post
doesn't give any clue of what the problem could be.
Try c.l.javascript
Hendri Kurniawan
Re: Initialisation Select avec Ajax (php)
am 07.08.2007 15:13:31 von NerdRevenge
VooDoo wrote:
> 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]
> type="text/javascript">
> ...
>
> ....
>
[/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
>
>
It appears that you need to have a "selected" for the default
value of the selection box. You could just put it in the html
that is displayed before the user changes things.