PDA

View Full Version : Parsing out post method variables


Terry
09-28-2002, 08:15 PM
I'm trying to parse out the variables at the end of a url that was passed from another page and put them into a javascript array. Say my URL is the following:
file:///C:/Documents%20and%20Settings/terry/Desktop/Testing/passPostGet2.htm?qty1=2&qty2=3&qty3=34&qty4=3&qty5=34&qty6=2&p1Total=199.98&p2Total=329.7&p3Total=4246.6&p4Total=449.7&p5Total=5096.6&p6Total=339.8&theTotal=10662.38

Here is the code I am working on.


var test, manip, manip2;
var manip3 = new Array();

test = document.location.toString();
manip = test.split("?");
manip[0] = "";
manip2 = manip[1].split("&");
for(var i = 0; i < manip2.length; i++)
manip3[i] = manip2[i].split('=');

alert(manip3.join("-"));


Up until the creation of manip2 array it is doing what I want it to do: manip2[0] is qty1=2, manip2[1] is qty2=3 etc.

When I try to split each manip2 subscript again at the "=", I get some funny results. manip3[0] is 'qty1,2' and manip3[1] is 'qty2,3'.
Any ideas on how I can tokenize manip2 into separate fields?

Thanks,
Terry

adios
09-28-2002, 08:23 PM
You'll be getting several responses to this - everyone seems to have their own preference; personally, I use Martin Honnen's approach of creating a 'handable object'; a hash seems like a logical structure here...

http://www.faqts.com/knowledge_base/view.phtml/aid/969

p.s. hope you meant 'get'..

Terry
09-28-2002, 09:15 PM
That's some ingenious scripting, thanks!

-Terry

ps: I meant to say 'get'. :thumbsup: