I’m trying to use the following code (https://codepen.io/enogrob/pen/OwjrGy) in my form and running into an issue with the $_POST() not pulling the name”” tag, it references the value”” tag which in this case isn’t helpful.
The 1st SELECT:
JavaScript
x
6
1
<select id="canvasSelect" name="canvasSelect" class="btn btn-outline-secondary dropdown-toggle form-control" data-toggle="dropdown">
2
<option>choose</option>
3
<option value="1">Canvas 1</option>
4
<option value="2">Canvas 2</option>
5
</select>
6
The select code looks like this:
JavaScript
1
9
1
<select id="colorSelect" name="colorSelect" class="btn btn-outline-secondary dropdown-toggle form-control" data-toggle="dropdown">
2
<option>choose</option>
3
<option name="6" value="1">WHITE</option>
4
<option name="7" value="1">BLUE</option>
5
<option name="8" value="1">GOLD</option>
6
<option name="9" value="2">BLUE</option>
7
<option name="10" value="2">GOLD</option>
8
</select>
9
and the java script implementation like this:
JavaScript
1
12
12
1
<script type="text/javascript">
2
var $select1 = $( '#canvasSelect' ),
3
$select2 = $( '#colorSelect' ),
4
$options = $select2.find( 'option' );
5
6
$select1.on( 'change', function() {
7
$select2.html( $options.filter( '[value="' + this.value + '"]' ) );
8
$('#colorSelect').val(''); //add this line for blank selection
9
} ).trigger( 'change' );
10
11
</script>
12
Is there a way to fix this or is there a better way to drive a second select from another ??
Advertisement
Answer
I solved this problem by creating a custom attribute on the 2nd SELECT combined with a hidden input using the following:
JavaScript
1
9
1
<select id="colorSelect" name="colorSelect" class="btn btn-outline-secondary dropdown-toggle form-control" data-toggle="dropdown">
2
<option>choose</option>
3
<option colorID="6" value="1">WHITE</option>
4
<option colorID="7" value="1">BLUE</option>
5
<option colorID="8" value="1">GOLD</option>
6
<option colorID="9" value="2">BLUE</option>
7
<option colorID="10" value="2">GOLD</option>
8
</select><input type="hidden" id="custAtt" name="colorID" />
9
and the script that goes with it:
JavaScript
1
9
1
<script>
2
$(function() {
3
$("#colorSelect").change(function(){
4
var option = $('option:selected', this).attr('colorID');
5
$('#custAtt').val(option);
6
});
7
});
8
</script>
9