Misterman
11-04-2014, 02:16 PM
DISCLOSURE TIME:
1. I am new in this forum, though I have read the rules and FAQ, I may make mistakes, please forgive me
2. I know next to nothing about JavaScript, so please be gentle with me. In fact, I am a complete novice, though I have solid knowledge of VBScript.
THE PROBLEM
I wrote a VBScript client-side script to make sure some data are entered and if not to stop form submission. It works great in VBScript, but of course it will be ignored by Firefox and others because they don't speak VBS. I am forced to migrate the code to JavaScript. This is where I am having problems. In VBS, to respond to an event, such as form submission, the name of the event handler (function) is FormName_Event e.g.frmDefault_onSubmit. The first question is: doesn't JVS have an equivalent?
In my research on JVS, here is what I learnt:
I changed the HTML a little bit to <form method="POST" action="welcome.asp" name="frmDefault" onsubmit="return frmDefault_onSubmit()"> and then have a function called. Here is the function: function frmDefault_onSubmit(). However, I couldn't get it to work. What am I doing wrong? Here is the JVS code:
<script Language="JavaScript">
<!--
function frmDefault_onSubmit() {
var UserInput;
alert("Hello");
this should generate an error if this is called
UserInput = frmDefault.Firstname.value;
If (UserInput.trim() == "") {
alert(" Enter the Firstnsme ");
return false;
}
UserInput = frmDefault.Lastname.value;
If (UserInput.Trim() == "") {
alert(" Enter the Lastnsme ");
return false;
}
UserInput = frmDefault.GSMNumber.value;
If (UserInput.Trim() == "") {
alert(" Enter the GSM Number ");
return false;
}
UserInput = frmDefault.Email.value;
If (UserInput.Trim() == "") {
alert(" Enter the Email ");
return false;
}
frmDefault.Source.value = "<% =Request.QueryString("Source") %>";
frmDefault.Website.value = "<% =Request.QueryString("Website") %>";
return true;
}
-->
</script>
The code is completely ignored, as if it were not there:
I even had the following line sof code (which of course would be removed later:
alert("Hello");
this should generate an error if this is called
No message was displayed neither did I get any error message. It is supposed to check that First name, Last name, GSM Number and Email were entered. Help is very much appreciated. Thanks
1. I am new in this forum, though I have read the rules and FAQ, I may make mistakes, please forgive me
2. I know next to nothing about JavaScript, so please be gentle with me. In fact, I am a complete novice, though I have solid knowledge of VBScript.
THE PROBLEM
I wrote a VBScript client-side script to make sure some data are entered and if not to stop form submission. It works great in VBScript, but of course it will be ignored by Firefox and others because they don't speak VBS. I am forced to migrate the code to JavaScript. This is where I am having problems. In VBS, to respond to an event, such as form submission, the name of the event handler (function) is FormName_Event e.g.frmDefault_onSubmit. The first question is: doesn't JVS have an equivalent?
In my research on JVS, here is what I learnt:
I changed the HTML a little bit to <form method="POST" action="welcome.asp" name="frmDefault" onsubmit="return frmDefault_onSubmit()"> and then have a function called. Here is the function: function frmDefault_onSubmit(). However, I couldn't get it to work. What am I doing wrong? Here is the JVS code:
<script Language="JavaScript">
<!--
function frmDefault_onSubmit() {
var UserInput;
alert("Hello");
this should generate an error if this is called
UserInput = frmDefault.Firstname.value;
If (UserInput.trim() == "") {
alert(" Enter the Firstnsme ");
return false;
}
UserInput = frmDefault.Lastname.value;
If (UserInput.Trim() == "") {
alert(" Enter the Lastnsme ");
return false;
}
UserInput = frmDefault.GSMNumber.value;
If (UserInput.Trim() == "") {
alert(" Enter the GSM Number ");
return false;
}
UserInput = frmDefault.Email.value;
If (UserInput.Trim() == "") {
alert(" Enter the Email ");
return false;
}
frmDefault.Source.value = "<% =Request.QueryString("Source") %>";
frmDefault.Website.value = "<% =Request.QueryString("Website") %>";
return true;
}
-->
</script>
The code is completely ignored, as if it were not there:
I even had the following line sof code (which of course would be removed later:
alert("Hello");
this should generate an error if this is called
No message was displayed neither did I get any error message. It is supposed to check that First name, Last name, GSM Number and Email were entered. Help is very much appreciated. Thanks