Click to See Complete Forum and Search --> : There IS a bug


echo
04-12-2003, 09:43 PM
I REALLY FEEL LIKE SMASHING THE GUY WHO INVENT JAVASCRIPT!

Another look at my js code would make me vomit! If somebody have any ideas why, would be very much appreciated.

The Problem:



[HTML Form]
<form name="frm" id="frm" method="post" onsubmit="return checkForm(this)">

<input name="name" type="text" id="name">

<select name="country">
<option value="">Select A Country</option>
<option value="SGP">Singapore</option>
<option value="USA">United States</option>
<option value="MYS">Malaysia</option>
<option value="AFG">Afghanistan</option>
<option value="ALB">Albania</option>
</select>

<input name="email" id="email" type="text">

<input name="phone" type="text" id="phone">





[Javascript Code]
function checkForm( frm )
{

if ( frm.title.value == '' )
{
alert( "Error: Please specify your title" );
frm.title.focus( );
return false;
}

if ( frm.name.value == '' )
{
alert( "Error: Please enter your name" );
frm.name.focus( );
return false;
}

if ( frm.country.value == '' )
{
alert( "Error: Please specify your country" );
frm.country.focus( );
return false;
}

if ( frm.email.value == '' )
{
alert( "Error: Please enter your email address" );
frm.email.focus( );
return false;
}

if ( frm.phone.value == '' )
{
alert( "Error: Please enter your phone no." );
frm.phone.focus( );
return false;
}

if ( frm.projsum.value == '' )
{
alert( "Error: Please enter your project summary" );
frm.projsum.focus( );
return false;
}

}



Javascript only validate the name and country and a textfield (projsum), while no matter what, email and phone can never be prompt! When I set

if ( frm.email.value == null ) <--- instead

It prompt, but when I click ok, the form gets submitted. damn i really can't figure out, javascript is so much full of bugs and is so sensitive unlike serverside codes.

Nedals
04-12-2003, 10:07 PM
A brief check of your code and it seemed to work with the following additions, which I assume are already in your HTML code but not shown.

I added a 'projsum' field, a 'submit button', and a </form> tag

Incidently, you don't need all the 'id=name'

echo
04-13-2003, 01:15 AM
thanks for your reply nedals, yes, the additions was there which I've not added here. I've try removing the id='' away but no dice. Also, how do you explain (if you have any ideas) why is it that for

if ( frm.email.value == '' ) // alert don't work

if ( frm.email.value == null ) // alert work

:confused:

Nedals
04-13-2003, 01:42 AM
if ( frm.email.value == '' ) // alert don't work
Should work. As I said, what you posted worked as expected. Do you have more script or additional form elements that use the same names? (a common problem easily missed).

Oh! and don't forget to 'return true' if checkForm is valid

echo
04-13-2003, 02:21 AM
Do you have more script or additional form elements that use the same names?

I WOULD HAVE TO SAY, NEDALS!!!! YOU ROCKS BIG TIME!!! ;)

Geeeeez, I have 3 radio element. email, fax, phone. Almost smash my pc. I would have to bow to you, Nedals.

Nevermore
04-13-2003, 06:41 AM
Instead of if ( frm.email.value == null ) you can just use
if(!frm.email.value)