Solved

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

Posted on 2002-04-02
5
157 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
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

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

Expert Comment

by:knightEknight
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a bunch.
0
 
LVL 8

Author Comment

by:dds110
Comment Utility
Thanks a bunch.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now