Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Javascript needs modifying
Old 10-08-2007, 03:34 PM Javascript needs modifying
Novice Talker

Posts: 7
Name: James Hammond
Trades: 0
Thanks to tripy I've been able to set up a delegate booking form on my website www.brandhalo.co.uk/booking_form.html. This gives an opportunity for a user to pay for one delegate or two, the second having a discount, but only if the first delegate paid the full amount.

My payment processors were concerned about the ability for the user to submit a payment for the second delegate without paying for the main delegate, so they gave me the following script, modified from what tripy gave me, so that the discounted second delegate part could not be filled in unless the main delegate part was completed:

function load(){
window.status = "Made by Ville Leivo 15.07.2002"
document.getElementById("MC_secdel_firstname").dis abled=true
document.getElementById("MC_secdel_jtl").disabled= true
document.getElementById("MC_secdel_email").disable d=true
document.getElementById("MC_secdel_tel").disabled= true
document.getElementById("MC_secdel_fax").disabled= true
document.getElementById("MC_secdel_diet").disabled =true
document.getElementById("MC_secdel_acc").disabled= true
document.getElementById("item2").disabled=true
}
function count(){
var item1price = 249;
var item2price = 199;
var calc=document.getElementById('myForm');

// kortti
if (calc.item1.checked){
var witem1 = document.calc.item1.value = item1price;
} else {
var witem1 = document.calc.item1.value = 0;
}
if (calc.item2.checked && !calc.item2.disabled){
var witem2 = document.calc.item2.value = item2price;
} else {
var witem2 = document.calc.item2.value = 0;
}

calc.amount.value = witem1 + witem2;
}
function enableDiscount()
{
var selected=document.getElementById("item1").checked
if (selected==false)
{
document.getElementById("MC_secdel_firstname").dis abled=true
document.getElementById("MC_secdel_jtl").disabled= true
document.getElementById("MC_secdel_email").disable d=true
document.getElementById("MC_secdel_tel").disabled= true
document.getElementById("MC_secdel_fax").disabled= true
document.getElementById("MC_secdel_diet").disabled =true
document.getElementById("MC_secdel_acc").disabled= true
document.getElementById("item2").disabled=true
}
else if (selected==true)
{
document.getElementById("MC_secdel_firstname").dis abled=false
document.getElementById("MC_secdel_jtl").disabled= false
document.getElementById("MC_secdel_email").disable d=false
document.getElementById("MC_secdel_tel").disabled= false
document.getElementById("MC_secdel_fax").disabled= false
document.getElementById("MC_secdel_diet").disabled =false
document.getElementById("MC_secdel_acc").disabled= false
document.getElementById("item2").disabled=false
}
}
/*function disableDiscount()
{
document.getElementById("MC_secdel_firstname").dis abled=true
document.getElementById("MC_secdel_jtl").disabled= true
document.getElementById("MC_secdel_email").disable d=true
document.getElementById("MC_secdel_tel").disabled= true
document.getElementById("MC_secdel_fax").disabled= true
document.getElementById("MC_secdel_diet").disabled =true
document.getElementById("MC_secdel_acc").disabled= true
document.getElementById("item2").disabled=true
}*/

This works fine in IE7, but not in FF. In FF, both parts of the form can be filled in independently. As I understand it, FF looks for 'cleaner' Javascript, but from what little I know the script seems okay. Any ideas what's wrong?

In addition, I need to be able to prevent the user from altering the final total payment to be sent on to the payment processors. For example, if the final price is £290, it's possible at the moment for the user to amend the total to read just £29 and for this to go through to the processing stage. Is there any way to prevent the alteration of this one field?

Many thanks.
James
mollymowler is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-08-2007, 06:29 PM Re: Javascript needs modifying
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by mollymowler View Post
This works fine in IE7, but not in FF. In FF, both parts of the form can be filled in independently. As I understand it, FF looks for 'cleaner' Javascript, but from what little I know the script seems okay. Any ideas what's wrong?
In compliant browsers, document.getElementById does exactly what its name suggests. Your form elements don't have IDs they have names. You can either assign them all IDs matching/replacing their name attributes, or change the syntax of your script to read the elements by name.
Code:
document.formName.elementName
I think the former would be a better option.
logic ali is offline
Reply With Quote
View Public Profile
 
Old 10-08-2007, 06:57 PM Re: Javascript needs modifying
Novice Talker

Posts: 7
Name: James Hammond
Trades: 0
Thanks for this, but I'm not sure where everything goes.

The text fields currently have no IDs. So, for example, MC_secdel_firstname is:

<textarea name="MC_secdel_firstname" rows="2" class="booking_box"></textarea>

Should I change this to

<textarea name="MC_secdel_firstname" rows="2" class="booking_box" id="MC_secdel_firstname"></textarea>

And then run the script 'as is' (obviously changing each text field to include a matching ID)?

James
mollymowler is offline
Reply With Quote
View Public Profile
 
Old 10-08-2007, 07:13 PM Re: Javascript needs modifying
Novice Talker

Posts: 7
Name: James Hammond
Trades: 0
Actually, I've just answered my own question! I added an id to each text field using the same name as the field itself and hey presto, worked first time. Thanks very much for your help.

Any idea how I might solve the other vital part of the problem with preventing user amendment of the total sum text field?

Thanks again.

James
mollymowler is offline
Reply With Quote
View Public Profile
 
Old 10-08-2007, 08:48 PM Re: Javascript needs modifying
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by mollymowler View Post
Any idea how I might solve the other vital part of the problem with preventing user amendment of the total sum text field?
Make the field readonly. I hope you're going to validate this data on the server...
logic ali is offline
Reply With Quote
View Public Profile
 
Old 10-09-2007, 05:06 AM Re: Javascript needs modifying
Novice Talker

Posts: 7
Name: James Hammond
Trades: 0
READONLY only worked in FF, but didn't have any effect in IE7, so I added an onfocus='this.blur()' and it all works fine now.

Not sure what you mean by validating on the server. As soon as the 'submit' button is pressed, it goes off to Worldpay's processing page. Everything is working fine at this end!

Thanks for all your help...I'd be lost without you techies!

James
mollymowler is offline
Reply With Quote
View Public Profile
 
Old 10-09-2007, 09:59 AM Re: Javascript needs modifying
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by mollymowler View Post
READONLY only worked in FF, but didn't have any effect in IE7, so I added an onfocus='this.blur()' and it all works fine now.
That's no solution.

Try this.
Complete the form and press 'Calculate'.
In the address bar, type: javascript:void(document.forms[0].amount.value=1)
Disable JavaScript.
Click 'Pay'.
Quote:
Not sure what you mean by validating on the server.
Then you need to learn a server-side language about now.
Quote:
As soon as the 'submit' button is pressed, it goes off to Worldpay's processing page.
Yes - but Worldpay doesn't know what the amount should be.
Quote:
Everything is working fine at this end!
You won't be after I've booked 100 seminar places at 50 pence each.
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Javascript needs modifying
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26502 seconds with 12 queries