/    Sign up×
Community /Pin to ProfileBookmark

There IS a bug

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:

[code=php]

[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”>

[/code]

[code=php]

[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;
}

}

[/code]

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.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@NedalsApr 13.2003 — 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'
Copy linkTweet thisAlerts:
@echoauthorApr 13.2003 — 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

?
Copy linkTweet thisAlerts:
@NedalsApr 13.2003 — [i]if ( frm.email.value == '' ) // alert don't work [/i]

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
Copy linkTweet thisAlerts:
@echoauthorApr 13.2003 — Do you have more script or additional form elements that use the same names? [/QUOTE]

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.
Copy linkTweet thisAlerts:
@NevermoreApr 13.2003 — Instead of if ( frm.email.value == null ) you can just use

if(!frm.email.value)
×

Success!

Help @echo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...