Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Javascript problem with alert
Old 07-12-2012, 10:09 AM Javascript problem with alert
Average Talker

Posts: 18
Name: Phill Brown
Trades: 0
I have this pice of code:

Code:
    function validator() {
    var l1 = document.calculation.l1.value;
    var l2 = document.calculation.l2.value;
    var right = document.calculation.right.value;
     
 
if (l1 == null || l1 == "") alert("error ");
else if (l1 == null || l2 == "") alert("error");
else if (l1 == null || right == "") alert("error");
else if (right == 1) { alert("Correct"); }
 
  else { alert("Incorrect incorect"); } 
 
return false;
};
In Firefox is ok, but in Chrome the alert box is displayed before pressing the Submit button from my form. What can be wrong here?
__________________
I have a
Please login or register to view this content. Registration is FREE
and I write about
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
and
Please login or register to view this content. Registration is FREE
.
RedPitbull is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-12-2012, 12:00 PM Re: Javascript problem with alert
miki86's Avatar
Extreme Talker

Posts: 239
Location: print_r($serbia);
Trades: 0
Where did you put validator() ? On which event?
miki86 is offline
Reply With Quote
View Public Profile
 
Old 07-12-2012, 01:02 PM Re: Javascript problem with alert
Average Talker

Posts: 18
Name: Phill Brown
Trades: 0
Well, validator is the function that I have for a small form.
I'm calling it this way (the function is in a speratate file that I have declared it in header):
Code:
...............
...............
<input type="text" value=""  name="l2" size="10" />

<input type="submit" value="Check your answer" onClick="return validator();">  


  
<script type="text/javascript"><!--//--><![CDATA[//><!--
onClick(validator());  //--><!]]&gt;</script>
__________________
I have a
Please login or register to view this content. Registration is FREE
and I write about
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
and
Please login or register to view this content. Registration is FREE
.

Last edited by RedPitbull; 07-12-2012 at 01:04 PM..
RedPitbull is offline
Reply With Quote
View Public Profile
 
Old 07-12-2012, 03:02 PM Re: Javascript problem with alert
miki86's Avatar
Extreme Talker

Posts: 239
Location: print_r($serbia);
Trades: 0
Try to change it to onSubmit and put that tag inside the <form> element like in this example:
http://www.w3schools.com/jsref/event_form_onsubmit.asp
miki86 is offline
Reply With Quote
View Public Profile
 
Old 07-13-2012, 08:44 AM Re: Javascript problem with alert
chrishirst's Avatar
Defies a Status

Posts: 43,966
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
So what is the script element in that code supposed to be doing?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Javascript problem with alert
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.18544 seconds with 11 queries