0

I am looking at setting the option for my select dropdown which has been passed back from the DB.

 "<td><select id=\"sel" + res.sku.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '-') + "\"><option>True</option><option>False</option></select></td>" +

I have it passing over the option true or false, how would i go about setting this on the option please?

Thanks in advance.

Andrea Turri
  • 6,480
  • 7
  • 37
  • 63
thatuxguy
  • 2,418
  • 7
  • 30
  • 51
  • 2
    Do you want to select one of the two automatically? Try ` – pimvdb Jul 10 '12 at 15:31
  • @thattuxguy Did you have a chance to try any of the answers that were posted? – Jason Towne Jul 11 '12 at 14:44
  • Sorry, i chose to go down a different route. Basically it was silly to use a drop down as most items would be false as true is not displayed. So i simply added a update button, which then updates the DB and removes the row from the table. Seemed to be the best way for this. I was only going to use a dropdown as the person who made the previous version of the software did so. – thatuxguy Jul 11 '12 at 16:06

2 Answers2

0

Please see the article: .prop() vs .attr()

 $('#sel').prop('checked', false)

Or you could change the false to a true, depending upon your application's logic.

Community
  • 1
  • 1
Sablefoste
  • 4,032
  • 3
  • 37
  • 58
  • I'm not sure what checking a select element means. You'd at least need to specify the option. – pimvdb Jul 10 '12 at 15:35
  • 1
    You're right, @pimvdb. I just reasoned that since it was a true or false, it would was a radio button, not a pull down (my mistake). I might suggest that thatuxguy use a Radio button since true and false are mutually exclusive. – Sablefoste Jul 10 '12 at 15:38
0

I agree with Sable that a radio button might be a better choice in this situation, but if you're determined to use a drop down list, you can try something like this:

"<option" + (myValue === true ? " selected" : "") + ">True</option><option" + (myValue === false? " selected" : "") + ">False</option></select></td>"
Jason Towne
  • 8,014
  • 5
  • 54
  • 69
  • tested using this, and it worked well however i used a update button instead which made more sense. Thanks though, i will no doubt use this somewhere in the app :) – thatuxguy Jul 11 '12 at 16:08