Change the data when the option is selected
up vote
2
down vote
favorite
I have the following pricing plan and I've already broke my had trying to change the data of list item <li>Gain 20 Likes</li>
when the appropriate option is chosen. For example when chosen the option <option value="10.00">15 .......$10.00</option>
I want the list item to display <li>Gain 15 Likes</li>
, when chosen <option value="15.00">30 .......$15.00</option>
to display <li>Gain 30 Likes</li>
etc. My javascript knowledge is too poor to solve this problem unfortunately.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00">15 .......$10.00</option>
<option value="15.00">30 .......$15.00</option>
<option value="30.00">50 .......$30.00</option>
<option value="60.00">100 .....$60.00</option>
<option value="100.00">200 .....$100.00</option>
<option value="140.00">300 .....$140.00</option>
<option value="220.00">500 .....$220.00</option>
<option value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li>Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
javascript jquery html
add a comment |
up vote
2
down vote
favorite
I have the following pricing plan and I've already broke my had trying to change the data of list item <li>Gain 20 Likes</li>
when the appropriate option is chosen. For example when chosen the option <option value="10.00">15 .......$10.00</option>
I want the list item to display <li>Gain 15 Likes</li>
, when chosen <option value="15.00">30 .......$15.00</option>
to display <li>Gain 30 Likes</li>
etc. My javascript knowledge is too poor to solve this problem unfortunately.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00">15 .......$10.00</option>
<option value="15.00">30 .......$15.00</option>
<option value="30.00">50 .......$30.00</option>
<option value="60.00">100 .....$60.00</option>
<option value="100.00">200 .....$100.00</option>
<option value="140.00">300 .....$140.00</option>
<option value="220.00">500 .....$220.00</option>
<option value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li>Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
javascript jquery html
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have the following pricing plan and I've already broke my had trying to change the data of list item <li>Gain 20 Likes</li>
when the appropriate option is chosen. For example when chosen the option <option value="10.00">15 .......$10.00</option>
I want the list item to display <li>Gain 15 Likes</li>
, when chosen <option value="15.00">30 .......$15.00</option>
to display <li>Gain 30 Likes</li>
etc. My javascript knowledge is too poor to solve this problem unfortunately.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00">15 .......$10.00</option>
<option value="15.00">30 .......$15.00</option>
<option value="30.00">50 .......$30.00</option>
<option value="60.00">100 .....$60.00</option>
<option value="100.00">200 .....$100.00</option>
<option value="140.00">300 .....$140.00</option>
<option value="220.00">500 .....$220.00</option>
<option value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li>Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
javascript jquery html
I have the following pricing plan and I've already broke my had trying to change the data of list item <li>Gain 20 Likes</li>
when the appropriate option is chosen. For example when chosen the option <option value="10.00">15 .......$10.00</option>
I want the list item to display <li>Gain 15 Likes</li>
, when chosen <option value="15.00">30 .......$15.00</option>
to display <li>Gain 30 Likes</li>
etc. My javascript knowledge is too poor to solve this problem unfortunately.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00">15 .......$10.00</option>
<option value="15.00">30 .......$15.00</option>
<option value="30.00">50 .......$30.00</option>
<option value="60.00">100 .....$60.00</option>
<option value="100.00">200 .....$100.00</option>
<option value="140.00">300 .....$140.00</option>
<option value="220.00">500 .....$220.00</option>
<option value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li>Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00">15 .......$10.00</option>
<option value="15.00">30 .......$15.00</option>
<option value="30.00">50 .......$30.00</option>
<option value="60.00">100 .....$60.00</option>
<option value="100.00">200 .....$100.00</option>
<option value="140.00">300 .....$140.00</option>
<option value="220.00">500 .....$220.00</option>
<option value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li>Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00">15 .......$10.00</option>
<option value="15.00">30 .......$15.00</option>
<option value="30.00">50 .......$30.00</option>
<option value="60.00">100 .....$60.00</option>
<option value="100.00">200 .....$100.00</option>
<option value="140.00">300 .....$140.00</option>
<option value="220.00">500 .....$220.00</option>
<option value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li>Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
javascript jquery html
javascript jquery html
edited Nov 10 at 16:40
Stony
19.6k135064
19.6k135064
asked Nov 10 at 16:25
Jamdev
287112
287112
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
Here is a simple solution with Vanilla JavaScript.
var plans = document.getElementById("followersPlans");
var selectedPlan = document.getElementById("selected-plan");
plans.addEventListener('change', setLikes);
function setLikes()
var value = plans.querySelector('option:checked').dataset.like;
selectedPlan.innerHTML = "Gain " + value + " Likes";
setLikes();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
<option data-like="100" value="60.00">100 .....$60.00</option>
<option data-like="200" value="100.00">200 .....$100.00</option>
<option data-like="300" value="140.00">300 .....$140.00</option>
<option data-like="500" value="220.00">500 .....$220.00</option>
<option data-like="1000" value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li id="selected-plan">Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
Check out dataset: developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
– Xatenev
Nov 12 at 11:35
Awesome @Xatenev. Updated the code. Thanks!!
– Pablo Darde
Nov 12 at 16:28
add a comment |
up vote
2
down vote
As you want to store your $
amount on the value
attributes of the options items, you might want to use data-attributes
to store the like numbers.
Here is how to do it with jQuery
:
$(document).ready(function()
$('#followersPlans').on('change', function()
// console.log($(this).find('option:selected').data('likes'));
var likes = $(this).find('option:selected').data('likes');
$('.updateLikes').html('Gain ' + likes + ' Likes');
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col">
<!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00" data-likes="15">15 .......$10.00</option>
<option value="15.00" data-likes="30">30 .......$15.00</option>
<option value="30.00" data-likes="50">50 .......$30.00</option>
<option value="60.00" data-likes="100">100 .....$60.00</option>
<option value="100.00" data-likes="200">200 .....$100.00</option>
<option value="140.00" data-likes="300">300 .....$140.00</option>
<option value="220.00" data-likes="500">500 .....$220.00</option>
<option value="420.00" data-likes="1000">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li class='updateLikes'>Gain 20 Likes</li>
</ul>
</div>
</div>
</div>
<!-- t#4-ends -->
add a comment |
up vote
2
down vote
You could work with data attributes in your options and set a second value with that data you need for example:
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
</select>
</div>
With jQuery you can access that values with the .data()
function something like this:
$(document).ready(function()
$("#followersPlans").change(function()
var yourData = $("#followersPlans option:selected").data('like');
# Alternative
# var likes = $(this).find('option:selected').data('likes');
console.log(yourData);
);
);
thanks so much!
– Jamdev
Nov 10 at 17:04
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Here is a simple solution with Vanilla JavaScript.
var plans = document.getElementById("followersPlans");
var selectedPlan = document.getElementById("selected-plan");
plans.addEventListener('change', setLikes);
function setLikes()
var value = plans.querySelector('option:checked').dataset.like;
selectedPlan.innerHTML = "Gain " + value + " Likes";
setLikes();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
<option data-like="100" value="60.00">100 .....$60.00</option>
<option data-like="200" value="100.00">200 .....$100.00</option>
<option data-like="300" value="140.00">300 .....$140.00</option>
<option data-like="500" value="220.00">500 .....$220.00</option>
<option data-like="1000" value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li id="selected-plan">Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
Check out dataset: developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
– Xatenev
Nov 12 at 11:35
Awesome @Xatenev. Updated the code. Thanks!!
– Pablo Darde
Nov 12 at 16:28
add a comment |
up vote
1
down vote
accepted
Here is a simple solution with Vanilla JavaScript.
var plans = document.getElementById("followersPlans");
var selectedPlan = document.getElementById("selected-plan");
plans.addEventListener('change', setLikes);
function setLikes()
var value = plans.querySelector('option:checked').dataset.like;
selectedPlan.innerHTML = "Gain " + value + " Likes";
setLikes();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
<option data-like="100" value="60.00">100 .....$60.00</option>
<option data-like="200" value="100.00">200 .....$100.00</option>
<option data-like="300" value="140.00">300 .....$140.00</option>
<option data-like="500" value="220.00">500 .....$220.00</option>
<option data-like="1000" value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li id="selected-plan">Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
Check out dataset: developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
– Xatenev
Nov 12 at 11:35
Awesome @Xatenev. Updated the code. Thanks!!
– Pablo Darde
Nov 12 at 16:28
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Here is a simple solution with Vanilla JavaScript.
var plans = document.getElementById("followersPlans");
var selectedPlan = document.getElementById("selected-plan");
plans.addEventListener('change', setLikes);
function setLikes()
var value = plans.querySelector('option:checked').dataset.like;
selectedPlan.innerHTML = "Gain " + value + " Likes";
setLikes();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
<option data-like="100" value="60.00">100 .....$60.00</option>
<option data-like="200" value="100.00">200 .....$100.00</option>
<option data-like="300" value="140.00">300 .....$140.00</option>
<option data-like="500" value="220.00">500 .....$220.00</option>
<option data-like="1000" value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li id="selected-plan">Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
Here is a simple solution with Vanilla JavaScript.
var plans = document.getElementById("followersPlans");
var selectedPlan = document.getElementById("selected-plan");
plans.addEventListener('change', setLikes);
function setLikes()
var value = plans.querySelector('option:checked').dataset.like;
selectedPlan.innerHTML = "Gain " + value + " Likes";
setLikes();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
<option data-like="100" value="60.00">100 .....$60.00</option>
<option data-like="200" value="100.00">200 .....$100.00</option>
<option data-like="300" value="140.00">300 .....$140.00</option>
<option data-like="500" value="220.00">500 .....$220.00</option>
<option data-like="1000" value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li id="selected-plan">Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
var plans = document.getElementById("followersPlans");
var selectedPlan = document.getElementById("selected-plan");
plans.addEventListener('change', setLikes);
function setLikes()
var value = plans.querySelector('option:checked').dataset.like;
selectedPlan.innerHTML = "Gain " + value + " Likes";
setLikes();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
<option data-like="100" value="60.00">100 .....$60.00</option>
<option data-like="200" value="100.00">200 .....$100.00</option>
<option data-like="300" value="140.00">300 .....$140.00</option>
<option data-like="500" value="220.00">500 .....$220.00</option>
<option data-like="1000" value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li id="selected-plan">Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
var plans = document.getElementById("followersPlans");
var selectedPlan = document.getElementById("selected-plan");
plans.addEventListener('change', setLikes);
function setLikes()
var value = plans.querySelector('option:checked').dataset.like;
selectedPlan.innerHTML = "Gain " + value + " Likes";
setLikes();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col"><!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
<option data-like="100" value="60.00">100 .....$60.00</option>
<option data-like="200" value="100.00">200 .....$100.00</option>
<option data-like="300" value="140.00">300 .....$140.00</option>
<option data-like="500" value="220.00">500 .....$220.00</option>
<option data-like="1000" value="420.00">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li id="selected-plan">Gain 20 Likes</li>
</ul>
</div>
</div>
</div><!-- t#4-ends -->
edited Nov 12 at 16:27
answered Nov 10 at 16:39
Pablo Darde
1,37311427
1,37311427
Check out dataset: developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
– Xatenev
Nov 12 at 11:35
Awesome @Xatenev. Updated the code. Thanks!!
– Pablo Darde
Nov 12 at 16:28
add a comment |
Check out dataset: developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
– Xatenev
Nov 12 at 11:35
Awesome @Xatenev. Updated the code. Thanks!!
– Pablo Darde
Nov 12 at 16:28
Check out dataset: developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
– Xatenev
Nov 12 at 11:35
Check out dataset: developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
– Xatenev
Nov 12 at 11:35
Awesome @Xatenev. Updated the code. Thanks!!
– Pablo Darde
Nov 12 at 16:28
Awesome @Xatenev. Updated the code. Thanks!!
– Pablo Darde
Nov 12 at 16:28
add a comment |
up vote
2
down vote
As you want to store your $
amount on the value
attributes of the options items, you might want to use data-attributes
to store the like numbers.
Here is how to do it with jQuery
:
$(document).ready(function()
$('#followersPlans').on('change', function()
// console.log($(this).find('option:selected').data('likes'));
var likes = $(this).find('option:selected').data('likes');
$('.updateLikes').html('Gain ' + likes + ' Likes');
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col">
<!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00" data-likes="15">15 .......$10.00</option>
<option value="15.00" data-likes="30">30 .......$15.00</option>
<option value="30.00" data-likes="50">50 .......$30.00</option>
<option value="60.00" data-likes="100">100 .....$60.00</option>
<option value="100.00" data-likes="200">200 .....$100.00</option>
<option value="140.00" data-likes="300">300 .....$140.00</option>
<option value="220.00" data-likes="500">500 .....$220.00</option>
<option value="420.00" data-likes="1000">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li class='updateLikes'>Gain 20 Likes</li>
</ul>
</div>
</div>
</div>
<!-- t#4-ends -->
add a comment |
up vote
2
down vote
As you want to store your $
amount on the value
attributes of the options items, you might want to use data-attributes
to store the like numbers.
Here is how to do it with jQuery
:
$(document).ready(function()
$('#followersPlans').on('change', function()
// console.log($(this).find('option:selected').data('likes'));
var likes = $(this).find('option:selected').data('likes');
$('.updateLikes').html('Gain ' + likes + ' Likes');
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col">
<!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00" data-likes="15">15 .......$10.00</option>
<option value="15.00" data-likes="30">30 .......$15.00</option>
<option value="30.00" data-likes="50">50 .......$30.00</option>
<option value="60.00" data-likes="100">100 .....$60.00</option>
<option value="100.00" data-likes="200">200 .....$100.00</option>
<option value="140.00" data-likes="300">300 .....$140.00</option>
<option value="220.00" data-likes="500">500 .....$220.00</option>
<option value="420.00" data-likes="1000">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li class='updateLikes'>Gain 20 Likes</li>
</ul>
</div>
</div>
</div>
<!-- t#4-ends -->
add a comment |
up vote
2
down vote
up vote
2
down vote
As you want to store your $
amount on the value
attributes of the options items, you might want to use data-attributes
to store the like numbers.
Here is how to do it with jQuery
:
$(document).ready(function()
$('#followersPlans').on('change', function()
// console.log($(this).find('option:selected').data('likes'));
var likes = $(this).find('option:selected').data('likes');
$('.updateLikes').html('Gain ' + likes + ' Likes');
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col">
<!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00" data-likes="15">15 .......$10.00</option>
<option value="15.00" data-likes="30">30 .......$15.00</option>
<option value="30.00" data-likes="50">50 .......$30.00</option>
<option value="60.00" data-likes="100">100 .....$60.00</option>
<option value="100.00" data-likes="200">200 .....$100.00</option>
<option value="140.00" data-likes="300">300 .....$140.00</option>
<option value="220.00" data-likes="500">500 .....$220.00</option>
<option value="420.00" data-likes="1000">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li class='updateLikes'>Gain 20 Likes</li>
</ul>
</div>
</div>
</div>
<!-- t#4-ends -->
As you want to store your $
amount on the value
attributes of the options items, you might want to use data-attributes
to store the like numbers.
Here is how to do it with jQuery
:
$(document).ready(function()
$('#followersPlans').on('change', function()
// console.log($(this).find('option:selected').data('likes'));
var likes = $(this).find('option:selected').data('likes');
$('.updateLikes').html('Gain ' + likes + ' Likes');
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col">
<!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00" data-likes="15">15 .......$10.00</option>
<option value="15.00" data-likes="30">30 .......$15.00</option>
<option value="30.00" data-likes="50">50 .......$30.00</option>
<option value="60.00" data-likes="100">100 .....$60.00</option>
<option value="100.00" data-likes="200">200 .....$100.00</option>
<option value="140.00" data-likes="300">300 .....$140.00</option>
<option value="220.00" data-likes="500">500 .....$220.00</option>
<option value="420.00" data-likes="1000">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li class='updateLikes'>Gain 20 Likes</li>
</ul>
</div>
</div>
</div>
<!-- t#4-ends -->
$(document).ready(function()
$('#followersPlans').on('change', function()
// console.log($(this).find('option:selected').data('likes'));
var likes = $(this).find('option:selected').data('likes');
$('.updateLikes').html('Gain ' + likes + ' Likes');
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col">
<!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00" data-likes="15">15 .......$10.00</option>
<option value="15.00" data-likes="30">30 .......$15.00</option>
<option value="30.00" data-likes="50">50 .......$30.00</option>
<option value="60.00" data-likes="100">100 .....$60.00</option>
<option value="100.00" data-likes="200">200 .....$100.00</option>
<option value="140.00" data-likes="300">300 .....$140.00</option>
<option value="220.00" data-likes="500">500 .....$220.00</option>
<option value="420.00" data-likes="1000">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li class='updateLikes'>Gain 20 Likes</li>
</ul>
</div>
</div>
</div>
<!-- t#4-ends -->
$(document).ready(function()
$('#followersPlans').on('change', function()
// console.log($(this).find('option:selected').data('likes'));
var likes = $(this).find('option:selected').data('likes');
$('.updateLikes').html('Gain ' + likes + ' Likes');
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12 col-md-6 compare-col">
<!-- t#4-starts -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plan</h3>
</div>
<div class="panel-body">
<div class="the-price">
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option value="10.00" data-likes="15">15 .......$10.00</option>
<option value="15.00" data-likes="30">30 .......$15.00</option>
<option value="30.00" data-likes="50">50 .......$30.00</option>
<option value="60.00" data-likes="100">100 .....$60.00</option>
<option value="100.00" data-likes="200">200 .....$100.00</option>
<option value="140.00" data-likes="300">300 .....$140.00</option>
<option value="220.00" data-likes="500">500 .....$220.00</option>
<option value="420.00" data-likes="1000">1000 ...$420.00</option>
</select>
</div>
<p class="mini">Monthly Subscription</p>
<a href="#" class="btn btn-block btn-success" role="button">Activate</a>
</div>
<ul class="pricing__list">
<li>No Survey Required</li>
<li class='updateLikes'>Gain 20 Likes</li>
</ul>
</div>
</div>
</div>
<!-- t#4-ends -->
answered Nov 10 at 16:42
Towkir Ahmed
857619
857619
add a comment |
add a comment |
up vote
2
down vote
You could work with data attributes in your options and set a second value with that data you need for example:
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
</select>
</div>
With jQuery you can access that values with the .data()
function something like this:
$(document).ready(function()
$("#followersPlans").change(function()
var yourData = $("#followersPlans option:selected").data('like');
# Alternative
# var likes = $(this).find('option:selected').data('likes');
console.log(yourData);
);
);
thanks so much!
– Jamdev
Nov 10 at 17:04
add a comment |
up vote
2
down vote
You could work with data attributes in your options and set a second value with that data you need for example:
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
</select>
</div>
With jQuery you can access that values with the .data()
function something like this:
$(document).ready(function()
$("#followersPlans").change(function()
var yourData = $("#followersPlans option:selected").data('like');
# Alternative
# var likes = $(this).find('option:selected').data('likes');
console.log(yourData);
);
);
thanks so much!
– Jamdev
Nov 10 at 17:04
add a comment |
up vote
2
down vote
up vote
2
down vote
You could work with data attributes in your options and set a second value with that data you need for example:
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
</select>
</div>
With jQuery you can access that values with the .data()
function something like this:
$(document).ready(function()
$("#followersPlans").change(function()
var yourData = $("#followersPlans option:selected").data('like');
# Alternative
# var likes = $(this).find('option:selected').data('likes');
console.log(yourData);
);
);
You could work with data attributes in your options and set a second value with that data you need for example:
<div class="form-group" style="margin-bottom:13px;">
<select class="form-control" id="followersPlans" name="followersPlans">
<option data-like="15" value="10.00">15 .......$10.00</option>
<option data-like="30" value="15.00">30 .......$15.00</option>
<option data-like="50" value="30.00">50 .......$30.00</option>
</select>
</div>
With jQuery you can access that values with the .data()
function something like this:
$(document).ready(function()
$("#followersPlans").change(function()
var yourData = $("#followersPlans option:selected").data('like');
# Alternative
# var likes = $(this).find('option:selected').data('likes');
console.log(yourData);
);
);
edited Nov 10 at 17:05
answered Nov 10 at 16:39
Stony
19.6k135064
19.6k135064
thanks so much!
– Jamdev
Nov 10 at 17:04
add a comment |
thanks so much!
– Jamdev
Nov 10 at 17:04
thanks so much!
– Jamdev
Nov 10 at 17:04
thanks so much!
– Jamdev
Nov 10 at 17:04
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240959%2fchange-the-data-when-the-option-is-selected%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown