Solved

Just fiddlin' around - What's wrong with this???

Posted on 2002-04-02
5
165 Views
Last Modified: 2010-04-09
Hi there.  I'm not doing anything really important, but I can't figure out why this code doesn't work.  Can someone point me in the right direction.

<code>
<HTML>
<HEAD>
<TITLE> My First Attempt at VB Script!</TITLE>

<SCRIPT LANGUAGE="VBSCRIPT" TYPE="text/vbs">

<!-- Instruct non-IE browsers to skip over scripts

    Sub MYBUTTON_OnClick
     MsgBox "Over the hills and through the woods, to grandmothers house we go!"
    End Sub

    Sub MYBUTTON2_OnClick
     DIM X
     X = INPUTBOX("Enter Your Name:")
         if X = "" then
          Exit Sub
         end if
     MsgBox "Your Name is: " & X
    End Sub

    Sub CALC_OnClick
     msgbox ((document.myform.FSTNUM.VALUE) + (document.myform.SECNUM.VALUE))
    end sub
-->
</SCRIPT>
</HEAD>

<BODY BGCOLOR = 'beige'>

<FORM NAME = "myForm">
    <INPUT TYPE = "BUTTON" NAME = "MYBUTTON" VALUE = "WOO - HOO">
    <INPUT TYPE = "BUTTON" NAME = "MYBUTTON2" VALUE = "NAME SCRIPT">
    <INPUT TYPE = "Text" NAME = "FSTNUM" VALUE = 0 SIZE = 4>
    <INPUT TYPE = "Text" NAME = "SECNUM" VALUE = 0 SIZE = 4>
    <INPUT TYPE = "BUTTON" NAME = "CALC" VALUE = "CALCULATE">
</FORM>

</BODY>
</HTML>
</code>

in the Calc_OnClick, the message box returns the values of the text boxes concatenated.  If I try multiplying, it works fine.

Thanks for any help.

DDS
0
Comment
Question by:dds110
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 6914090
  Sub CALC_OnClick
    msgbox (eval(document.myform.FSTNUM.VALUE) + eval(document.myform.SECNUM.VALUE))
   end sub
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 6914091
without the eval() , the input values are treated as text, so you are concatinating two strings together.  
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 15 total points
ID: 6914096
actually, you may want to use CInt instead of eval:


   msgbox (CInt(document.myform.FSTNUM.VALUE) + CInt(document.myform.SECNUM.VALUE))
0
 
LVL 8

Author Comment

by:dds110
ID: 6921615
Thanks a bunch.
0
 
LVL 8

Author Comment

by:dds110
ID: 6921617
Thanks a bunch.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question