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
validate and not coninue on
Old 06-02-2005, 11:51 PM validate and not coninue on
Skilled Talker

Posts: 69
Trades: 0
Hello,

I have the following script. The error message pops up but then when I click ok, the browser continues on to the result page. Is there a way just to alert and stay on the same page?

<form enctype="multipart/form-data" action="uploadimage.php" method="post" name="picture">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" maxlength="15"/>
<input type="hidden" name="id" value="10025">
<table border="1" align="center">
<tr><td valign="top" width="590">Image file size must be less than 100 Kilobytes and be less than 200 px wide. Image format must be either JPG or GIF or animated GIF.
</td></tr>
<tr><td align="center">

<script type="text/javascript">
<!--
var photo
function formvalidation (photo)
{
var pict = document.picture.userfile.value;
if (pict.length >15 || pict.length <2) {
alert("Your file name must be less than 16 letters and more than 1 letter.");
}
else if (pict.search(/[^\w]/)>-1) {
alert("Your file name must be letters and numbers only");
}
}
</script>

Logo file: <input name="userfile" type="file" maxlength="15"/><br>Your file name can be letters and numbers only, without spaces.<br>
<input type="submit" value="Send Image File" onclick="formvalidation(photo)"/>
form>


Thanks,
Matt
weddingm is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-03-2005, 12:03 AM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
If you return false on error, the page will not submit.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 06-03-2005, 12:33 AM
Skilled Talker

Posts: 69
Trades: 0
sorry to say but I added a "return false;" after the alert and when I click ok in the alert window, it still submits the form ????
weddingm is offline
Reply With Quote
View Public Profile
 
Old 06-03-2005, 01:17 AM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Oops. The onclick function must also have a "return" before, to "pass on" the value of the validation.

You should also use onsubmit on the forum instead of onclick on the submit buttonL
Code:
<form enctype="multipart/form-data" action="uploadimage.php" method="post" name="picture" onsubmit="return formvalidation(photo);">
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 06-03-2005, 10:40 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Quote:
Oops. The onclick function must also have a "return" before,
How many times have i fallen for this one.......

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Reply     « Reply to validate and not coninue on
 

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.37841 seconds with 12 queries