Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

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

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
dds110
Asked:
dds110
  • 3
  • 2
1 Solution
 
knightEknightCommented:
  Sub CALC_OnClick
    msgbox (eval(document.myform.FSTNUM.VALUE) + eval(document.myform.SECNUM.VALUE))
   end sub
0
 
knightEknightCommented:
without the eval() , the input values are treated as text, so you are concatinating two strings together.  
0
 
knightEknightCommented:
actually, you may want to use CInt instead of eval:


   msgbox (CInt(document.myform.FSTNUM.VALUE) + CInt(document.myform.SECNUM.VALUE))
0
 
dds110Author Commented:
Thanks a bunch.
0
 
dds110Author Commented:
Thanks a bunch.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now