Thanks Ricardo, I got it to work :D Here's the final code.
////////////////// JS /////////////////// $(document).ready(function(){ $("select").empty().append( new Option(0), new Option(1), new Option(2), new Option(3) ); $(":button").click(function(){ $(this).parent().prev("td").find('select').val(1); }); }); /////////////////// HTML //////////////////// <tr> <td>Perogy and Egg platter</td> <td>3 eggs, 7 perogies and Bavarian or Chorizo sausage and toast</td> <td>$10.49</td> <td> <select name="select"> <option>0</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> </td> <td><input type="button" value="Add" /></td> </tr> //////////////////////////// Thanks a ton for your help guys. - Justin =) On Feb 26, 11:51 pm, ricardobeat <ricardob...@gmail.com> wrote: > Oh, I guess the select is not a descendant of the button. It all > depends on the HTML. Try this, if it doesn't work please paste your > html so we can see what's going on. > > $(".myButtons").click(function(){ > $(this).parent().find('select').val(1); > }); > > - ricardo > > On Feb 26, 10:15 pm, Jsudesign <jus...@jsudesign.com> wrote: > > > Hi James, thanks for the response. > > > It wasn't that I did try your idea. > > It's something to do with the $(this) part. > > > Example: > > $(this).find("select").val('1'); //this will select the option > > with // Does not work > > $("tr").find("select").val('1'); //this will select the option > > with // Works but changes all buttons. > > > Any thoughts? Thanks! > > > On Feb 26, 5:00 pm, James <james.gp....@gmail.com> wrote: > > > > You probably need a 'value' attribute assigned to your options. eg.: > > > <option value="1">1</option> > > > <option value="2">2</option> > > > > On Feb 26, 2:45 pm, Jsudesign <jus...@jsudesign.com> wrote: > > > > > Thanks Ricardo, You are wonderful are understanding my problem. > > > > > After trying your code. The append part works, but the selection part > > > > does not. > > > > > Any suggestions? Thanks for your help, I'm fairly new to jquery. > > > > > // Code does not work...? hmm > > > > > $(".myButtons").click(function(){ > > > > $(this).find('select').val(1); //this will select the option > > > > with > > > > value == 1 > > > > }); > > > > }); > > > > > On Feb 24, 11:25 pm, ricardobeat <ricardob...@gmail.com> wrote: > > > > > > Probably changing > > > > > > $("tr #button").click(function(){... > > > > > > to this > > > > > > $("tr #button").click(function(){ > > > > > $("select", this).html("<option>0</option><option > > > > > selected='selected'>1</ > > > > > option><option>2</option><option>3</option><option>4</ > > > > > option><option>5</option>"); > > > > > return false; > > > > > }); > > > > > > Will fix it. You need to find the select element in the right context, > > > > > remember that jQuery's selectors work like CSS. > > > > > > Also I would write your code like this (you don't need to rewrite all > > > > > the options just to select one, and you're not setting the option's > > > > > values): > > > > > > $(document).ready(function(){ > > > > > > $("select").empty().append( > > > > > new Option(0), > > > > > new Option(1), > > > > > new Option(2) > > > > > ); > > > > > > $(".myButtons").click(function(){ > > > > > $(this).find('select').val(1); //this will select the option with > > > > > value == 1 > > > > > }); > > > > > > }); > > > > > > From the code your posted one can assume you have multiple elements > > > > > with the "button" ID. That's invalid (IDs should be unique) and will > > > > > certainly cause you trouble, use class="something" instead. > > > > > > cheers, > > > > > - ricardo > > > > > > On Feb 23, 9:30 pm, Jsudesign <jus...@jsudesign.com> wrote: > > > > > > > Hi everyone, > > > > > > > I have an add button set up and when you click it it changes the > > > > > > selected input from 0 to 1. > > > > > > Where my problem is...is that it's doing this for every product. > > > > > > > Here's an > > > > > > example:http://rickyscentralcitymall.com/ordering/tables.html > > > > > > > I would add a new class to each product, but that's going to be a > > > > > > pain > > > > > > in the end because there are 100+ items on the menu. > > > > > > > Here's the code I'm working with currently. > > > > > > > $(document).ready(function(){ > > > > > > $("select").html("<option>0</option><option>1</option><option>2</ > > > > > > option><option>3</option><option>4</option><option>5</option>"); > > > > > > $("tr #button").click(function(){ > > > > > > $("select").html("<option>0</option><option > > > > > > selected='selected'>1</ > > > > > > option><option>2</option><option>3</option><option>4</ > > > > > > option><option>5</option>"); > > > > > > return false; > > > > > > }); > > > > > > > }); > > > > > > > Any help with this would be great. > > > > > > > Best, > > > > > > Justin