Click to See Complete Forum and Search --> : onsubmit="Javascript:..." not working in Netscape
KeithP
01-24-2003, 10:17 PM
This validate function is working fine in ie, but the form posts just like the validate function isn't there when run in Netscape. Is there another way to validate forms in Netscape? Other Javascripts on the same page are working fine in Netscape.
<form method="POST" action="http://www.domain.com/htbin/mailit"
name="textmsg" onsubmit="Javascript: return Validate()">
Thanks
Nedals
01-24-2003, 11:58 PM
Try
<form method="POST" action="http://www.domain.com/htbin/mailit" name="textmsg" onSubmit="Validate()">
Charles
01-25-2003, 05:09 AM
In XHTML that would need to be
<form method="POST" action="http://www.domain.com/htbin/mailit" name="textmsg" onsubmit="Validate()">
Strictly speaking the names of the event handlers are all lower case. You may not have noticed this because HTML is case insensitive but XHTML is case sensitive.
Webskater
01-25-2003, 08:20 AM
You say in Netscape the form submits and the validate function is ignored. Assuming it is being called, which you can test easily by sticking document.write('this proves the function is being called') in your script, it appears to think it has nothing to validate. I don't know whether this will work or not but to make sure the function realises what it has to validate why not try:
onsubmit="return Validate(this)"
and in your function
function Validate(this)
KeithP
01-25-2003, 11:51 AM
Thanks for all the suggestions.
I've changed onsubmit="Javascript: return Validate()" to onsubmit="return validate()"
I removed Javascript:, I changed V to v, and I added a write.document line in the function. The write comment comes up in IE as expected, but nothing in Netscape. So it looks like the fucntion isn't being called in Netscape.
When I use onsubmit="validate()" (without return) the function pops up a validation message when there's a problem, but then goes ahead and submits the form anyway. (and of course, nothing happens in Netscape, the form just submits.)
Any other ideas??
Webskater
01-25-2003, 11:56 AM
I would be interested to see the code for the validate function.
KeithP
01-25-2003, 05:16 PM
I tryed using:
onsubmit="alert('Starting onsubmit event.');return validate();"
The onsubmit alert message runs in Netscape, but not the validate function. (Still working in IE) I've included the function code per request. The true alert message (or the false message) in the function never comes up in Netscape. Any suggestions are welcome.
Here's the validate function:
<script language="JavaScript">
function validate(){
var strSponsor;
var strfrom;
var strAddress;
var strCityStateZip;
var strContact;
var strContactTitle;
var strPhone;
var strAmount
strSponsor = textmessage.Sponsor.value;
strfrom = textmessage.from.value;
strAddress = textmessage.Address.value;
strCityStateZip = textmessage.CityStateZip.value;
strContact = textmessage.Contact.value;
strPhone = textmessage.Phone.value;
strAmount = textmessage.Amount.value
if (strSponsor == ''){
window.alert('Please specifiy a Sponsor name.');
textmessage.Sponsor.focus();
return false;
}
window.alert('this proves the function is being called, true');
return true;
}
</script>
KeithP
01-25-2003, 05:58 PM
THAT'S IT!!
I added document. throughout the code and now it works great in IE and in Netscape.
Thanks for the help!!
ghartmaier
02-17-2003, 04:54 AM
Hello friends of java script!!
I have a similar problem with my form validation script. Works perfect in IE, no way in NS 4.7 - 6.0 :-(
Here the script:
function LM_Form()
{
var errors='',nm;
// ---PERSÖNLICHEDATEN---
if (document.PDform.nombre.value =='') errors+='- Wir benötigen ihren Vornamen!\n';
if (document.PDform.apellidos.value =='') errors+='- Wir benötigen ihren Nachnamen!\n';
if (document.PDform.direccion.value =='') errors+='- Bitte Ihre Adresse angeben!\n';
if (document.PDform.edad.value =='') errors+='- Wir benötigen ihr Alter!\n';
// if ((PCform.telefono.value =='') && (PCform.email.value =='')&& (PCform.fax.value =='')) errors+='- Für die Bestätigung brauchen wir entweder Ihre Telefonnummer, Faxnummer oder E-Maildaresse\n';
// ---FAHRZEUGTYP---
if (document.PDform.vehiculo.value =='value') errors+='- Bitte wählen Sie einen Fahzeugtyp!\n';
// ---ANKUNFTSTAG-ABGABETAG+ZEIT---
if (document.PDform.diarecoge.value =='Dia') errors+='- Ankunftstag fehlt!\n';
if (document.PDform.mesrecoge.value =='Mes') errors+='- Ankunftsmonat fehlt!\n';
if (document.PDform.anyorecoge.value =='Ano') errors+='- Ankunftsjahr fehlt!\n';
if (document.PDform.diaentrega.value =='Dia') errors+='- Abfahrtstag fehlt!\n';
if (document.PDform.mesentrega.value =='Mes') errors+='- Abfahrtsmonat fehlt!\n';
if (document.PDform.anyoentrega.value =='Ano') errors+='- Abfahrtsjahr fehlt!\n';
if (document.PDform.horarecogida.value =='') errors+='- Ankunftszeit fehlt!\n';
if (document.PDform.horaentrega.value =='') errors+='- Rückgabezeit fehlt!\n';
if(!document.PDform.recoge[0].checked && !document.PDform.recoge[1].checked && !document.PDform.recoge[2].checked && !document.PDform.recoge[3].checked && !document.PDform.recoge[4].checked) errors+='- Geben Sie bitte einen Empfangsort an!\n';
if ((!document.PDform.recoge[3].checked == false ) && (document.PDform.vuelo.value == '')) errors+='- Geben Sie bitte Ihre Flugnummer an\n';
if ((!document.PDform.recoge[4].checked == false ) && (document.PDform.hotel.value == '')) errors+='- Geben Sie bitte Ihr Hotel an\n';
// ---RÜCKGABEORT---
if (document.PDform.entregavehiculo.value =='Elija Uno') errors+='- Geben Sie bitte einen Rückgabeort an!\n';
// ---BESTÄTIGUNG---
if (!document.PDform.confirma[0].checked && !document.PDform.confirma[1].checked && !PDform.confirma[2].checked) errors+='- Bitte teilen Sie uns mit wie wir Ihre Buchung bestätigen sollen!\n';
if ((!document.PDform.confirma[0].checked == false) && (document.PDform.email.value == '')) errors+='- Für die Buchungsbestätigung brauchen wir ihre eMailadresse\n';
if ((!document.PDform.confirma[1].checked == false) && (document.PDform.telefono.value == '')) errors+='- Für die Buchungsbestätigung brauchen wir ihre Telefonnummer\n';
if ((!document.PDform.confirma[2].checked == false) && (document.PDform.fax.value == '')) errors+='- Für die Buchungsbestätigung brauchen wir ihre Faxnummer\n';
if (errors) alert('\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
the submit button looks like this:
<input
type="submit" value="Senden" name="enviar" onClick="LM_Form();return document.MM_returnValue">
Any idears??
Thanks a lot for trying
Gregor,Lanzarote,spain.
ghartmaier
02-17-2003, 07:16 AM
Hi Dave, your right, makes it much easier to see the page:
http://www.autospluscar.com/de/reservastest.htm
anyway thanx for your quick respond!!!
Gregor.
ghartmaier
02-17-2003, 07:33 AM
really???
Isn't java script uni code??
Only the error messages are in german, and they should'nt bother you.
But If you prefer the english version...
http://www.autospluscar.com/en/reservastest.htm
better??
Thanx so far....
BTW: when I read the earlier postings, I changed the german page and added the document in document.form.field
the english version still comes without the document. >But even this change didn't make the script work in NS
ghartmaier
02-17-2003, 07:40 AM
Originally posted by Dave Clark
However, if I had to guess, I'd say that it is only your SELECT objects you're having trouble with. Is that right?
Dave
No, non of the validations work in NS, not even the simpel "if field = empty ...
khalidali63
02-17-2003, 08:04 AM
This is interesting.I have just submitted the form using NS6+ browsers
(mozilla1.21 to be exact)
An have gotten the submission completed message?
What could I have missed?
ghartmaier
02-17-2003, 08:10 AM
Originally posted by khalidali63
This is interesting.I have just submitted the form using NS6+ browsers
(mozilla1.21 to be exact)
An have gotten the submission completed message?
What could I have missed?
This is the problem i'm talking about.
the script works fine in IE but no way with NS or Mozilla!?
What could I have missed??????????
Gregor
(it should not be submitable, if not all fields are filed correctly!! but it does.)
khalidali63
02-17-2003, 08:32 AM
Originally posted by ghartmaier
......
(it should not be submitable, if not all fields are filed correctly!! but it does.)
Now this is more clearer.
What detemines that which field should be filled with what data?
That may require allots of work on anybody's behalf to find out your correct requirements and go through your code and make sure you are testing for the correct conditions.
On the other hand you can always mention the problematic fields and there data type so that some one can take a look.
Khalid
ghartmaier
02-17-2003, 08:45 AM
Originally posted by khalidali63
Now this is more clearer.
What detemines that which field should be filled with what data?
That may require allots of work on anybody's behalf to find out your correct requirements and go through your code and make sure you are testing for the correct conditions.
On the other hand you can always mention the problematic fields and there data type so that some one can take a look.
Khalid
Hi Khalid
I already set up the "correct" conditions and a javascript code that works absolutly perfect for IE users. My only problem is: Netscape does not work with the Javascript code at all, NS just ignores it and - as you found out - sends the form even nothing is filled in the fields.
here is the code again, maybe you know where the error could be??:
<script language="JavaScript">
<!--
<!--
function LM_Form()
{
var errors='',nm;
// ---Personal dates---
if (document.PEform.nombre.value =='') errors+='- Please insert your name!\n';
if (document.PEform.apellidos.value =='') errors+='- Please insert your surname!\n';
if (document.PEform.direccion.value =='') errors+='- Please insert your address!\n';
if (document.PEform.edad.value =='') errors+='- Please insert your age!\n';
// if ((PCform.telefono.value =='') && (PCform.email.value =='')&& (PCform.fax.value =='')) errors+='- Für die Bestätigung brauchen wir entweder Ihre Telefonnummer, Faxnummer oder E-Maildaresse\n';
// ---Vehicle---
if (document.PEform.vehiculo.value =='value') errors+='- You have forgoten to choose a vehicle!\n';
// ---Collection-Return-Dates---
if (document.PEform.diarecoge.value =='Dia') errors+='- Day of collection missing!\n';
if (document.PEform.mesrecoge.value =='Mes') errors+='- Month of collection missing!\n';
if (document.PEform.anyorecoge.value =='Ano') errors+='- Year of collection missing!\n';
if (document.PEform.diaentrega.value =='Dia') errors+='- Day of return missing!\n';
if (document.PEform.mesentrega.value =='Mes') errors+='- Month of return missing!\n';
if (document.PEform.anyoentrega.value =='Ano') errors+='- Year of return missing!\n';
if (document.PEform.horarecogida.value =='') errors+='- Time of collection missing!\n';
if (document.PEform.horaentrega.value =='') errors+='- Time of return missing!\n';
// ---Place of collection---
if(!document.PEform.recoge[0].checked && !document.PEform.recoge[1].checked && !document.PEform.recoge[2].checked && !document.PEform.recoge[3].checked && !document.PEform.recoge[4].checked) errors+='- You have not chosen a place of collection!\n';
if ((!document.PEform.recoge[3].checked == false ) && (document.PEform.vuelo.value == '')) errors+='- Please fill in your flight number!\n';
if ((!document.PEform.recoge[4].checked == false ) && (document.PEform.hotel.value == '')) errors+='- Please fill in your hotel!\n';
// ---Place of return---
if (document.PEform.entregavehiculo.value =='Elija Uno') errors+='- Place of return missing!\n';
// ---Confirmation---
if (!document.PEform.confirma[0].checked && !document.PEform.confirma[1].checked && !document.PEform.confirma[2].checked) errors+='- How do you want us to confirm the reservation?\n';
if ((!document.PEform.confirma[0].checked == false) && (document.PEform.email.value == '')) errors+='- To confirm the reservation we will need your E-Mail address!\n';
if ((!document.PEform.confirma[1].checked == false) && (document.PEform.telefono.value == '')) errors+='- To confirm the reservation we will need your telefon number!\n';
if ((!document.PEform.confirma[2].checked == false) && (document.PEform.fax.value == '')) errors+='- To confirm the reservation we will need your fax number!\n';
if (errors) alert('\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
the button:
<input
type="submit" value="Send" name="enviar" onClick="LM_Form();return document.MM_returnValue">
khalidali63
02-17-2003, 08:49 AM
Originally posted by ghartmaier
Hi Khalid
............ as you found out - sends the form even nothing is filled in the fields.
..............
I never said that.As a matter of fact I tested it with these 2 conditions on Mozilla1.21
1. did not enter email[ got appropriate error message]
2.without returning time[ got error message for it].
Now it seems like there is a huge gap of either communication or the environment.
I am using windows 2000Pro sp2
Mozilla 1.21
IE6
Khalid
ghartmaier
02-17-2003, 08:59 AM
Originally posted by khalidali63
I never said that.As a matter of fact I tested it with these 2 conditions on Mozilla1.21
1. did not enter email[ got appropriate error message]
2.without returning time[ got error message for it].
Now it seems like there is a huge gap of either communication or the environment.
I am using windows 2000Pro sp2
Mozilla 1.21
IE6
Khalid
Must be a gap of communication ;-)
I just tested the script again with:
1.Netscape 7.0 = sends empty form!:-(
2.Netscape 4.7 = sends empty form!:-(
3.IE 6.02 = popup message with correct errors!:-)
on Windows XP home Sp1
???
khalidali63
02-17-2003, 09:01 AM
Grrrrrrrrrr windows XP
try this link
http://68.145.35.86/temp/ghartmaier-FormProblem.html
Khalid
ghartmaier
02-17-2003, 09:08 AM
Whats this?? it works??
What have you done? I tried your link in NS7 and I finaly got the error?? Please what is the difference between your link and mine??
:-) I see the light at the end of the tunnel
khalidali63
02-17-2003, 09:16 AM
Well now its really interesting.The only thing that I can say is re-install NS7 or Mozilla 1.21 for winXP.
I have not done anything to your code at all.
Khalid
ghartmaier
02-17-2003, 09:22 AM
Originally posted by khalidali63
Well now its really interesting.The only thing that I can say is re-install NS7 or Mozilla 1.21 for winXP.
I have not done anything to your code at all.
Khalid
Anyway, if it is only not working on my system....I can live with it :-)
thank you very much for your time and for taking away my worries, have a nice day, regards to canada.
::AND::
Make love not war <--- to all american BUSH fighters.
khalidali63
02-17-2003, 09:25 AM
I think I know
gutten morgan..how do u say good night?
ghartmaier
02-17-2003, 09:35 AM
Gute nacht!
guten morgen = good morning
here it is 3.30 PM, so some hours more to work until good night.
it is funny, I copied the code from your page and pasted it into mine, believe it or not, know it works on my NS6 8-)
funny netscape, isn't it??
Thanx for all.
Gregor.
khalidali63
02-17-2003, 09:44 AM
The only possibility I see is that there must be some hidden character which when I opend your page in my text editor(Homesite5) it automatically deleted that.(because of my settings inHomesite5).
Well.its all good.
cheers
Khalid