PDA

View Full Version : Obtaining a javascript



mae
Aug 25th, 2003, 02:27 PM
I am a complete novice trying to do the impossible for a charity. Im wondering if anyone could tell me how it is possible to obtain two scripts to do the following. a) to automatically insert a total in a form created in frontpage. e.g. 2 ordered at $1.20 equals a total of $2.40. Its the $2.40 bit I want automatically added and b) create a logon for users. I would be ever so grateful if anyone advise me. Before you answer you should know that I am not kidding when I say complete novice. I have copied a few scripts from dynamicdrive and managed to edit them, but nothing too flash. Thanks...cheers

Vincent Puglia
Aug 25th, 2003, 02:56 PM
Hi,

1) Logon scripts need to be done server side; otherwise, anyone could get the username and its password by viewing the page's source.

2) the same is essentially true for ecommerce.

3) people earn their livings writing the above type of scripts

With that in mind, the following demonstrates the essentials. If you would like to see a different example of an orderform with full explanation of the code, see the "Orderform 1" script/tutorial at my site (GrassBlade)



<script type="text/javascript">
<!--
function doit(formObj)
{
formObj.total1.value = formObj.price1.value * formObj.qty1[formObj.qty1.selectedIndex].value;
formObj.total2.value = formObj.price2.value * formObj.qty2[formObj.qty2.selectedIndex].value;

formObj.gtotal.value= parseFloat(formObj.total1.value) + parseFloat(formObj.total2.value);
}
//-->
</script>
</head>
<body>
<form name="a">
<select name="qty1">
<option selected value="0">Select Qty</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Price:<input type="text" name='price1' value='9.99' onfocus='this.blur()'>
Total:<input type="text" name='total1' onfocus='this.blur()'>
<select name="qty2">
<option selected value="0">Select Qty</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Price:<input type="text" name='price2' value='1.20' onfocus='this.blur()'>
Total:<input type="text" name='total2' onfocus='this.blur()'>
<input type="text" name='gtotal' onfocus='this.blur()'>
<input type="button" value='Finished' onclick='doit(this.form)'>
</form>


Vinny

mae
Aug 25th, 2003, 03:08 PM
Thanks for that vinny. I will have a look at your website. You have saved me a stack of time trying to search for a script that will give me the logon feature. At least I know now what can't actually be done my me! :->

Mae

Kor
Aug 25th, 2003, 04:25 PM
Let's be fair... "people earn their livings writing the above type of scripts" AND modifying the others' above type of scripts and using it... :-)

Vincent Puglia
Aug 25th, 2003, 09:56 PM
Hi mae,

When you get stuck (which you probably will since scripts never work the first time out) repost with some code or let me know.

Kor:

modifying...

In my statement to Mae, I was referring primarily to server-side coding. Modifying javascripts is how virtually all of us have learned javascript.

Vinny