PDA

View Full Version : form onsubmit problems


ecnarongi
10-01-2002, 08:11 PM
I have
<form action="go.asp" method="post" name="reg" target="regnow" onSubmit="javascript:window.open('','regnow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrol lbars=no,resizable=yes,width=413,height=250')">

but the attributes are not being hornored?? I've also tried to taken out the onsubmit event and putting the whole thing in an onClick event inside the button

"javascript:document.reg.submit() ;window.open('','regnow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,r esizable=yes,width=413,height=250')"

but I received the same results, all help is appreciated.

ecnarongi
10-01-2002, 09:38 PM
I've also tried putting the code in a function

function popReg(){
window.open('','regnow','resizable=yes,width=413,height=250');
return true;
}

and changing the form to onsubmit="return popReg" but it doesn't work, is there an issue in IE6??

beetle
10-01-2002, 10:09 PM
Ok, best I can tell you did one thing wrong with each of your attempts. In your first try, when using an event, the javascript: pseudo-protocol isn't needed. Oh, and window features by default are off or 'no', so you don't need to specify those.<form action="go.asp" method="post" name="reg" target="regnow" onSubmit="javascript:window. open('','regnow','toolbar=no,location=no,directori
es=no,status=no,menubar=no,scrollbars=no,resizable
=yes,width=413,height=250')">

<!-- Change to... -->

<form action="go.asp" method="post" name="reg" target="regnow" onSubmit="window.open('','regnow','resizable=yes,width=413,height=250');"> With your second try, you call the function as a string, which (I think) only works for assiging a function to an event within a script block.onsubmit="return popReg"

// Should be

onsubmit="return popReg()"Let me know...

Addendum: I looked closer at what you are doing and think you need this:function popReg(){
var regnow = window.open('about:blank','regnow','resizable=yes,width=413,height=250');
return true;

<form onSubmit="return popReg()">
}

ecnarongi
10-02-2002, 03:36 PM
I figured out the problem it seems to not honor the attributes when there is no submit button, since I am using a button with the document.formname.submit() method the onsubmit event is being totally ignored.

can someone help me :(

ecnarongi
10-02-2002, 03:40 PM
I am using a graphic as my submit button that's why I am not using the submit button, and I checked and <input type="image" ... > doesn't work either. All help is appreciated.

ecnarongi
10-02-2002, 03:41 PM
sorry I solved my problem. :thumbsup:

ecnarongi
10-02-2002, 08:34 PM
I may have solved my own problem but riddle me this...

I now need to check the form to see if fields are filled in, and I can't use the document.formname.submit() method what method do I use. My button is still a graphic (<input type='image'...>) and if I put an onClick event in the input element the form will still be submitted.

All help will be appreciated.

beetle
10-02-2002, 10:27 PM
Uh, the onSubmit event when properly attached to the FORM object should fire whenever the form is submitted, regardless of how it was invoked.

For your validation, the the fValidate link in my sig if you need something...

FYI: By default, an INPUT type=image will submit it's form when clicked.

whammy
10-03-2002, 02:23 AM
As beetle said, regardless of whether you are using his API or not, this concept applies to all programming languages...:

Make a list (array, database entry, variable, whatever) of what you want to validate.

Set a variable flag to true.

If what you want to validate doesn't meet your criteria, set the variable flag to false.

Return the variable flag... since it will now be a boolean. (Either true or false). Submit the form if the variable is true.

If you don't understand what I just said, then that's exactly what you need to learn! :D

P.S. Of course you can also do the same validation in reverse where logic requires it... and you will need to do all of this validation before you SUBMIT your data.

;)

ecnarongi
10-03-2002, 03:00 AM
Originally posted by beetle
Uh, the onSubmit event when properly attached to the FORM object should fire whenever the form is submitted, regardless of how it was invoked.

interesting you said that Bettle did you read my early problems? Is the above code wrong b/c using that code I can not get the onsubmit event to hornor the window attributes when I use the document.formname.submit() method. maybe I am just not focused I am having woman issues...DAMN!

and Whammy I know how to write the validation script (if you guys kept the old DB you could look me up) my problem lies with the onsubmit event and buttons... am I rambling :confused:

beetle
10-03-2002, 03:21 AM
Ah, I see. Here's your solutionfunction popReg(f) {
var regnow = window.open('','regnow','resizable=yes,width=130,height=250');
f.submit();
return false;
}

<form target="regnow">
<!-- form code -->
<input type="button" onClick="popReg(this.form);" value="Submit">
<!-- or -->
<input type="image" src="submit.gif" onClick="return false; popReg(this.form);">
</form>

glenngv
10-03-2002, 04:48 AM
FYI.

talking from experience.
these are (surprisingly) not handled by onsubmit event:

1. calling submit() method of the form object
2. input type=image (which is acts the same as input type=submit)

only input type=submit is handled by onsubmit event.

ecnarongi, if you use input type=submit, your code will work.

