Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Feaky 2

Status
Not open for further replies.

kizmar2

Programmer
Joined
May 25, 2004
Messages
164
Location
US
Can anyone help me out here... I am writing a page for a friend of mine and it's driving me up the wall. The javascript suddenly won't work in Firefox (FF), yet it works in Internet Explorer (IE) with no errors.

THEN, the table in IE looks all crappy, but in FF it looks fine. *sigh*

Here's the page:

Here's the Javascript I'm using:
Code:
// Created for the pax.php form

// This funtion will fill in the package pricing when user selects a payment frequency
// p = payment frequency selected
function fillWith(p) {
	// Create the base form object
	i = document.paxreg;
	
	switch(p) {
		// Set all the text boxes to the prices selected
		case 'month':
			i.price1.value = '- $15.00';
			i.price2.value = '- $25.00';
			i.price3.value = '- $35.00';
			i.price4.value = '- $45.00';
			i.price5.value = '- $55.00';
			break;
		case 'quarter':
			i.price1.value = '- $45.00';
			i.price2.value = '- $75.00';
			i.price3.value = '- $105.00';
			i.price4.value = '- $135.00';
			i.price5.value = '- $165.00';
			break;
		case 'year':
			i.price1.value = '- $180.00';
			i.price2.value = '- $300.00';
			i.price3.value = '- $420.00';
			i.price4.value = '- $540.00';
			i.price5.value = '- $660.00';
			break;
	}
}

// This function will submit the form and create the action based on the package selected
function teeth() {
	// We're going to set the action based on selected package...
	// Create the base form object
	i = document.paxreg;
	
	if (i.package.value != 0) {
		// They selected something so we can set the form action method
		switch(i.package.value) {
			case '1':
				i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=5';[/URL]
				break;
			case '2':
				i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=6';[/URL]
				break;
			case '3':
				i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=7';[/URL]
				break;
			case '4':
				i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=8';[/URL]
				break;
			case '5':
				i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=9';[/URL]
				break;
		}
		// It worked, return to form and submit
		return true;
	} else {
		// If the radio button hasn't been set throw an alert and return
		alert('Please select a package!');
		return false;
	}
	alert('Something else is broke...');
	return false;
}

I have a feeling the form action isn't getting set in FF, but then why is it working in IE?

KizMar
------------
 
Try:

i = document.forms['paxreg'];

and

i.elements['price1'].value;
i.elements['price2'].value;
i.elements['price3'].value;
i.elements['price4'].value;
i.elements['price5'].value;

Lee
 
kizmar2,

[1] [blue]"package" is reserved for ff & nn[/blue]. Change it to some other name like salespackage etc. --- [blue]This is a must[/blue] for cross browser other than ie.

[2] To use radio button set value as a conditional with pre-submit processing, you cannot use i.[red]sales[/red]package.value, you have to discover first with radio button is actually selected, then get its value. (I use salespackage as radio set name.)
[tt]
var nchk;
for (var j=0;j<i.salespackage.length;j++) {
if (i.salespackage[j].checked) {
nchk=j;
break;
}
}
[/tt]
Then use nchk so discovered within the conditionals like:
[tt]
if (i.salespackage[nchk] !=0) {
//etc etc
}
[/tt]
With [1] and [2], I think you can make it work cross browser already.

[3] Let your variable i local (with var keyword before its definition), no real need to have it global. This is minor issue and no real harm neither.

regards - tsuji
 
Amendment:
For the conditional line, I meant:
[tt]
if (i.salespackage[nchk][red].value[/red] !=0) {
//etc etc
}
[/tt]
- tsuji
 
Awesome tsuji... I think the whole problem was the use of "package" because it was a reserved name. I changed it to "pkg" and it works.

BTW - I'm setting a hidden field when someone clicks on a radio button so I don't have to cycle trough the nodes to find out what they picked. =)

KizMar
------------
 
OK now i have another problem... With the new Javascript below, everything seems to work except when someone picks the "Quarterly" payment frequency. It's populating the year action instead of the quarterly actions...

Code:
// Created for the pax.php form

// This funtion will fill in the package pricing when user selects a payment frequency
// p = payment frequency selected
function fillWith(p) {
	// Create the base form object
	var i = document.paxreg;
	
	switch(p) {
		// Set all the text boxes to the prices selected
		case 'month':
			i.price1.value = '- $15.00';
			i.price2.value = '- $25.00';
			i.price3.value = '- $35.00';
			i.price4.value = '- $45.00';
			i.price5.value = '- $55.00';
			break;
		case 'quarter':
			i.price1.value = '- $45.00';
			i.price2.value = '- $75.00';
			i.price3.value = '- $105.00';
			i.price4.value = '- $135.00';
			i.price5.value = '- $165.00';
			break;
		case 'year':
			i.price1.value = '- $180.00';
			i.price2.value = '- $300.00';
			i.price3.value = '- $420.00';
			i.price4.value = '- $540.00';
			i.price5.value = '- $660.00';
			break;
	}
}

// This function will submit the form and create the action based on the package selected
function teeth() {
	// We're going to set the action based on selected package...
	// Create the base form object
	var i = document.paxreg
	
	if (i.payFreq.value != 0) { // They selected a payment frequency
		if (i.pkg.value != 0) { // They selected a package
			switch (i.payFreq.value) {
				// They selected to pay monthly
				case '1':
					switch (i.pkg.value) {
						case '1':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=5&demo=y';[/URL]
							break;
						case '2':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=6&demo=y';[/URL]
							break;
						case '3':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=7&demo=y';[/URL]
							break;
						case '4':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=8&demo=y';[/URL]
							break;
						case '5':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=9&demo=y';[/URL]
							break;
					}
				// They selected to pay every 3 months
				case '2':
					switch (i.pkg.value) {
						case '1':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=10&demo=y';[/URL]
							break;
						case '2':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=12&demo=y';[/URL]
							break;
						case '3':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=14&demo=y';[/URL]
							break;
						case '4':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=16&demo=y';[/URL]
							break;
						case '5':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=18&demo=y';[/URL]
							break;
					}
				// They selected to pay once a year
				case '3':
					switch (i.pkg.value) {
						case '1':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=11&demo=y';[/URL]
							break;
						case '2':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=13&demo=y';[/URL]
							break;
						case '3':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=15&demo=y';[/URL]
							break;
						case '4':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=17&demo=y';[/URL]
							break;
						case '5':
							i.action = '[URL unfurl="true"]https://www.2checkout.com/2co/buyer/purchase?sid=100402&quantity=1&product_id=19&demo=y';[/URL]
							break;
					}
			}
			// Looks like everything worked, allow form to submit
			return true;
			} else {
				// There's no package selected
				alert('Please select a package.');
				return false;
			}
		} else {
			// There's no payment frequency selected
			alert('Please select a payment frequency.');
			return false;
		}
		// It worked, return to form and submit

}

KizMar
------------
 
kizmar2,
It can only mean (p=='quarter') evaluated to false. You know where to look for the reason why!
- tsuji
 
Not quite sure what you're getting at. I think the problem lies in the "teeth()" function with the "switch (i.payFreq.value)" statement somewhere.

I added a default to the main case statement... How can it be hitting the default, yet still be populating the action with the 3rd case statement?

KizMar
------------
 
OK... so when I select the "Quarterly" payment frequency, my Javascript is hitting case 2, case 3 and default... This makes no sense.

KizMar
------------
 
You don't have enough break statements. You have them inside the innermost case statements, but not the outer ones.

Lee
 
Gnnahhhh I figured it was something stupid like that... didn't even catch it. Thanks!

KizMar
------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top