hi,
i posted this in the javascript forums but didn't get any replies, maybe this is a better place.
i have a website for properties (rent, sell, etc), using php and mysql. i allow the admin to manage existing properties by selecting the property id from a dropdown
that lists all properties ids from the database, or by directly entering the property id in a textbox and submitting a form to go to this property and edit or delete
it.
now when the admin decides to enter the property id in the textbox instead of selecting it from the dropdown, i need to validate the id they entered and it needs to
exist in the database or i dont submit the form and show them an alert msg that they should enter id for existing property. i would like to do this when they click the
submit button of the form using javascript, where the javascript will get the textbox value and compare it to the results i got from the mysql database using php.
Can you please tell me how to write the javascript function to validate the id? here is my part of the code that has the form:
<form name="form1" method="post" action="<? echo($target_page);?>">
<table width="90%" height="37" border="0" align="center" cellpadding="5" cellspacing="5">
<tr>
<td width="40%">Select property id from the drop down list,</td>
<td>
<select name="id2" style="font-family:Verdana; font-size: 8pt;">
<?
$reza=mysql_query("select id from $table order by id desc");
while ($row=mysql_fetch_array($reza)){
$id2=$row["id"];
echo " <option value=\"$id2\">$id2</option>";
}
?>
</select>
<script language="JavaScript">
function submit_form(target_page,this_property){
var id_value=document.getElementById("id1").value;
if(id_value!=""){
for(loop php ids here){
if(id_value==php id value here){
document.location = target_page;
}
else{
alert("id does not exist");
}
}
</script>
</td>
</tr>
<tr>
<td>or type property id in the text box,</td>
<td><input type="text" name="id1" value="" size="1" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
<tr>
<td colspan="2">
Or find property from the list below.
</td>
</tr>
</table>
</form>