Solved

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

Posted on 2002-04-02
5
162 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

829 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