2013-07-31 30 views
0
<form name="reservation" id="reservation" class="reservation" action="validate_form.php" method="post"> 
<input type="hidden" name="side_check_in_date" id="side_check_in_date" value=""/> 
<input type="hidden" name="side_check_out_date" id="side_check_out_date" value=""/> 
<select name="side_room_type" id="room_type" onchange="return getAdultRoom(this.value)" class="input-medium"><?=room_type_cmb();?></select> 
<script> 
var xmlHTTP; 
function GetXmlHttpObject() 
{ 
    xmlHTTP=null; 
    try 
    { 
     xmlhttp=new XMLHttpRequest(); 
    } 
    catch (e) 
    { 
     try 
     { 
      xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");    
     } 
     catch (e) 
     { 
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
     } 
    } 

} 
function getAdultRoom(room_id) 
{ 
      if (window.XMLHttpRequest) 
      { 
      xmlhttp=new XMLHttpRequest(); 
      } 
     else 
      { 
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
      } 

      if(xmlhttp == null) 
      { 
       alert("Your browser not support the AJAX"); 
       return; 
      } 

      var url = "ajax_fetch_room.php?room_id="+room_id; 
      //xmlhttp.onreadystatechang = handleResponce(); 
      xmlhttp.onreadystatechange=function() 
      { 
      if(xmlhttp.readyState==4 && xmlhttp.status==200) 
      { 
      document.getElementById("roomadult").innerHTML=xmlhttp.responseText; 

      } 
      } 
      xmlhttp.open("GET",url,true); 
      xmlhttp.send(null); 
} 
</script> 

嗨數據! 我有一個選擇框。當選擇房間時,它會從ajax_fetch_room.php獲取數據 上面的腳本正在工作,但我還添加了2個隱藏的輸入以形成入住和退房日期。當從日曆中選擇入住和退房日期時,隱藏的輸入正在改變。我想從ajax_fetch_rooms.php,因爲它的數據初級講座阿賈克斯 - 我怎樣才能改變使用隱藏輸入元素值

ajax_fetch_room.php ROOM_ID = 「+ ROOM_ID +」 & side_check_in_date = 「+ side_check_in_date +」 & side_check_out_date =「+ side_check_out_date;

應該如何我編輯它,使其工作

PS我不雷到了,只要jQuery的,因爲它的工作原理使用預先感謝您

回答

0

要使用jQuery獲得的價值:? $('#yourHiddenFieldId').val();

因此,它應該是這樣的:

room_id="+room_id+"&side_check_in_date="+$('#side_check_in_date').val()+"&side_check_out_date="+$('#side_check_out_date').val(); 

不喜歡用它應該被什麼東西:

document.getElementById('yourId').value 

所以這將轉化爲:

room_id="+room_id+"&side_check_in_date="+document.getElementById('side_check_in_date').value+"&side_check_out_date="+document.getElementById('side_check_out_date').value; 
+0

嗨!你能充分利用這個嗎?我不是很擅長ajax/jquery – hijacker83

+0

嗨!我編輯了答案,所以你不需要jQuery – Nick

+0

偏離主題,但我建議你看看$ .ajax(jQuery),它比'xmlhttp = new ActiveXObject(「Microsoft.XMLHTTP」);'更容易。如果您有一段時間,請在YouTube上搜索一些AngularJS教程 – Nick