Wrox Programmer Forums
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 17th, 2008, 06:22 AM
Authorized User
 
Join Date: Mar 2006
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default Text area

Hi all,

Instead of using input box for INPUT in order to do some calculation with VBScript, I would like to use Text area created in my web for my INPUT. How should I do that ? Any Idea ?

Example:-

<BODY>

        <TABLE BORDER="0">

            <TR>
                <TD>
                    Enter a Number
                </TD>

                <TD>
                    <INPUT TYPE="TEXT" NAME="nom(0)" SIZE="10">
                </TD>
            </TR>

            <TR>
                <TD>
                    Enter a Number
                </TD>

                <TD>
                    <INPUT TYPE="TEXT" NAME="nom(1)" SIZE="10">
                </TD>
            </TR>

            <TR>
                <TD>
                    Enter a Number
                </TD>

                <TD>
                    <INPUT TYPE="TEXT" NAME="nom(2)" SIZE="10">
                </TD>
            </TR>

        </TABLE>

Let say I want to do...
answer = nom(0) + nom(1) + nom(2)

Reply With Quote
  #2 (permalink)  
Old September 17th, 2008, 02:01 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Code:
<HTML>
<HEAD>
<script language="VBScript">
Sub Total( aButton )
    Dim sum, frm
    Set frm = aButton.form
    sum = CDBL( frm.nom0.value ) + CDBL( frm.nom1.value ) + CDBL( frm.nom2.value )
    frm.sum.value = FormatNumber( sum )
End Sub
</script>
</HEAD>
<BODY>
<FORM>
<TABLE BORDER="0">
<TR>
    <TD>Enter a Number</TD>
    <TD><INPUT NAME="nom0" SIZE="10"></TD>
</TR>
<TR>
    <TD>Enter a Number</TD>
    <TD><INPUT NAME="nom1" SIZE="10"></TD>
</TR>
<TR>
    <TD>Enter a Number</TD>
    <TD><INPUT NAME="nom2" SIZE="10"></TD>
</TR>
<TR>
    <TD align=right>Total:</TD>
    <TD><INPUT NAME="sum" SIZE="10" readonly></TD>
</TR>
<TR>
    <TD></TD>
    <TD><INPUT Type=Button Value="Get total" onClick="Call Total(me)"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
Reply With Quote
  #3 (permalink)  
Old September 18th, 2008, 08:57 AM
Authorized User
 
Join Date: Mar 2006
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot Old Pedant but why must "Call Total(me)" not "Call Total(you)" it just an argument.

<TR>
    <TD></TD>
    <TD><INPUT Type=Button Value="Get total" onClick="Call Total(me)"></TD>
</TR>


Reply With Quote
  #4 (permalink)  
Old September 18th, 2008, 10:26 AM
Authorized User
 
Join Date: Mar 2006
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It couldnt works.....fuh !

<HTML>
    <HEAD>
            <TITLE>
                Old Pedant
            </TITLE>


        <SCRIPT LANGUAGE="VBScript">

            Sub compare( aButton )

                dim sum, frm
            Set frm = aButton.form

            if CINT( frm.nom0.value ) < CINT( frm.nom1.value ) and CINT( frm.nom0.value ) < CINT( frm.nom2.value ) then

                if CINT( frm.nom0.value ) mod 2 = 0 then

                    msgbox (CINT( frm.nom0.value ) & " is the smallest and Even number")
                else
                    msgbox (CINT( frm.nom0.value ) & " is the smallest and Odd number")

                end if


            elseif CINT( frm.nom1.value ) < CINT( frm.nom0.value ) and CINT( frm.nom1.value ) < CINT( frm.nom2.value ) then

                if CINT( frm.nom1.value ) mod 2 = 0 then

                    msgbox (CINT( frm.nom1.value ) & " is the smallest and Even number")
                else
                    msgbox (CINT( frm.nom1.value ) & " is the smallest and Odd number")

                end if


                elseif CINT( frm.nom2.value ) < CINT( frm.nom0.value ) and CINT( frm.nom2.value ) < CINT( frm.nom1.value ) then

                    if CINT( frm.nom2.value ) mod 2 =0 then

                        msgbox (CINT( frm.nom2.value ) & " is the smallest and Even number")
                    else
                        msgbox (CINT( frm.nom2.value ) & " is the smallest and Odd number")

                    end if
            end if

            End Sub


        </SCRIPT>


    </HEAD>



    <BODY>

        <FORM>

            <TABLE BORDER="0">

            <TR>
                <TD>
                    Enter a Number
                </TD>

                <TD>
                    <INPUT NAME="nom0" SIZE="10">
                </TD>
            </TR>

            <TR>
                <TD>
                    Enter a Number
                </TD>

                <TD>
                    <INPUT NAME="nom1" SIZE="10">
                </TD>
            </TR>

            <TR>
                <TD>
                    Enter a Number
                </TD>

                <TD>
                    <INPUT NAME="nom2" SIZE="10">
                </TD>
            </TR>

            </TABLE>


            <BR>

            <INPUT Type=Button Value="Enter" onClick="Call compare(me)">

        </FORM>
    </BODY>

