• 0

Very lost on a simple Vbscript project for school


Question

I have to create a simple bookstore style site. My site needs to ask for how many books you want, and then multiply that number by 9.95 which is the price of the book, and then add 4.95 for shipping. It just simply needs to ask for how many books you want. and then output that number in a message box. It needs a button to initiate the book sale.

this is what i have so far.

<html>
<head>
<p style="font-size:30px">Welcome to Artis' Book Collection</p>

<script type="text/vbscript">
Option Explicit

	sub ValNumber()

		dim number 
		dim answer
		dim books


	    number = InputBox("How many books do you want?")
		answer = isNumeric(number)

	'add numbers
		answer = number * 9.95
		msgBox number & " * " & 9.95 " - " & answer

		'Depending on answer display the appropriate message
		if answer = true then
			alert("Your Total is: answer")
		else
			alert("Sorry you did not enter a number")
		end if
	end sub



</script>
</head>
<body>
<b>
This page will help you to order some of my fantastic books.
When prompted enter in the book title and the number of books you wish to order.
You will then see your total cost.
<br>
<br>
To get started click on the Book Sale Button

</b><br>
<button onclick="ValNumber()">Is Number?</button>
</body>
</html>

any help you can assist me with will be appreciated. i'm not very good at this so explaining is needed.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Oh yea I'm sure that's the answer he was looking for Anon... :rolleyes:

I made a few amendments in the structure and the way the function is called from the button.

<html>
<head>
<p style="font-size:30px">Welcome to Artis' Book Collection</p>

<script type="text/vbscript">
<!--
        sub ValNumber_OnClick

                dim number 
                dim answer
                dim books


            number = InputBox("How many books do you want?")
                answer = isNumeric(number)

        'add numbers
                answer = number * 9.95
                msgBox number & " * " & 9.95 & " - " & answer

                'Depending on answer display the appropriate message
                if answer = true then
                        alert("Your Total is: answer")
                else
                        alert("Sorry you did not enter a number")
                end if
        end sub

-->

</script>
</head>
<body>
<b>
This page will help you to order some of my fantastic books.
When prompted enter in the book title and the number of books you wish to order.
You will then see your total cost.
<br>
<br>
To get started click on the Book Sale Button

</b><br>
<button NAME="ValNumber">Is Number?</button>
</body>
</html>

Try that. :)

Link to comment
Share on other sites

  • 0

Few questions to think about, is it good practise to use one variable to hold different types of data used for different purposes?

answer = isNumeric(number) [Boolean Output]
answer = number * 9.95 [Numeric Output]

Does this is statement provide the functionality you are expecting, on face value it doesn't appear to do so?

if answer = true then [Checking for Boolean]
    alert("Your Total is: answer") [Will output text as string, exactly as shown]
else
    alert("Sorry you did not enter a number")
end if

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.