I have a piece of code in one of my web applications that has been written with ASP Classic.
Unfortunately, some part of the code is VBScript and does not run in FireFox. I need to change it to JavaScript, but I'm not familiar with JavaScript.
Can anyone help me?
This is the piece of code in VBScript. I need to have a JavaScript version of the following code: - <%
-
Response.Write "<SCRIPT LANGUAGE=vbscript Event=OnClick For=btnConf>" & vbCrLf _
-
& "If f1.txtName.value = " & """""" & "Then" & vbCrLf _
-
& "MsgBox " & """Empty Field for the Name!""" & ",vbExclamation," & """Error""" & vbCrLf _
-
& "f1.txtName.select" & vbCrLf _
-
& "ElseIf f1.txtMail.value = " & """""" & "Then" & vbCrLf _
-
& "MsgBox " & """Please Enter Your E-mail!""" & ",vbExclamation," & """Error""" & vbCrLf _
-
& "f1.txtMail.select" & vbCrLf _
-
& "ElseIf f1.txtPhone.value = " & """""" & "Or Not IsNumeric(f1.txtPhone.value) Then" & vbCrLf _
-
& "MsgBox " & """Please Enter Your Phone Number!""" & ",vbExclamation," & """Error""" & vbCrLf _
-
& "f1.txtPhone.select" & vbCrLf _
-
& "Else" & vbCrLf _
-
& "f1.action = " & """SaveOrder.asp?" & Request.QueryString & """" & vbCrLf _
-
& "f1.submit" & vbCrLf _
-
& "End If" & vbCrLf _
-
& "</SCRIPT>"
-
If Session("NotComplete") <> "" Then
-
Response.Write "<SCRIPT LANGUAGE=vbscript Event=OnLoad For=Window>" & vbCrLf _
-
& "MsgBox " & """" & Session("NotComplete") & """" & ",vbExclamation," & """Error""" & vbCrLf _
-
& "</SCRIPT>"
-
End If
-
%>
What I don't get is why you are attempting to execute vb script in a web browser??? No wonder it doesn't work in FireFox.
Here's something quick that I did based on what you've posted... it is NOT guaranteed to work: - <script type="text/javascript">
-
-
var txtName = document.getElementById('txtName');
-
var txtMail = document.getElementById("txtMail');
-
var txtPhone = document.getElementById('txtPhone');
-
var f1 = document.getElementById('f1');
-
-
if(txtName.value == '')
-
{
-
alert('Empty Field for the Name!')
-
}
-
else if(txtMail.value== '' )
-
{
-
alert('Please Enter Your E-mail!');
-
}
-
else if(txtPhone.value == '' || isNaN(txtPhone.value) == false)
-
{
-
alert('Please Enter Your Phone Number!');
-
}
-
else
-
{
-
f1.action = 'SaveOrder.asp?T2=1&T3=2&T4=3';
-
}
-
-
f1.submit();
-
-
</script>
26 5406
It would help to see just the VBScript code.
Unfortunately, I'm not familiar with JavaScript. That's why I have asked experts' help to solve this problem.
What you have there is a server side VBScript that outputs client side VBScript. What you want to convert is the client side VBScript because that's what's affected by a browser. Since that's what you want to convert, it would help to see the client side VBScript by itself.
This is a really difficult question, especially since you posted the raw ASP code, instead of the interpreted code with the server-side code gone. Instead we look at this and see jumbles of VBScript, some of which is server-side and some is client-side.
Post the code as it looks on the browser - right-click and "view source". This should have no server-side code left.
Jared
This is the code as it looks on the browser: - <SCRIPT LANGUAGE=vbscript Event=OnClick For=btnConf>
-
If f1.txtName.value = ""Then
-
MsgBox "Empty Field for the Name!",vbExclamation,"Error"
-
f1.txtName.select
-
ElseIf f1.txtMail.value = ""Then
-
MsgBox "Please Enter Your E-mail!",vbExclamation,"Error"
-
f1.txtMail.select
-
ElseIf f1.txtPhone.value = ""Or Not IsNumeric(f1.txtPhone.value) Then
-
MsgBox "Please Enter Your Phone Number!",vbExclamation,"Error"
-
f1.txtPhone.select
-
Else
-
f1.action = "SaveOrder.asp?T2=1&T3=2&T4=3"
-
f1.submit
-
End If
-
</SCRIPT>
Thank you for your attention.
This is actually fairly simple.
In javascript, lines of code end in a semicolon so you'll need to put those in.
There's no MsgBox but you can use alert in its place.
You'll need to change the if conditionals to the javascript version.
And I think that's pretty much it in terms of the port. You have have to finagle a bit with the dom. I can't remember if you have direct access to the dom subelements like you do in vbscript so you may have to use the document.getElementById method.
What I don't get is why you are attempting to execute vb script in a web browser??? No wonder it doesn't work in FireFox.
Here's something quick that I did based on what you've posted... it is NOT guaranteed to work: - <script type="text/javascript">
-
-
var txtName = document.getElementById('txtName');
-
var txtMail = document.getElementById("txtMail');
-
var txtPhone = document.getElementById('txtPhone');
-
var f1 = document.getElementById('f1');
-
-
if(txtName.value == '')
-
{
-
alert('Empty Field for the Name!')
-
}
-
else if(txtMail.value== '' )
-
{
-
alert('Please Enter Your E-mail!');
-
}
-
else if(txtPhone.value == '' || isNaN(txtPhone.value) == false)
-
{
-
alert('Please Enter Your Phone Number!');
-
}
-
else
-
{
-
f1.action = 'SaveOrder.asp?T2=1&T3=2&T4=3';
-
}
-
-
f1.submit();
-
-
</script>
@Frinny: VBScript will work in IE and IE only.
Client-side vbscript is a throw-back from the netscape/IE wars of the 90s. It was never standardized and was never a good idea. Even when I used to have mixed client- and server-side scripting it always made sense to me to switch back and forth so I could say "this part is vbscript, so must be server-side, and this part is javascript so must be client-side" as I was re-reading the code.
Really, kudos to you, nicebasic. Responsible web owners need to be removing it wherever they find it.
Jared
Thank you "Frinavale" for the JavaScript code you have posted. I'll test your code. Unfortunately, my Internet Provider had a problem with its servers. I didn't have any Internet Connection in the past week. That's why I couldn't check this thread. I hope I can solve this problem with your help.
I'm not familiar with JavaScript. I'm only familiar with VB 6.0 & ASP Classic & VBScript.
The above VBScript does not belong to me. One of my friends has written that code. He doesn't know how to translate it to JavaScript either.
Thank you everybody for your kind help on this question.
Let me know how it goes :)
-Frinny
Dear Frinavale,
I hope that you would excuse me for such a long absence. Something happened to my ISP and I lost many things.
Moreoever, the company that hosted my files lost all of them and wasn't able to restore them.
It was a big disaster. I have heard that hosting companies should provide RAID for data loss.
Anyway, I tested your valuable JavaScript code. I had to put your code in some ASP code to be generated on the Server.
This is your code wrapped in some ASP code: - Response.Write "<script type='text/javascript'>" & vbCrLf _
-
& "var txtName = document.getElementById('txtName');" & vbCrLf _
-
& "var txtMail = document.getElementById('txtMail');" & vbCrLf _
-
& "var txtPhone = document.getElmentById('txtPhone');" & vbCrLf _
-
& "var f1 = document.getElementById('f1');" & vbCrLf _
-
& "if(txtName.value = '')" & vbCrLf _
-
& "{" & vbCrLf _
-
& "alert('Empty Field for the Name')" & vbCrLf _
-
& "}" & vbCrLf _
-
& "else if(txtMail .value = '' )" & vbCrLf _
-
& "{" & vbCrLf _
-
& "alert('Please Enter Your E-mail!');" & vbCrLf _
-
& "}" & vbCrLf _
-
& "else if(txtPhone.value = '' || isNaN(txtPhone.value) = false)" & vbCrLf _
-
& "{" & vbCrLf _
-
& "alert('Please Enter Your Phone Number!');" & vbCrLf _
-
& "}" & vbCrLf _
-
& "else" & vbCrLf _
-
& "{" & vbCrLf _
-
& "f1.action = " & "'SaveOrder.asp?" & Request.QueryString & "';" & vbCrLf _
-
& "}" & vbCrLf _
-
& "f1.submit();" & vbCrLf _
-
& "</script>"
And, this is your code as it looks on the browser: - <script type='text/javascript'>
-
var txtName = document.getElementById('txtName');
-
var txtMail = document.getElementById('txtMail');
-
var txtPhone = document.getElmentById('txtPhone');
-
var f1 = document.getElementById('f1');
-
if(txtName.value = '')
-
{
-
alert('Empty Field for the Name')
-
}
-
else if(txtMail .value = '' )
-
{
-
alert('Please Enter Your E-mail!');
-
}
-
else if(txtPhone.value = '' || isNaN(txtPhone.value) = false)
-
{
-
alert('Please Enter Your Phone Number!');
-
}
-
else
-
{
-
f1.action = 'SaveOrder.asp?T1=1&T2=1';
-
}
-
f1.submit();
-
</script>
-
When I run this code on the specified page, nothing seems to happen. I press the Submit Button, but nothing happens. Even if you leave the fields EMPTY, no Error Messages or Alert Boxes will be displayed.
It seems as if something is wrong. The original code, without any changes, can be run in IE, but due to the lack of VBScript support in FireFox, it does not work in FF. I was trying to translate this code to JavaScript using expert programmers in this great forum.
I hope you and great programmers like you can help me solve this problem.
Thank you again.
There's probably a JavaScript error on the page.
Use the JavaScript debugging tools that come with the browser that you prefer to work with. If you are using FireFox, install a plugin called FireBug (it'll help you debug JavaScript and HTML/CSS stuff).
Once you have started JavaScript debugging, you should see errors pop up.... Once you have the errors, it will be easier to track down what is going on.
My first guess would be that you have not named your HTML elements the same way as you did the first time. You should have HTML <input type="text"/> elements with IDs 'txtName', 'txtMail', and 'txtPhone'. You should also have a submit button with the id 'f1'.
If you are missing any of these, or you have the different IDs, then your script will crash and your submit will never be called.
-Frinny
Isn't that going to run as soon as the page loads and before the form elements are available for use? You need to tie it to the event on the button.
It works with no problem in IE.
The problem is with FireFox. I changed the codes from VBScript to JavaScript using the help of Experts in this forum.
It seems something is wrong with quotations or something like that.
If you leave the boxes empty and press Submit, no Alerts will be displayed.
If you fill up the boxes and press Submit, nothing will happen.
I'm really confused.
Like I said in my previous post, it's going to run as soon as the page loads and before the form elements are available for use. You need to tie it to the event on the button
Rabbit is right!
That JavaScript code is not within a function so it is going to be executed when the page loads. Put it into a function and call the function during the button click event.
-Frinny
The original code that used VBScript was like this: - <SCRIPT LANGUAGE=vbscript Event=OnClick For=btnConf>
-
.......
-
</SCRIPT>
Can we change the code to this? - <SCRIPT LANGUAGE=JavaScript Event=OnClick For=btnConf>
-
.......
-
</SCRIPT>
Is this a valid change?
Fortunately, using your great advice, I added a new JavaScript Function like this: - <script language="JavaScript">
-
function cancel(){
-
window.location = './cancel.asp'
-
}
-
</script>
When you click on the Cancel Button, the above JavaScript will redirect you to the Cancel page and the variables of the current page will be lost.
But:
I have made some changes to the code as you mentioned. Your instructions were really great. I put the code in a JavaScript function like this: - <script type='text/javascript'>
-
function decide(){
-
..........
-
}
-
</script>
-
but I get this error message in FireFox Error Console: invalid assignment left-hand side - else if(txtPhone.value = '' || isNaN(txtPhone.value) = false)
If you're trying to compare values, you use ==. If you're trying to assign a value, you use =.
Ooops, sorry that's my fault. I remember translating the vbScript into JavaScript quickly and not testing anything. I edited/fixed my original post so that it uses the proper comparison operators in the if statements instead of trying to assign things.
-Frinny
I edited this line from: - else if(txtPhone.value = '' || isNaN(txtPhone.value) = false)
to - else if(txtPhone.value = '')
and the above error disappeared.
But another error shows up: document.getElmentById is not a function
Can't we replace document.getElmentById by something else?
You should have changed the single "=" to a double "==" in the if statements...
Like this: - else if(txtPhone.value == '' || isNaN(txtPhone.value) == false)
-Frinny
I found a problem in this line: - var txtPhone = document.getElmentById('txtPhone');
This very simple problem prevented the code from running. I changed it to: - var txtPhone = document.getElementById('txtPhone');
It was a misspelling. Changing "getElmentById" to "getElementById" fixed it all.
I'm checking the other parts now.
I'm really grateful to Frinavale and Rabbit for your really useful support.
Did you put in those ==? Because you may not get an error but the results would be wrong if you didn't.
Yes, Rabbit. I used your great help and great support. Without your help, it wouldn't be possible to solve this complicated problem.
Since this line causes a problem: - else if(txtPhone.value == '' || isNaN(txtPhone.value) == false)
I removed the second part of the condition and changed it to: - else if(txtPhone.value == '')
I don't know why it doesn't accept any numbers. I enter a number, but it gives me an Alert that I have to enter a valid number. I didn't know how to fix it, so I removed it.
Thank you again, Rabbit.
You contributed so much. You referred to a key point here: it's going to run as soon as the page loads and before the form elements are available for use. You need to tie it to the event on the button Sign in to post your reply or Sign up for a free account.
Similar topics
by: Martin |
last post by:
Shown below is the body of a web page I'm developing. When it loads, a
socket connection is established back to a socket that's on my server.
I can then send a message from the server and it will...
|
by: Sergio del Amo |
last post by:
i,
I have the next html page
<html>
<head>
<script>
<!--
function insertcode()
{
var code ="<p> blablabal babala babababab</p><h1>here comes
header</h1><span>fadfafa<a...
|
by: fred4534 |
last post by:
Hello,
I'm using the GoAhead embedded Webserver
(http://webserver.goahead.com/webserver/webserver.htm) which can use
only ASP and a set of javascript instructions.
I'm trying to make an upload...
|
by: Carlo Marchesoni |
last post by:
I have a button that opens a new Window (some kind of search-window), which is fired using JavaScript (btnSearch.Attributes=".....";)
Now I need to run some code behind code BEFORE this JavaScript...
|
by: Shadow Lynx |
last post by:
That subject packs a whallop, so let me explain in better detail what's
happening and how it relates to ASPX pages...
In a nutshell, if the first <script /on a page is of type
"text/vbscript",...
|
by: mistral |
last post by:
I want find code for clickable thumbnails, when click on small
picture, a big image will popup in new window, sized to fit picture.
Same as standard javascript image previewer, but without using...
|
by: =?Utf-8?B?QWxleGFuZGVy?= |
last post by:
Hi!
I want to learn C# in the near future. But for now, I would be more than
happy if someone could translate this short c# source code into c++. (I
searched the web for c++ equivalents but after...
|
by: cromoglic |
last post by:
Hello.
I am new to javascript, and need help with something:)
I came across this "hack my site"-site, and cant get past level 4 (lol);P I've got the source code:
<script src="JavaScript"...
|
by: urib |
last post by:
Suppose that I have some simple function in C like the following when I want to use it in javascript code
int plus1(int a)
{
return a+1;
}
I am using visual C++2008 for my C code.
I...
|
by: najmi |
last post by:
hai..
i have used jquery fullcalendar for my application and i have one problem that is how to display the event from the database.i have found the sample given in php but i want it in jsp.can...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |