thanks a lot evertjan and web.dev. i'll try all u guys suggested and
get back to you.
cheers
roohbir
On Oct 19, 10:38 am, "web.dev" <web.dev...@gmail.com> wrote:
> roohbir wrote:
> > <script language="JavaScript"
> > type="text/javascript"
> > src="myOwnJavaScript.js">1. The language attribute is deprecated, use the type attribute.
> 2. You can either use an external javascript or embedded, but not
> both.
>
> <script type = "text/javascript" src = "myOwnJavaScript.js"></script>
>
> <script type = "text/javascript">
> //etc
>
> > function ComputeCost()
> > {
> > //create an object
> > obj = new ShippingInfo(sampleform.menu1.value,
> > sampleform.menu2.value, sampleform.text1.value, sampleform.text2.value)It's good practice to start off your variables with "var" so that there
> is ambiguity to the person maintaining the code whether the variable is
> local or global.
>
> A "safer" way of accessing form elements would be to use the following
> syntax:
>
> document.forms["formName"].elements["elementName"].value;
>
> > //add a method
> > obj.GetShippingCost=GetShippingCost;Instead of adding the method to the object, it seems it would be better
> to just have the method already a part of the object to be invoked.
> See below.
>
> > //Invoke a method.
> > var Cost = obj.GetShippingCost();
> > var message = document.getElementById("myOwndivElement");
> > message.innerHTML = "Cost = " + Cost;
> > return false;
> > }
> > </script>[snip]
>
> > // This is a function that is added as a method of a JavaScript object
> > function GetShippingCost()To add a method to the object, one can go about doing this instead:
>
> ShippingInfo.prototype.GetShippingCost = function()
> {
> //etc
>
> This way, after you create a new object, you can just invoke it like
> so:
>
> obj.GetShippingCost();
>
> > {
> > int cost = 0;[snip if...else]
>
> It could become more efficient with the use of switches instead of
> nested if..else statements. (For scalability).
>
> > return cost;
> > }
|