نیلوفر66
سه شنبه 13 اسفند 1392, 19:53 عصر
یک فرم آپدیت هست که از یک کمبوباکس نام انتخاب میشود و کد به صفحه دیگری با تابع ایجکس ارسال میشود و اطلاعات را در div نشان میدهد تنها داده ای که در دایو آپدیت می شود تصویر هست که قبل از آپدیت چک میشود که آیا فایلی وارد شده است یا نه؟
اما در این کد پیغام خطای عدم انتخاب فایل نمایش داده می شود وسپس به صفحه ارسال اطلاعات میرود action
<head>
<script>
//AJAX ,اجاکس , ایجکس , اژاکس
//check browser
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;
}
//send data to other page
function unews()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
url='news-update-db.php?news='+document.getElementById("news").options[document.getElementById('news').selectedIndex].value;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
return false;
}
//get data from server
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("mdiv").innerHTML=xmlHttp.responseText;
}
}
function update()
{
if (document.getElementById('pic').value=="")
{
alert("فایلی انتخاب نشده است.")
return false;
}
return true;
}
</script>
</head>
<body>
<form action="news-update-data.php" method="post">
<table align="center" cellpadding="0" cellspacing="0" width="500" border="0" >
<tr class="tr" height="30"><td colspan="3">به روزرسانی </td></tr>
<tr height="20"><td colspan="3"></td></tr>
<tr style="font-family:'B Koodak', 'B Zar';" height="70" ><td width="315" align="left">عنوان اطلاعیه :</td>
<td dir="ltr" width="135" align="center"><select id="news" name="n1" style="font-size:12pt;font-family:'B Koodak', 'B Zar';" onchange="unews()">
<option id='op' value="0">-- انتخاب کنید -- </option>
<?php
include('db.php');
$link=mysql_query("select n_id ,n_title from news ");
while($row=mysql_fetch_assoc($link))
{
echo "<option id='op' value='$row[n_id]' >".$row['n_title']."</option>";
}
echo "</select></td><td width='255' align='right'><a href='#t' title='نمایش'><img src='img/4339.png' width='35' height='35' style='border:hidden;' /></a></td></tr>
<td colspan='3'>
<p />
//اطلاعات از فرم دیگری پر می شود و نشان داده میشود سپس آپدیت<div id='mdiv'></div>
</td></tr>
";
?>
<tr align='center'><td colspan='2' ><input type='submit' name='newsupdate' value='به روزرسانی ' onclick='update()'/></td></tr>
</table></form>
</body>
اما در این کد پیغام خطای عدم انتخاب فایل نمایش داده می شود وسپس به صفحه ارسال اطلاعات میرود action
<head>
<script>
//AJAX ,اجاکس , ایجکس , اژاکس
//check browser
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;
}
//send data to other page
function unews()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
url='news-update-db.php?news='+document.getElementById("news").options[document.getElementById('news').selectedIndex].value;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
return false;
}
//get data from server
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("mdiv").innerHTML=xmlHttp.responseText;
}
}
function update()
{
if (document.getElementById('pic').value=="")
{
alert("فایلی انتخاب نشده است.")
return false;
}
return true;
}
</script>
</head>
<body>
<form action="news-update-data.php" method="post">
<table align="center" cellpadding="0" cellspacing="0" width="500" border="0" >
<tr class="tr" height="30"><td colspan="3">به روزرسانی </td></tr>
<tr height="20"><td colspan="3"></td></tr>
<tr style="font-family:'B Koodak', 'B Zar';" height="70" ><td width="315" align="left">عنوان اطلاعیه :</td>
<td dir="ltr" width="135" align="center"><select id="news" name="n1" style="font-size:12pt;font-family:'B Koodak', 'B Zar';" onchange="unews()">
<option id='op' value="0">-- انتخاب کنید -- </option>
<?php
include('db.php');
$link=mysql_query("select n_id ,n_title from news ");
while($row=mysql_fetch_assoc($link))
{
echo "<option id='op' value='$row[n_id]' >".$row['n_title']."</option>";
}
echo "</select></td><td width='255' align='right'><a href='#t' title='نمایش'><img src='img/4339.png' width='35' height='35' style='border:hidden;' /></a></td></tr>
<td colspan='3'>
<p />
//اطلاعات از فرم دیگری پر می شود و نشان داده میشود سپس آپدیت<div id='mdiv'></div>
</td></tr>
";
?>
<tr align='center'><td colspan='2' ><input type='submit' name='newsupdate' value='به روزرسانی ' onclick='update()'/></td></tr>
</table></form>
</body>