Jump to content
xisto Community
.hack//GU

Javascript Function Problem

Recommended Posts

I make this function:

<script language="JavaScript" type="text/javascript">	function validFormUse(passF)	{		if(passF.user.value == "") return false;		if(passF.pass.value == "") return false;		return true	}</script>

I want to make :

if(passF.user.value == "") return false;

like this:

if(passF.user.value == ""){ alert("FALSE"); return false;}

but, it doesn;t work. Why? I use the brackets and it doens't work. only if it doesn't use brackets it is fully operational. anybody know what's wrong?

Notice from BuffaloHELP:
Please use correct bbcode for posting codes.

Share this post


Link to post
Share on other sites

Without brackets it would have the alert then always return false since it would only treat the alert as part of the if statement. I see no reason why it wouldn't work the second way, though.

Share this post


Link to post
Share on other sites

yes, in the first code it return false if the brackets is empty. But, what I mean is when I use brackets, well is pops up the window (alert), but the browser goes through the action in the form, means it doesn't return false. So, in short, I can only have 1 command after 'if' and cannot use any brackets. Is that possible for mistake? thanks in advance

Share this post


Link to post
Share on other sites
<script language="JavaScript" type="text/javascript">function validFormUse(passF){if(passF.user.value == "") return false;if(passF.pass.value == "") return false;return true}</script>

If iam not mistake...you're going to check 2 element user and pass that should not be submitted
until both is filled with a string...

how about using this code :

<form .... onSubmit="if (validFormUse('blablabla')) this.submit(); else return false;">......</form><script language="JavaScript" type="text/javascript">function validFormUse(passF){  if (passF.user.value == "") {	alert('Please entry your user name');	passF.user.focus();	return false;  } else if (passF.pass.value == "") {	alert('Please entry your password');	passF.pass.focus();	return false;  } else ruturn true;}</script>

i've add an alert() and focus() function so it would have information, and
pointing to `FALSE` element. so user can type without moving their mice.


i hope it could help you.

Share this post


Link to post
Share on other sites

It is probably syntax. Here is what I suggest:

Open up Firefox, go to tools-> Javascript console and hit "Clear".
Then open your page and test the script.
Then open up the Javascript console again and see what are the errors.

Hope this helps. Paste the error reports here.

Anyway, Javascript uses soft-typing. So

if (sth == ""){}

is the same as

if (sth){}

because null translates to false.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.