javascript - Get Option Value OnClick with No Class/ID -


I am creating an ecommerce website with 100 items. Each item has an item option (i.e. small, medium, large). Each option has an integer in which the option is identified.

When the user clicks "Add to Cart", then I should express that value as a variable. The problem is that all these items have the same exact class / id, so I can not write an onclick function for every one.

How can I use jQuery for an option, to identify ID?

The basic structure of the item form:

  & lt; Form & gt; & Lt; Label & gt; First item & lt; / Labels & gt; & Lt; Gt selection and; & Lt; Option value = "6432" & gt; Big & lt; / Options & gt; & Lt; Option value = "5332" & gt; Small & lt; / Options & gt; & Lt; / Select & gt; & Lt; Input type = "submit" value = "add to cart" & gt; & Lt; / Form & gt;     

Click "itemprop =" text " >

Try this:

  $ ('input [type = "submit"]'). ('Click', function (e) {e.preventDefault (); $ (This) .prev ('Select'). Val ());});   

Updated JSFiddle:

Note : If anything you can do that to reduce the code 'input [type = "submit"]' selector, you should, for example, if you have There is a fundamental element with the ID, so you can do it as if the '# purchase-item input Tar = "submit"] '.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -