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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is wrong with this code?

Status
Not open for further replies.

wolf73

Programmer
Feb 12, 2006
93
CA
I want to delete all the selected (checkbox checked)items from the bag. I am trying to undersnatd the folowing code. It is suppose to produce URL like

fields?package_id=114&items=211,212


instead it give me lot of junk like

fields?package_id=%3C?=%20$this-%3Epackage-%3Eid%20?%3E&items=211,212,
each,all,any,collect,detect,findAll,grep,include,inject,invoke,max,min,
partition,pluck,reject,sortBy,toArray,zip,inspect,find,select,member,
entries,_reverse,_each,clear,first,last,compact,flatten,without,remove,
removeItem,indices,call,______array



it gies me items 212 & 212 but what this stuff
"each,all,any,collect,detect,findAll,grep,include,inject,invoke,max,min,
partition,pluck,reject,sortBy,toArray,zip,inspect,find,select,member,
entries,_reverse,_each,clear,first,last,compact,flatten,without,remove,
removeItem,indices,call,______array"

I don't undersnad this for loop and if statment


function delete_selected_internal_field(package_id)
{

var tmpURL = '/integration/delete_multiple_internal_fields?package_id=' + package_id + '&items=';

var tmpConfirm = '\n';
for (var i in selected)
{
if (selected != 0 && i != 'extend')
{

tmpURL += i + ',';
tmpConfirm += i + '\n';

}
}


if (confirm('Are you sure you want to delete these internal fields?' + tmpConfirm) == true)
location.replace(tmpURL.substring(0, tmpURL.length - 1));
}
 
This line:

Code:
for (var i in selected)

iterates over the "selected" object (which we have no idea about, incidentally, although I'm guessing it's a form?), and appends each property to "tmpURL", if it's not called "extend".

Then you are going to the URL "tmpURL".

So - if you don't want all that stuff there, why add it in?

I'm guessing you're using an early version of the Prototype JS library. If so, consider upgrading to one that doesn't add all these extra methods to your object.

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Your tracing of nature of object vs index is misleaded by your symbol.
[tt]
for (var [blue]x[/blue] in selected)
{
if ([red]x[/red] != 0 && [blue]x[/blue] != 'extend')
{
tmpURL += [blue]x[/blue] + ',';
tmpConfirm += [blue]x[/blue] + '\n';
}
}
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top