Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / Removing [brackets] from <input name="id[x]"

Removing [brackets] from <input name="id[x]"

Locked

Views: 1,696

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
21 Nov 2007, 7:08 PM
#1
rippyuk avatar

rippyuk

New Zenner

Join Date:
Oct 2007
Posts:
5
Plugin Contributions:
0

Removing [brackets] from <input name="id[x]"

Hi guys, quick question for someone who knows Zen a bit better than me.

I need to remove the brackets from the input name generated by the attributes system.

e.g.

<input name="id[2]" 

would become

<input name="id2"

I've managed to get rid of the brackets by editing attributes.php, but this breaks the functionality of the attribute. Selecting the attribute before adding to cart results in no attribute ending up in the cart.

I'm assuming I need to edit another file, but can't find what to change, or where.

Please could somebody point me in the right direction! Many thanks..

21 Nov 2007, 8:43 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Removing [brackets] from <input name="id[x]"

As you've said, removing the brackets creates a lot of trouble.
So, the more important issue is your reason behind wanting to make the change.
Thus, my reply to your post is .... Why?

21 Nov 2007, 10:02 PM
#3
rippyuk avatar

rippyuk

New Zenner

Join Date:
Oct 2007
Posts:
5
Plugin Contributions:
0

Re: Removing [brackets] from <input name="id[x]"

I'm using the attribute form elements from the standard product info pages, to build a separate, custom form on another page.

I'm using Javascript to change, show & hide elements of the custom form, depending on which other attributes are selected.

The reason for removing the brackets is that one section of my custom form relies on a set of radio buttons controlling the contents of a dropdown menu below. Please see the except of code below to illustrate my problem, which is highlighted in red:

if(document.cart_quantity.id[2][0].checked==true)
	{
		locFrom.innerHTML='<select name="selectFrom" style="width:120px"><option value="test">Test</option></select>';
		//document.write(locFrom.innerHTML);
	}
	if(document.cart_quantity.id[2][1].checked==true)
	{
		locFrom.innerHTML='<select name="selectFrom" style="width:120px"><option value="test2">Test2</option></select>';
	}

Javascript uses the numbers [0], [1], [2] etc after the input name to identify each radio button in the set - but the fact that id[2] also contains bracketed numbers breaks the form.

I guess if it's not going to be possible to remove those brackets, I need to hit a Javascript forum instead!

21 Nov 2007, 10:38 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Removing [brackets] from <input name="id[x]"

The brackets cause the value to be treated as an array, which is crucial for processing the selected options when the Submit button is pressed.

I'm sure there will be other ways to process the information in your javascript. Perhaps you'll need to declare some other variables and stuff your information into them first, and then reference those variables with [0] or [1] etc appended to them. Or maybe lookup the object by name first, and reference those results instead.