Pergunta

I have to add a kind of shopping cart to a website I'm designing for a web design class where you can select a product from a combo box and then by clicking a button you can add it to a text area and then in a textbox it should show you how much you gotta pay for what you selected but the only thing I've done by now is to show the products in the combo but the adding and the result parts I'm totally lost I would appreciate if somebody helps me with this cause I only got 2 days to finish it or I will flunk the subject

Foi útil?

Solução

Include this in your html head

<script src="http://code.jquery.com/jquery-latest.min.js"></script>

Assuming your HTML looks like this:

<select name="products" id="products">
<option value="phone">Phone</option>
<option value="laptop">Laptop</option>
<option value="shirt">Shirt</option>
</select>

<input type="submit" id="submit"/>

<div id="selection"></div>

Use jquery to get the value on click event of submit and write that value in selection div:

<script>
$('#submit').click(function(e){

var selected=$("#products option:selected").val();
$('#selection').append("<p>"+selected+"</p>");
e.preventDefault();
});
</script>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top