</HTML>

Reply With Quote
  #5 (permalink)  
Old September 18th, 2008, 02:39 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Why do you say "couldn't work"??? Seems to me it worked fine. Except your code doesn't handle the case when two values are the same and also the least.

Anyway, "me" (or "ME" or "Me") is a special keyword in VBScript that means "the current object". So in an ONCLICK handler, "me" refers to the object that was clicked on...the button.

Your code could be a lot shorter and could be written to handle invalid data from the form fields. Try this:
Code:
<HTML>
<HEAD>
<script language="VBScript">
Sub Compare( aField )
    Dim frm, n0, n1, n2, least, evenOdd
    Set frm = aField.form
    n0 = 1E99 : n1 = 1E99 : n2 = 1E99
    On Error Resume Next
        n0 = CLNG( frm.nom0.value )
        n1 = CLNG( frm.nom1.value )
        n2 = CLNG( frm.nom2.value )
    On Error GoTo 0
    If n0 <= n1 AND n0 <= n2 Then
       least = n0
    Elseif n1 <= n0 AND n1 <= n2 Then
       least = n1
    Else
       least = n2
    End If
    If least > 1E20 Then 
         frm.answer.value = "No valid numbers were entered...try again"
         Exit Sub
    End If
    If least MOD 2 = 0 Then evenOdd = "even" Else evenOdd = "odd"
    frm.answer.value = least & " is the smallest and it is " & evenOdd
End Sub
</script>
</HEAD>
<BODY>
<FORM>
<TABLE BORDER="0">
<TR>
    <TD>Enter a Number</TD>
    <TD><INPUT NAME="nom0" SIZE="10" onChange="Call Compare(me)"></TD>
</TR>
<TR>
    <TD>Enter a Number</TD>
    <TD><INPUT NAME="nom1" SIZE="10" onChange="Call Compare(me)" ></TD>
</TR>
<TR>
    <TD>Enter a Number</TD>
    <TD><INPUT NAME="nom2" SIZE="10" onChange="Call Compare(me)"></TD>
</TR>
<TR>
    <TD align=right>Answer:</TD>
    <TD><INPUT NAME="answer" SIZE="50" readonly onFocus="Call me.form.nom0.focus()"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
Reply With Quote
  #6 (permalink)  
Old September 20th, 2008, 07:21 PM
Authorized User
 
Join Date: Mar 2006
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for my late reply Old Pedant, yeah you rite...it because my condition were not proper coded, thanks....now I already got it and it works after corrected...

Now I understood why must "me" not "you" because you are so creative not like me...hahahaha

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Submit text to main page from text area... user0b PHP How-To 2 June 30th, 2008 09:52 PM
Need help: Not able to Assign Value to a Text Area steveleong Classic ASP Professional 3 February 20th, 2008 09:15 PM
text area box shoakat Classic ASP Databases 2 September 11th, 2004 07:28 AM
text in limited area alittlebitter32 Dreamweaver (all versions) 4 July 8th, 2004 10:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.