miffe Posted September 3, 2007 Share Posted September 3, 2007 I want a form with 3 boxes, one for year, one for month, one for day... whenever any of the 3 boxes is changed, part of the page, below the 3 boxes, will be updated through AJAX. Here is my PHP code for the 3 boxes: //Fecha - > Añoecho "<SELECT name='date1' id='date1' STYLE='width: 74px' onChange='showUser2('date1','date2','date3')'>"; $ystart = date("Y") - 5; $yend = date("Y"); $ycurr = $yend; while ($ycurr >= $ystart) { echo "<OPTION value='" . $ycurr . "'>". $ycurr ."</OPTION>"; $ycurr--; } echo "</SELECT> ";//Fecha - > Mesecho "<SELECT name='date2' id='date2' STYLE='width: 74px' onChange='showUser2('date1','date2','date3')'>"; echo "<OPTION value='01'>Ene</OPTION>"; echo "<OPTION value='02'>Feb</OPTION>"; echo "<OPTION value='03'>Mar</OPTION>"; echo "<OPTION value='04'>Abr</OPTION>"; echo "<OPTION value='05'>May</OPTION>"; echo "<OPTION value='06'>Jun</OPTION>"; echo "<OPTION value='07'>Jul</OPTION>"; echo "<OPTION value='08'>Ago</OPTION>"; echo "<OPTION value='09'>Sep</OPTION>"; echo "<OPTION value='10'>Oct</OPTION>"; echo "<OPTION value='11'>Nov</OPTION>"; echo "<OPTION value='12'>Dic</OPTION>"; echo "</SELECT> ";//Fecha - > Diaecho "<SELECT name='date3' id='date3' STYLE='width: 74px' onChange='showUser2('date1','date2','date3')'>"; $ycurr = 1; while ($ycurr <= 31) { echo "<OPTION value='" . $ycurr . "'>". $ycurr ."</OPTION>"; $ycurr++; } echo "</SELECT><br><br>";echo "<span id='txtHint'>[Lista de Mercancía: Teclea una Fecha]</span>"; And here is my JS: function showUser2(str1,str2,str3){ xmlHttp=GetXmlHttpObject()if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="5remfind.php"url=url+"?rem="+str1+"-"+str2+"-"+str3url=url+"&sid="+Math.random()xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true)xmlHttp.send(null)} obviously it's not refreshing. I had it working with a textbox, but when I tried it out with the drop-down boxes it stopped working, it has something to do with how I want to send the 3 variables from each combobox. How can I send all the 'id' or name tags along to the JS function? 1 works fine by just using onkeyup='showUser(this.value)'><br><br>"; for example, but I want to use 3 and send the values along.Quite confusing,any help ?Thanks in advance :)miffe Link to comment Share on other sites More sharing options...
justsomeguy Posted September 4, 2007 Share Posted September 4, 2007 You're only sending the IDs of the elements, not the values. So when you do this:url=url+"?rem="+str1+"-"+str2+"-"+str3The url variables equals "5remfind.php?rem=date1-date2-date3". If you want to get the values of the elements you can use document.getElementById to get the element you want and then the value property will contain the value.document.getElementById(str1).value Link to comment Share on other sites More sharing options...
miffe Posted September 5, 2007 Author Share Posted September 5, 2007 You're only sending the IDs of the elements, not the values. So when you do this:url=url+"?rem="+str1+"-"+str2+"-"+str3The url variables equals "5remfind.php?rem=date1-date2-date3". If you want to get the values of the elements you can use document.getElementById to get the element you want and then the value property will contain the value.document.getElementById(str1).valuethanks, worked flawlessly, that was the code I was looking for. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.