Click to See Complete Forum and Search --> : Problem about sending form data


black_hawk
08-04-2006, 06:14 PM
Hi friends
There is a html file whose name is user.htm . I use it to add new user to my system it has a form that includes text and button.I control the values of the text and if there is no value at the field of the textbox, an alert appears to warn user. And after that if user enters valid values, the pogram should send form data to the related script.But it doesn't send.If user enters valid values for the first time, there is no problem but he enters invalid values and after that he enters valid values, this problem occurs.Is there anybody to help me about this?

My code is:

<html>
<head>
</head>

<body bgcolor="F9F9F9">
<form action="user.php" method="get">
<table>
<tr>
<td><font color="#526569">Kullanıcı Adı:</font></td>
<td><input type="text" name="k_adi" value=""></td>
</tr>
<tr>
<td><font color="#526569">Şifre:</font></td>
<td><input type="password" name="sifre" value=""></td>
</tr>
<tr>
<td><font color="#526569">Şifre(Yeniden):</font></td>
<td><input type="password" name="sifre_y" value=""></td>
</tr>
<tr>
<td><font color="#526569">Kullanıcı Tipi:</font></td>
<td>
<select name="k_tip">
<option value="2" selected>Seçin</option>
<option value="1">Admin</option>
<option value="0">User</option>
</select>
</td>
</tr>
<tr>
<td align="right" colspan="2"><input type="button" value="Ekle" onClick="javascript:
if((k_adi.value!='')&&(sifre.value!='')&&(sifre_y.value!='')&&(k_tip.value!=2))
{
if(sifre.value==sifre_y.value)
{
submit();
window.close();
}
else
{
window.alert('Girmiş olduğunuz şifreler arasında tutarsızlık var.');
window.location.href='user.htm';
}
}
else
{
window.alert('Lütfen tüm alanları doldurunuz.');
window.location.href='user.htm';
}
"></td>
</tr>
</table>
</form>
</body>
</html>

ray326
08-05-2006, 12:02 AM
Use an onsubmit handler to do field validation instead of imbedding it in the widget.

black_hawk
08-05-2006, 08:02 AM
Thanks for your attention ray326
I modified my code by using onSumbit but same problem occured.The code:

<html>
<head>
</head>

<body bgcolor="F9F9F9">
<script type="text/javascript">
function controlContent()
{
var k_adi=document.info.k_adi.value;
var sifre=document.info.sifre.value;
var sifre_y=document.info.sifre_y.value;
var k_tip=document.info.k_tip.value;
var control;
if((k_adi!='')&&(sifre!='')&&(sifre_y!='')&&(k_tip!=2))
{
if(sifre==sifre_y)
{
control=true;
window.close();
}
else
{
control=false;
window.alert('Girmiş olduğunuz şifreler arasında tutarsızlık var.');
//window.location.href='user.htm';
}
}
else
{
control=false;
window.alert('Lütfen tüm alanları doldurunuz.');
//window.location.href='user.htm';
}
return control;
}
</script>
<form name="info" action="user.php" method="post" onSubmit="return controlContent()">
<table>
<tr>
<td><font color="#526569">Kullanıcı Adı:</font></td>
<td><input type="text" name="k_adi" value=""></td>
</tr>
<tr>
<td><font color="#526569">Şifre:</font></td>
<td><input type="password" name="sifre" value=""></td>
</tr>
<tr>
<td><font color="#526569">Şifre(Yeniden):</font></td>
<td><input type="password" name="sifre_y" value=""></td>
</tr>
<tr>
<td><font color="#526569">Kullanıcı Tipi:</font></td>
<td>
<select name="k_tip">
<option value="2" selected>Seçin</option>
<option value="1">Admin</option>
<option value="0">User</option>
</select>
</td>
</tr>
<tr>
<td align="right" colspan="2"><input type="Submit" value="Ekle"><td>
</tr>
</table>
</form>
</body>
</html>


May my problem be about cleanup text usage? I heard this function before but i haven't used it.

ray326
08-05-2006, 12:15 PM
Declare control=false and remove that window.close().

black_hawk
08-05-2006, 01:06 PM
Thanks ray326
This is the solution.But the point ,that I did not understend, is 'window.close()'. Why does this method prevent my data to go to the script?

ray326
08-06-2006, 02:44 PM
Unknown. Maybe the Javascript engine threw an unhandled exception at that point.