<form name="..." onsubmit="return popReg()">
...
<input type="submit" name="btnSubmit" value="Submit">


but if you really want an image submit button:

<form name="...">
...
<input type="image" src="submit.gif" name="btnSubmit" onclick="return popReg()">

adios
10-03-2002, 04:53 AM
<html>
<head>
<title>untitled</title>
</head>
<body>
<form onsubmit="alert(event.type)">
<input type="text">
<input type="image" src="http://www.codingforums.com/images/reply.gif">
</form>
</body>
</html>

glenngv
10-03-2002, 05:06 AM
oh sorry, but i might have said it partially true.

<html>
<head>
<script>
function check(frm){
if (frm.username.value==""){
alert("Please enter username.");
frm.username.focus();
return false;
}
if (frm.passw.value==""){
alert("Please enter password.");
frm.passw.focus();
return false;
}
}
</script>
</head>
<body>
<form name=f action="" method=post onsubmit="return check(this)">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="passw"><br><br>
button: <input type="button" onclick="document.f.submit()" value="submit"><br>
image: <input type="image"><br>
submit: <input type="submit" value="Submit"><br>
</form>
</body>
</html>

adios
10-03-2002, 05:14 AM
alert("Please enter password.");
frm.passw.focus();
return false;
}
return true;
}


<input type="button" value="submit"
onclick="if(document.f.onsubmit())document.f.submit()">

glenngv
10-03-2002, 06:15 AM
Originally posted by adios
alert("Please enter password.");
frm.passw.focus();
return false;
}
return true;
}

<input type="button" value="submit"
onclick="if(document.f.onsubmit())document.f.submit()">

function check(frm){
alert("inside check() function");
if (frm.username.value==""){
alert("Please enter username.");
frm.username.focus();
return false;
}
//...
//...
return true;
}

<input type="button" value="submit"
onclick="if(document.f.onsubmit())document.f.submit()">

or even:

<input type="button" value="submit"
onclick="if(document.f.onsubmit)document.f.submit()">

adios
10-03-2002, 06:29 AM
Thought that looked familiar.
This:

<input type="button" value="submit"
onclick="if(document.f.onsubmit)document.f.submit()">

...won't work; it just tests for the presence of an object (assigned handler function) and submits. You need to run & evaluate the return value of the handler).

................
submit: <input type="submit" value="Submit"><br>
</form>
<script>
alert(document.f.onsubmit)
alert(document.f.onsubmit())
</script>

glenngv
10-03-2002, 06:40 AM
i just put this

<input type="button" value="submit"
onclick="if(document.f.onsubmit)document.f.submit()">

to show neither of that nor your code will not call check() function

function check(frm){
alert("inside check() function");
if (frm.username.value==""){
alert("Please enter username.");
frm.username.focus();
return false;
}
//...
//...
return true;
}

<input type="button" value="submit"
onclick="if(document.f.onsubmit())document.f.submit()">

adios
10-03-2002, 07:38 AM
Pointless demo:

<html>
<head>
<title>untitled</title>
<style>
input {width:300px;font: 200 11px arial;background:black;color:white;}
</style>
<script>
onerror = function() {alert('error');return true;}
</script>
</head>
<body style="font-weight:bold;">
<form>
1) <input type="button" value="alert(this.form.onsubmit)"
onclick="alert(this.form.onsubmit);this.style.color='yellow'"><br><br>
2) <input type="button" value="alert(Boolean(this.form.onsubmit))"
onclick="alert(Boolean(this.form.onsubmit));this.style.color='yellow'"><br><br>
3) <input type="button" value="this.form.onsubmit=function() { return 'handler running' }"
onclick="this.form.onsubmit=function(){return 'handler running'};this.style.color='yellow'"><br><br>
4) <input type="button" value="alert(Boolean(this.form.onsubmit))"
onclick="alert(Boolean(this.form.onsubmit));this.style.color='yellow'"><br><br>
5) <input type="button" value="alert(this.form.onsubmit)"
onclick="alert(this.form.onsubmit);this.style.color='yellow'"><br><br>
6) <input type="button" value="alert(this.form.onsubmit())"
onclick="alert(this.form.onsubmit());this.style.color='yellow'"><br><br>
<img src="http://www.codingforums.com/images/icons/icon4.gif">
<input type="button" value="reset"
onclick="location.reload()">
</form>
</body>
</html>

glenngv
10-03-2002, 07:57 AM
yes.

i agree with you on that. but my point here is that

function check(frm){
alert("inside check() function");
if (frm.username.value==""){
alert("Please enter username.");
frm.username.focus();
return false;
}
//...
//...
return true;
}
<form onsubmit="return check(this)">
<input type="button" value="submit"
onclick="if(document.f.onsubmit())document.f.submit()">

...that button will not call check() function.

whammy
10-04-2002, 03:11 AM
Ooooh! JavaScript fight! ;)

J/K. :D

ecnarongi
10-04-2002, 03:21 AM
yeah that is funny :D I guess people can fight over anything