Link to home
Start Free TrialLog in
Avatar of Jazzy 1012
Jazzy 1012

asked on

Change variable when you click + or - on another end

I have this code:
First part
										<div class="col-xs-4">
											<div class="black" style=" display: -webkit-inline-box; padding-top: 50px;float: right;">
										
												<div style="margin-right: 10px;">
													<input disabled id="qty<?= $delivery_id1 ?>" type="number" value="<?=$num_of_meals1?>" min="0" step="1" style="border:1px solid #d7d6d0;background:transparent;width:35px;height:33px;color:#000;font-size:21px;font-weight:700;">		
												</div>
											<input hidden="" id="price" value="">
										<p style="width:60px;font-size: 20px;margin-top: 8px;" ><?php echo $qty_price1;?> </strong> </p>
										
											</div>

Open in new window


Here is the second part:
							<div style="margin-right: 10px;margin-top: -15px">
								<input type="hidden" name="meal_id[]" value="<?php echo $meal_options_id2?>">
								<i id="qty-minus<?=$meal_options_id2 ?>" class="fa fa-minus-circle controls" style="color: #d7d6d0;margin-right:10px"></i>
								<input name="qty[]" id="qty<?=$meal_options_id2 ?>" type="number" value="<?=$num_of_meals2?>" min="0" step="1" style="border:1px solid #d7d6d0;background:transparent;width:35px;height:33px;color:#000;font-size:21px;font-weight:700;">		
								<i id="qty-plus<?=$meal_options_id2 ?>" class="fa fa-plus-circle controls" style="color: #d7d6d0;margin-left:10px"></i>
							</div>

Open in new window


I can change the second part but the +and - sign, but how can it also change inside the first part?
This is my output, I put the number 1 next to the first part and number 2 next to the second part(which I explained the function of earlier)
User generated image
Avatar of Jazzy 1012
Jazzy 1012

ASKER

I figured it out like this:
$('.fa-plus-circle').click(function () {
	//alert(this.id); -- THIS GETS ME THE qty-plus212
	var target=$(this).closest("div").children("input[type=number]")
	number=target.val()
	//alert($("#qty" + this.id)); -- THIS IS FOR THE ONE OUTSIDE.

});

Open in new window


How can I split the qty-plus212 into just a variable containing the id starting just from the first number in this case "212" so that I can add it to the
$("#qty + "212 variable"") . val(number)

Open in new window

 Number contains the changed qtys each time I add or remove
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial