Initialisation Select avec Ajax (php)

This is a discussion on Initialisation Select avec Ajax (php) within the PHP Language forums, part of the PHP Programming Forums category; Hello, I have a little script that display or hide input field depending on the choice of a select. It ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-06-2007
VooDoo
 
Posts: n/a
Default 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>
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);*/
}
}
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


Reply With Quote
  #2 (permalink)  
Old 08-07-2007
Hendri Kurniawan
 
Posts: n/a
Default Re: Initialisation Select avec Ajax (php)

On Aug 7, 12:51 am, "VooDoo" <voodoone...@free.fr> 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

Reply With Quote
  #3 (permalink)  
Old 08-07-2007
bill
 
Posts: n/a
Default Re: Initialisation Select avec Ajax (php)

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:
<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>
>
> 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);*/
>    }
> }
>
> 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.

bill
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:43 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0