Thanks again to James Figured this easy one out myself:
just changed: for (var i in rows) { var parts = rows[i].split(' '); partNum[i] = escape( parts[0] ); qty[i] = escape( parts[1] ); if(qty[i]=="undefined"|qty[i]==""){qty[i]= 1}; } On Oct 8, 9:12 am, "robert...@gmail.com" <robert...@gmail.com> wrote: > James - This is great!!! - thanks so much for the example. > > I am posting your code it here for reference...but I have one > additional question. > > I noticed that if the user puts a space after the part number but no > qty, then the querystring returns nothing. > If the user puts nothing after the part number then it reuturns > 'undefined'. > > Is there a way to put a default value of 1 if it is blank...something > like: > check the values after the partnumber and before the line return... > if it = space only then a line return then make it '[space]1' OR if it > a return line only then insert '[space]1' > Thanks again for your help > > Below is the solution to date: > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> > <head> > <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/ > jquery.min.js"></script> > <title>Test</title> > <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> > <style type="text/css" media="screen"> > body { background-color: #000; font: 16px Helvetica, Arial; color: > #fff; } > </style> > </head> > <body> > <p>Enter Part and Qty seperated by a space, <br /> > then line return and enter the second part and qty..etc..<br /> > ( I.E. bd7888 2)<br /> > <textarea cols="50" rows="4" id="partNum">BD7888 2 > BL9000 6</textarea> > <br /> > <input type="button" id="getData" value="Get Data" /> > </p> > <script type="text/javascript"> > > $("#getData").click(function() { > var data = $("#partNum").val(), > rows = data.split("\n"), > partNum = [], qty = [], > url = ''; > > for (var i in rows) { > var parts = rows[i].split(' '); > partNum[i] = escape( parts[0] ); > qty[i] = escape( parts[1] ); > } > > url = 'mypage.asp?Partnum='+partNum.join(',')+'&Qty='+qty.join(','); > alert(url); > > }); > > </script> > </body> > </html> > > On Oct 7, 4:06 pm, James <james.gp....@gmail.com> wrote: > > > > > I've set up a sample page on JS Bin:http://jsbin.com/oqeco > > > Check the source for the code. > > > On Oct 7, 2:38 am, "robert...@gmail.com" <robert...@gmail.com> wrote: > > > > It seems straight forward but I still need some advice. I have this so > > > far just to see if I cansplitthearraytwice...but it is not working > > > > $(document).ready(function() { > > > $("#GetData").click(function() { > > > var string = $('#PartNum').val().replace(/(\r\n)/g, "~"); > > > var group = string.split('~'); > > > $.each(group, function() { > > > var values = group.split(' '); > > > alert(values); > > > }); > > > > }); > > > > }); > > > > On Oct 6, 8:34 pm, James <james.gp....@gmail.com> wrote: > > > > > It should be fairly straightforward. > > > > Get the content of the text field: $("PartNum").val(); > > > > Use thesplit() function tospliteach line by "\n" (return). > > > > Then for each of those lines,splitit again by " " (space). > > > > (Store all of these in anarray(s).) > > > > Then you can use the join() function to add "," (comma) to a list in > > > > yourarray. > > > > > On Oct 6, 1:32 pm, "robert...@gmail.com" <robert...@gmail.com> wrote: > > > > > > I really hope someone can assist: > > > > > > I am trying to take a form field: > > > > > <textarea name="PartNum" cols="15" rows="5" id="PartNum" value=""></ > > > > > textarea> > > > > > > The user will put in part numbers , space, qty, carraige return ,then > > > > > another entry on the next line....it will look like this: > > > > > > bd1111 2 > > > > > bd1200 5 > > > > > > I want tosplitthis into two querystring variables before submitting > > > > > to next page: > > > > > > mypage.asp?Partnum=bd1111,bd1200&Qty=2,5 > > > > > > I have looked at the serialize() andarrayfunctions , but I can't > > > > > figure it out. > > > > > > thanks very much- Hide quoted text - > > > > > - Show quoted text -- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text -