dear all. i have a form that consist of two textfield and one combobox. i want prevent the duplicate entry data from client side. i get combobox data from DB, like:
<select id="line" name="faline" >
<?php
$sql="SELECT `Line_Name` FROM `prod_sch` WHERE `Line_Name` LIKE 'FA %' GROUP BY `Line_Name` ORDER BY `Line_Name`";
if ($sql) {
$res=mysql_query($sql) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() );
}
while ($dat = mysql_fetch_array($res, MYSQL_NUM)) {
echo "\t\t\t\t\t\t\t\t<option value='".$dat[0]."'>".$dat[0]."</option>\n";
}
?>
</select>
nasıl bu kodu birleştirmek veya değiştirmek için:
<script language="javascript" type="text/javascript">
$(function() {
$("#Button1").click(function(e) {
var itemExists = false;
var txt = $("#Text1").val();
e.preventDefault();
$("#Select1 option").each(function() {
if ($(this).text() == $.trim(txt)) {
itemExists = true;
alert('Item already exists');
}
});
if (!itemExists) {
$("#Select1").append("<option value=\"1\">" + txt + "</option>");
$("#Text1").val('');
}
});
});
</script>