displaying different form options based on the combination of previous input values
up vote
0
down vote
favorite
I´m building a website which is meant to be a store for selling eyeglasses.
Users would have to select from two selection type inputs their prescription value for each eye, in order to be able to choose the right lens for them.
I´m trying to find out how to use Jquery/Javascript to compare both eyes values since further options need to be displayed based on the highest one.
This is what I have so far. Each input it´s working independently from the other and i don´t know how to solve that.
$(function () {
$("#selection_1, #selection_2").change(function() {
var val = $(this).val();
if(val >="00.00" && val <="01.00" || val <="-01.00" && val >="-00.25" ) {
$("#product_b").hide();
}
else {
$("#product_b").show()
};
if(val >="01.25" && val <="02.00" || val <="-02.00" && val >="-01.25" ) {
$("#product_a").hide();
}
else {
$("#product_a").show();
};
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default"disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00"selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
This is what I need to accomplish:
if #selection_1 or #selection_2 is between 1.00 and -1.00, #product_a should be displayed.
if #selection_1 or #selection_2 is between 1.00 and 2.00, and between -1.00 and -2.00, #product_b should be displayed.
Here is an example of how they should work together:
if selection_1 is between 1.00 and 2.00, and selection_2 is between 1.00 and -1.00, #product_b should be displayed. The highest should be the one
to take into consideration.
I hope someone can help me out! thanks
javascript jquery html
add a comment |
up vote
0
down vote
favorite
I´m building a website which is meant to be a store for selling eyeglasses.
Users would have to select from two selection type inputs their prescription value for each eye, in order to be able to choose the right lens for them.
I´m trying to find out how to use Jquery/Javascript to compare both eyes values since further options need to be displayed based on the highest one.
This is what I have so far. Each input it´s working independently from the other and i don´t know how to solve that.
$(function () {
$("#selection_1, #selection_2").change(function() {
var val = $(this).val();
if(val >="00.00" && val <="01.00" || val <="-01.00" && val >="-00.25" ) {
$("#product_b").hide();
}
else {
$("#product_b").show()
};
if(val >="01.25" && val <="02.00" || val <="-02.00" && val >="-01.25" ) {
$("#product_a").hide();
}
else {
$("#product_a").show();
};
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default"disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00"selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
This is what I need to accomplish:
if #selection_1 or #selection_2 is between 1.00 and -1.00, #product_a should be displayed.
if #selection_1 or #selection_2 is between 1.00 and 2.00, and between -1.00 and -2.00, #product_b should be displayed.
Here is an example of how they should work together:
if selection_1 is between 1.00 and 2.00, and selection_2 is between 1.00 and -1.00, #product_b should be displayed. The highest should be the one
to take into consideration.
I hope someone can help me out! thanks
javascript jquery html
1
Good start! Instead of getting just val on change, you can grab both:var val1 = $('#selection_1').val(); var val2 = $('#selection_2').val();
from there, you would need to figure out which of the two values to pass into your if statements below. Hope that hint helps!
– jacob.mccrumb
Nov 11 at 4:21
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I´m building a website which is meant to be a store for selling eyeglasses.
Users would have to select from two selection type inputs their prescription value for each eye, in order to be able to choose the right lens for them.
I´m trying to find out how to use Jquery/Javascript to compare both eyes values since further options need to be displayed based on the highest one.
This is what I have so far. Each input it´s working independently from the other and i don´t know how to solve that.
$(function () {
$("#selection_1, #selection_2").change(function() {
var val = $(this).val();
if(val >="00.00" && val <="01.00" || val <="-01.00" && val >="-00.25" ) {
$("#product_b").hide();
}
else {
$("#product_b").show()
};
if(val >="01.25" && val <="02.00" || val <="-02.00" && val >="-01.25" ) {
$("#product_a").hide();
}
else {
$("#product_a").show();
};
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default"disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00"selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
This is what I need to accomplish:
if #selection_1 or #selection_2 is between 1.00 and -1.00, #product_a should be displayed.
if #selection_1 or #selection_2 is between 1.00 and 2.00, and between -1.00 and -2.00, #product_b should be displayed.
Here is an example of how they should work together:
if selection_1 is between 1.00 and 2.00, and selection_2 is between 1.00 and -1.00, #product_b should be displayed. The highest should be the one
to take into consideration.
I hope someone can help me out! thanks
javascript jquery html
I´m building a website which is meant to be a store for selling eyeglasses.
Users would have to select from two selection type inputs their prescription value for each eye, in order to be able to choose the right lens for them.
I´m trying to find out how to use Jquery/Javascript to compare both eyes values since further options need to be displayed based on the highest one.
This is what I have so far. Each input it´s working independently from the other and i don´t know how to solve that.
$(function () {
$("#selection_1, #selection_2").change(function() {
var val = $(this).val();
if(val >="00.00" && val <="01.00" || val <="-01.00" && val >="-00.25" ) {
$("#product_b").hide();
}
else {
$("#product_b").show()
};
if(val >="01.25" && val <="02.00" || val <="-02.00" && val >="-01.25" ) {
$("#product_a").hide();
}
else {
$("#product_a").show();
};
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default"disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00"selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
This is what I need to accomplish:
if #selection_1 or #selection_2 is between 1.00 and -1.00, #product_a should be displayed.
if #selection_1 or #selection_2 is between 1.00 and 2.00, and between -1.00 and -2.00, #product_b should be displayed.
Here is an example of how they should work together:
if selection_1 is between 1.00 and 2.00, and selection_2 is between 1.00 and -1.00, #product_b should be displayed. The highest should be the one
to take into consideration.
I hope someone can help me out! thanks
$(function () {
$("#selection_1, #selection_2").change(function() {
var val = $(this).val();
if(val >="00.00" && val <="01.00" || val <="-01.00" && val >="-00.25" ) {
$("#product_b").hide();
}
else {
$("#product_b").show()
};
if(val >="01.25" && val <="02.00" || val <="-02.00" && val >="-01.25" ) {
$("#product_a").hide();
}
else {
$("#product_a").show();
};
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default"disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00"selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
$(function () {
$("#selection_1, #selection_2").change(function() {
var val = $(this).val();
if(val >="00.00" && val <="01.00" || val <="-01.00" && val >="-00.25" ) {
$("#product_b").hide();
}
else {
$("#product_b").show()
};
if(val >="01.25" && val <="02.00" || val <="-02.00" && val >="-01.25" ) {
$("#product_a").hide();
}
else {
$("#product_a").show();
};
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default"disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00"selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
javascript jquery html
javascript jquery html
edited Nov 11 at 7:55
Towkir Ahmed
910619
910619
asked Nov 11 at 2:58
javier
1
1
1
Good start! Instead of getting just val on change, you can grab both:var val1 = $('#selection_1').val(); var val2 = $('#selection_2').val();
from there, you would need to figure out which of the two values to pass into your if statements below. Hope that hint helps!
– jacob.mccrumb
Nov 11 at 4:21
add a comment |
1
Good start! Instead of getting just val on change, you can grab both:var val1 = $('#selection_1').val(); var val2 = $('#selection_2').val();
from there, you would need to figure out which of the two values to pass into your if statements below. Hope that hint helps!
– jacob.mccrumb
Nov 11 at 4:21
1
1
Good start! Instead of getting just val on change, you can grab both:
var val1 = $('#selection_1').val(); var val2 = $('#selection_2').val();
from there, you would need to figure out which of the two values to pass into your if statements below. Hope that hint helps!– jacob.mccrumb
Nov 11 at 4:21
Good start! Instead of getting just val on change, you can grab both:
var val1 = $('#selection_1').val(); var val2 = $('#selection_2').val();
from there, you would need to figure out which of the two values to pass into your if statements below. Hope that hint helps!– jacob.mccrumb
Nov 11 at 4:21
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
While comparing number values, you need to parse
your values to number type, in your case, you should parseFloat()
the values before calculation.
From your paragraph, your conditions seemed a little complicated to me, still I tried to implement as much as I understood. Hope this will help you to implement the rest of it according to your needs.
Here is the snippet.
$(function() {
$("#selection_1, #selection_2").change(function() {
var val1 = parseFloat($('#selection_1').val());
var val2 = parseFloat($('#selection_2').val());
if ((val1 => -1.0 && val1 <= 1.0) || (val2 >= -1.0 && val2 <= 1.0)) {
$('#product_a').show();
$('#product_b').hide();
}
if ((val1 >= 1.0 && val1 <= 2.0) || (val2 >= 1.0 && val2 <= 2.0) || (val1 >= -2.0 && val1 <= -1.0) || (val2 >= -2.0 && val2 <= -1.0)) {
$('#product_a').hide();
$('#product_b').show();
}
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
While comparing number values, you need to parse
your values to number type, in your case, you should parseFloat()
the values before calculation.
From your paragraph, your conditions seemed a little complicated to me, still I tried to implement as much as I understood. Hope this will help you to implement the rest of it according to your needs.
Here is the snippet.
$(function() {
$("#selection_1, #selection_2").change(function() {
var val1 = parseFloat($('#selection_1').val());
var val2 = parseFloat($('#selection_2').val());
if ((val1 => -1.0 && val1 <= 1.0) || (val2 >= -1.0 && val2 <= 1.0)) {
$('#product_a').show();
$('#product_b').hide();
}
if ((val1 >= 1.0 && val1 <= 2.0) || (val2 >= 1.0 && val2 <= 2.0) || (val1 >= -2.0 && val1 <= -1.0) || (val2 >= -2.0 && val2 <= -1.0)) {
$('#product_a').hide();
$('#product_b').show();
}
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
add a comment |
up vote
1
down vote
While comparing number values, you need to parse
your values to number type, in your case, you should parseFloat()
the values before calculation.
From your paragraph, your conditions seemed a little complicated to me, still I tried to implement as much as I understood. Hope this will help you to implement the rest of it according to your needs.
Here is the snippet.
$(function() {
$("#selection_1, #selection_2").change(function() {
var val1 = parseFloat($('#selection_1').val());
var val2 = parseFloat($('#selection_2').val());
if ((val1 => -1.0 && val1 <= 1.0) || (val2 >= -1.0 && val2 <= 1.0)) {
$('#product_a').show();
$('#product_b').hide();
}
if ((val1 >= 1.0 && val1 <= 2.0) || (val2 >= 1.0 && val2 <= 2.0) || (val1 >= -2.0 && val1 <= -1.0) || (val2 >= -2.0 && val2 <= -1.0)) {
$('#product_a').hide();
$('#product_b').show();
}
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
add a comment |
up vote
1
down vote
up vote
1
down vote
While comparing number values, you need to parse
your values to number type, in your case, you should parseFloat()
the values before calculation.
From your paragraph, your conditions seemed a little complicated to me, still I tried to implement as much as I understood. Hope this will help you to implement the rest of it according to your needs.
Here is the snippet.
$(function() {
$("#selection_1, #selection_2").change(function() {
var val1 = parseFloat($('#selection_1').val());
var val2 = parseFloat($('#selection_2').val());
if ((val1 => -1.0 && val1 <= 1.0) || (val2 >= -1.0 && val2 <= 1.0)) {
$('#product_a').show();
$('#product_b').hide();
}
if ((val1 >= 1.0 && val1 <= 2.0) || (val2 >= 1.0 && val2 <= 2.0) || (val1 >= -2.0 && val1 <= -1.0) || (val2 >= -2.0 && val2 <= -1.0)) {
$('#product_a').hide();
$('#product_b').show();
}
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
While comparing number values, you need to parse
your values to number type, in your case, you should parseFloat()
the values before calculation.
From your paragraph, your conditions seemed a little complicated to me, still I tried to implement as much as I understood. Hope this will help you to implement the rest of it according to your needs.
Here is the snippet.
$(function() {
$("#selection_1, #selection_2").change(function() {
var val1 = parseFloat($('#selection_1').val());
var val2 = parseFloat($('#selection_2').val());
if ((val1 => -1.0 && val1 <= 1.0) || (val2 >= -1.0 && val2 <= 1.0)) {
$('#product_a').show();
$('#product_b').hide();
}
if ((val1 >= 1.0 && val1 <= 2.0) || (val2 >= 1.0 && val2 <= 2.0) || (val1 >= -2.0 && val1 <= -1.0) || (val2 >= -2.0 && val2 <= -1.0)) {
$('#product_a').hide();
$('#product_b').show();
}
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
$(function() {
$("#selection_1, #selection_2").change(function() {
var val1 = parseFloat($('#selection_1').val());
var val2 = parseFloat($('#selection_2').val());
if ((val1 => -1.0 && val1 <= 1.0) || (val2 >= -1.0 && val2 <= 1.0)) {
$('#product_a').show();
$('#product_b').hide();
}
if ((val1 >= 1.0 && val1 <= 2.0) || (val2 >= 1.0 && val2 <= 2.0) || (val1 >= -2.0 && val1 <= -1.0) || (val2 >= -2.0 && val2 <= -1.0)) {
$('#product_a').hide();
$('#product_b').show();
}
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
$(function() {
$("#selection_1, #selection_2").change(function() {
var val1 = parseFloat($('#selection_1').val());
var val2 = parseFloat($('#selection_2').val());
if ((val1 => -1.0 && val1 <= 1.0) || (val2 >= -1.0 && val2 <= 1.0)) {
$('#product_a').show();
$('#product_b').hide();
}
if ((val1 >= 1.0 && val1 <= 2.0) || (val2 >= 1.0 && val2 <= 2.0) || (val1 >= -2.0 && val1 <= -1.0) || (val2 >= -2.0 && val2 <= -1.0)) {
$('#product_a').hide();
$('#product_b').show();
}
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container ">
<div class="form-group col-md-6">
<label class="control-label" for="selection_1">Selection 1</label>
<select class="my-form-control" id="selection_1" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
<div class="form-group col-md-6">
<label class="control-label" for="selection_2">Selection 2</label>
<select class="my-form-control" id="selection_2" name="right eye">
<option value="default" disabled>choose...</option>
<option value="-02.00">-02.00</option>
<option value="-01.75">-01.75</option>
<option value="-01.50">-01.50</option>
<option value="-01.25">-01.25</option>
<option value="-01.00">-01.00</option>
<option value="-00.75">-00.75</option>
<option value="-00.50">-00.50</option>
<option value="-00.25">-00.25</option>
<option value="00.00" selected>00.00</option>
<option value="00.25">00.25</option>
<option value="00.50">00.50</option>
<option value="00.75">00.75</option>
<option value="01.00">01.00</option>
<option value="01.25">01.25</option>
<option value="01.50">01.50</option>
<option value="01.75">01.75</option>
<option value="02.00">02.00</option>
</select>
</div>
</div>
<div class="container">
<div id="product_a" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1">
<label class="form-check-label" for="product_a">
Product A
</label>
</div>
<div id="product_b" class="form-check">
<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
<label class="form-check-label" for="product_b">
Product B
</label>
</div>
</div>
answered Nov 11 at 7:55
Towkir Ahmed
910619
910619
add a comment |
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%2f53245461%2fdisplaying-different-form-options-based-on-the-combination-of-previous-input-val%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
1
Good start! Instead of getting just val on change, you can grab both:
var val1 = $('#selection_1').val(); var val2 = $('#selection_2').val();
from there, you would need to figure out which of the two values to pass into your if statements below. Hope that hint helps!– jacob.mccrumb
Nov 11 at 4:21