Jump to content

[SOLVED] Ajax variable undefined??


garethhall

Recommended Posts

I am working on a CMS system and I want to use ajax to update my DB when the user changes the radio button state.

 

I know that the code is incomplete but I am just alerting the the URL variables so that I know that my php page get the right information.

 

I just need help on why my variable is undefined?

 

alert result is "cmsLiveUpdatePageStatus.php?pageId=1&pageStatus=undefined" why is pageStatus undefined??

 

php source code

      <?php do { ?>
        <tr class="tableBG1">
        <form name="formId<?php echo $row_rs_ListPages['pageId']; ?>" method="post" action="">
          <td class="row">
          <input name="pageId" type="hidden" id="pageId" value="<?php echo $row_rs_ListPages['pageId']; ?>" />
          <?php echo $row_rs_ListPages['pageMetaTitle']; ?></td>
          <td><?php echo $row_rs_ListPages['pageMetaDescription']; ?></td>
          <td><?php echo $row_rs_ListPages['pageDate']; ?></td>
          
            <td align="center" valign="middle"><a href="cmsEditPage.php?pageId=<?php echo $row_rs_ListPages['pageId']; ?>"><img src="cmsImages/btnEdit.png" width="56" height="16" alt="Edit" /></a>•<a href="<?php echo $row_rs_ListPages['pagePath']; ?>" target="_blank"><img src="cmsImages/btnView.png" width="56" height="16" alt="Delete" /></a>
            <input <?php if (!(strcmp($row_rs_ListPages['pageStatus'],"on"))) {echo "checked=\"checked\"";} ?> type="radio" name="status" value="on" onchange="updatePageStatus(pageId.value, status.value)" />
            On
            <input <?php if (!(strcmp($row_rs_ListPages['pageStatus'],"Off"))) {echo "checked=\"checked\"";} ?> type="radio" name="status" value="off" onchange="updatePageStatus(pageId.value, status.value)" />
           Off</td></form>
        </tr>
        <?php } while ($row_rs_ListPages = mysql_fetch_assoc($rs_ListPages)); ?>
    </table>

 

javascript or ajax

var xmlHttp
function updatePageStatus(pageId, status){
xmlHttp=GetXmlHttpObject()
if(xmlHttp==null){
	alert("Browser does not support HTTP Request");
	return;
}; 
var url="cmsLiveUpdatePageStatus.php";
url += "?pageId="+pageId;
url += "&pageStatus="+status;
alert(url);
xmlHttp.onreadystatechange=stateChanged ;
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
};

function GetXmlHttpObject(){
var xmlHttp=null;
try{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
}catch (e){
	// Internet Explorer
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}catch (e){
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	};
};
return xmlHttp;
};

 

the generated html/php

              <tr class="tableBG1">
        <form name="formId1" method="post" action="">
          <td class="row">
          <input name="pageId" type="hidden" id="pageId" value="1" />
          Home: Smart Photography</td>
          <td>Home Description</td>
          <td>2009-03-21</td>
          
            <td align="center" valign="middle"><a href="cmsEditPage.php?pageId=1"><img src="cmsImages/btnEdit.png" width="56" height="16" alt="Edit" /></a>•<a href="http://www.smart-photography.co.nz/index.php" target="_blank"><img src="cmsImages/btnView.png" width="56" height="16" alt="Delete" /></a>
            <input checked="checked" type="radio" name="status" value="on" onchange="updatePageStatus(pageId.value, status.value)" />
            On
            <input  type="radio" name="status" value="off" onchange="updatePageStatus(pageId.value, status.value)" />
           Off</td></form>
        </tr>
                <tr class="tableBG1">
        <form name="formId2" method="post" action="">
          <td class="row">
          <input name="pageId" type="hidden" id="pageId" value="2" />
          About: Smart Photography</td>
          <td>Meta Description</td>
          <td>2009-03-21</td>
          
            <td align="center" valign="middle"><a href="cmsEditPage.php?pageId=2"><img src="cmsImages/btnEdit.png" width="56" height="16" alt="Edit" /></a>•<a href="http://www.smart-photography.co.nz/about.php" target="_blank"><img src="cmsImages/btnView.png" width="56" height="16" alt="Delete" /></a>
            <input checked="checked" type="radio" name="status" value="on" onchange="updatePageStatus(pageId.value, status.value)" />
            On
            <input  type="radio" name="status" value="off" onchange="updatePageStatus(pageId.value, status.value)" />
           Off</td></form>
        </tr>
                <tr class="tableBG1">
        <form name="formId3" method="post" action="">
          <td class="row">
          <input name="pageId" type="hidden" id="pageId" value="3" />
          Gallery: Smart Photography</td>
          <td>Smart Photography</td>
          <td>2009-03-21</td>
          
            <td align="center" valign="middle"><a href="cmsEditPage.php?pageId=3"><img src="cmsImages/btnEdit.png" width="56" height="16" alt="Edit" /></a>•<a href="http://www.smart-photography.co.nz/gallery.php" target="_blank"><img src="cmsImages/btnView.png" width="56" height="16" alt="Delete" /></a>
            <input checked="checked" type="radio" name="status" value="on" onchange="updatePageStatus(pageId.value, status.value)" />
            On
            <input  type="radio" name="status" value="off" onchange="updatePageStatus(pageId.value, status.value)" />
           Off</td></form>
        </tr>
                <tr class="tableBG1">
        <form name="formId4" method="post" action="">
          <td class="row">
          <input name="pageId" type="hidden" id="pageId" value="4" />
          Contact: Smart Photography</td>
          <td>Smart Photography</td>
          <td>2009-03-21</td>
          
            <td align="center" valign="middle"><a href="cmsEditPage.php?pageId=4"><img src="cmsImages/btnEdit.png" width="56" height="16" alt="Edit" /></a>•<a href="http://www.smart-photography.co.nz/contact.php" target="_blank"><img src="cmsImages/btnView.png" width="56" height="16" alt="Delete" /></a>
            <input checked="checked" type="radio" name="status" value="on" onchange="updatePageStatus(pageId.value, status.value)" />
            On
            <input  type="radio" name="status" value="off" onchange="updatePageStatus(pageId.value, status.value)" />
           Off</td></form>
        </tr>
                <tr class="tableBG1">
        <form name="formId5" method="post" action="">
          <td class="row">
          <input name="pageId" type="hidden" id="pageId" value="5" />
          Login: Smart Photography</td>
          <td>log in</td>
          <td>2009-03-21</td>
          
            <td align="center" valign="middle"><a href="cmsEditPage.php?pageId=5"><img src="cmsImages/btnEdit.png" width="56" height="16" alt="Edit" /></a>•<a href="http://www.smart-photography.co.nz/login.php" target="_blank"><img src="cmsImages/btnView.png" width="56" height="16" alt="Delete" /></a>
            <input checked="checked" type="radio" name="status" value="on" onchange="updatePageStatus(pageId.value, status.value)" />
            On
            <input  type="radio" name="status" value="off" onchange="updatePageStatus(pageId.value, status.value)" />
           Off</td></form>
        </tr>
            </table>

</div>
</body>

 

Link to comment
https://forums.phpfreaks.com/topic/156914-solved-ajax-variable-undefined/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.