Change the data when the option is selected
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 |
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 |
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.9k135164
19.9k135164
asked Nov 10 at 16:25
Jamdev
424214
424214
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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 |
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 |
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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,38711527
1,38711527
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 |
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 |
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 |
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
947619
947619
add a comment |
add a comment |
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 |
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 |
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.9k135164
19.9k135164
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 |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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