28, May 2012

Calling Two Different Functions onSubmit - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  JavaScript
Topic: Calling Two Different Functions onSubmit
« previous next »
Pages: [1] 2 Print
Instabuck - The easy way to sell digital products online

Author Topic: Calling Two Different Functions onSubmit  (Read 4633 times)
Pinoy Webmaster
.com pimp
*****
Gender: Male
Posts: 1126
6048 credits
Members referred : 0


Philippine Beaches


« on: Sep 19, 2007, 04:26:46 pm »

guys, here i go again:

i have two functions i want to call when my user clicks the submit button in my form. how should i do it? here is the code i found on the web:

Function 1
Code:
<script>

/*
Check required form elements script-
By JavaScript Kit (http://javascriptkit.com)
Over 200+ free scripts here!
*/

function checkrequired(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
pass=false
break
}
}
}
}
if (!pass){
alert("One or more of the required fields are not completed. Please complete them, then submit again!")
return false
}
else
return true
}
</script>

onSubmit="return checkrequired(this)"

Function 2
Code:
function onSubmitForm( f, ext ){
//(C)2006 Stephen Chalmers

var badName="", allBlank=true, rx;

rx=new RegExp("[^\.]\."+ext+"\s*$", "i");

for( var i=0,e=f.elements; i<e.length; i++ )
{
if( e[i].type=='file' )
{
e[i].value=e[i].value.replace(/^\s+/,'').replace(/\s+$/,'');

if( e[i].value.length )
{
allBlank=false;
if( !rx.test(e[i].value) )
badName+='\n\n' + e[i].value;
}
}
}

if( allBlank )
alert("Please click on 'Browse' and select a file to upload.")
else
if( badName )
alert( 'A required .'+ext+' extension was not found in:' + badName );

return (badName || allBlank) ? false : true;
}

onSubmit="return onSubmitForm(this, [\'gif\', \'jpg\', \'jpeg\'])"

i wish to validate some required fields and the file name of the photo they will upload.


Last blog : Bingag Beach, Bohol, Philippines
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Sep 19, 2007, 04:48:34 pm »

create a third function that calls the other two Smiley

Pinoy Webmaster
.com pimp
*****
Gender: Male
Posts: 1126
6048 credits
Members referred : 0


Philippine Beaches


« Reply #2 on: Sep 19, 2007, 04:58:46 pm »

Code:
function Third {
var Rtn = true;
Rtn = checkrequired(this);
if (Rtn) {
Rtn = onSubmitForm(this, ['gif', 'jpg', 'jpeg']);
}
return Rtn;
}

onSubmit="return Third()"

i tried this but it didnt work. please correct it.


Last blog : Bingag Beach, Bohol, Philippines
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Sep 19, 2007, 05:23:10 pm »

just read your full post Smiley

I think you can't validate the filename before upload.

but why not validating the whole thing on the server site (using php)?

check this demo:
http://www.finalwebsites.com/demos/php_file_upload.php

Pinoy Webmaster
.com pimp
*****
Gender: Male
Posts: 1126
6048 credits
Members referred : 0


Philippine Beaches


« Reply #4 on: Sep 19, 2007, 05:33:26 pm »

the two functions work separately but when i call the two, it doesnt anymore. is there anything wrong with the code?


Last blog : Bingag Beach, Bohol, Philippines
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Sep 19, 2007, 06:30:07 pm »

the two functions work separately but when i call the two, it doesnt anymore. is there anything wrong with the code?

i think the problem is this, btw you need these functions together like:
if all fields are valid then validate the file name...

Pinoy Webmaster
.com pimp
*****
Gender: Male
Posts: 1126
6048 credits
Members referred : 0


Philippine Beaches


« Reply #6 on: Sep 19, 2007, 06:59:03 pm »

tried it on my own but i wasnt able to make it work. any help with the code for combining or calling the two functions at the same time will be very much appreciated!
« Last Edit: Sep 19, 2007, 07:57:19 pm by vbignacio »


Last blog : Bingag Beach, Bohol, Philippines
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #7 on: Sep 20, 2007, 09:32:48 am »

First of all, can you explain what exactly do you want to do?

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #8 on: Sep 20, 2007, 09:38:55 am »

First of all, can you explain what exactly do you want to do?

he is trying something similar to my demo link Smiley

Pinoy Webmaster
.com pimp
*****
Gender: Male
Posts: 1126
6048 credits
Members referred : 0


Philippine Beaches


« Reply #9 on: Sep 20, 2007, 09:46:55 am »

thanks. i just want to validate a form for the required fields and the file name of the photos to be uploaded just using javascript. i cant do it server side because i already have php functions implemented and i dont want to complicate it further, me not being a programmer...


Last blog : Bingag Beach, Bohol, Philippines
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #10 on: Sep 20, 2007, 09:52:32 am »

Validate the file name against what? If the file is not empty, then it is correct, right?

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Pinoy Webmaster
.com pimp
*****
Gender: Male
Posts: 1126
6048 credits
Members referred : 0


Philippine Beaches


« Reply #11 on: Sep 20, 2007, 10:19:33 am »

if they are submitting the right file format: jpeg, jpg, gif, png... and they are filling the required fields before it gets sent to my server.


Last blog : Bingag Beach, Bohol, Philippines
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #12 on: Sep 20, 2007, 11:56:15 am »

if they are submitting the right file format: jpeg, jpg, gif, png... and they are filling the required fields before it gets sent to my server.

maybe you should post the existing php code, adding the two rows for validation is much easier then writing some new JS function

Pinoy Webmaster
.com pimp
*****
Gender: Male
Posts: 1126
6048 credits
Members referred : 0


Philippine Beaches


« Reply #13 on: Sep 20, 2007, 12:48:25 pm »

thanks man. i decided to just convert whatever file they uploaded into a jpeg file.


Last blog : Bingag Beach, Bohol, Philippines
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #14 on: Sep 20, 2007, 01:42:17 pm »

thanks man. i decided to just convert whatever file they uploaded into a jpeg file.

yeah use imagemagicks (but you need to prevent the upload of dangerous files (scripts))

Pinoy Webmaster
.com pimp
*****
Gender: Male
Posts: 1126
6048 credits
Members referred : 0


Philippine Beaches


« Reply #15 on: Sep 20, 2007, 03:00:54 pm »

even if i convert those dangerous file or scripts into .jpeg file, are they still dangerous?


Last blog : Bingag Beach, Bohol, Philippines
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #16 on: Sep 20, 2007, 03:08:55 pm »

even if i convert those dangerous file or scripts into .jpeg file, are they still dangerous?

I guess this should be answered by a Linux guru Smiley

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #17 on: Sep 20, 2007, 07:49:31 pm »

As far as I know nothing is dangerous unless you do it Smiley

If you are moving the files to a standard directory, and you are not using those files to run code (which would be impossible with php anyway) you wont have any problems.

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Pinoy Webmaster
.com pimp
*****
Gender: Male
Posts: 1126
6048 credits
Members referred : 0


Philippine Beaches


« Reply #18 on: Sep 20, 2007, 09:21:47 pm »

thanks for the help!


Last blog : Bingag Beach, Bohol, Philippines
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #19 on: Sep 20, 2007, 09:25:00 pm »

As far as I know nothing is dangerous unless you do it Smiley

If you are moving the files to a standard directory, and you are not using those files to run code (which would be impossible with php anyway) you wont have any problems.
so I cant run a (risky) script via the browser like http://www.domain.com/dir/somescript.jpg?

Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7134
Tags : javascript form submit Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] 2 Print 
Webdigity Webmaster Forums  >  Web Development  >  JavaScript
Topic: Calling Two Different Functions onSubmit
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 09:22:00 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.