I am a newbie and I have this project where the user should have the option of custom input if the listed options are not in dropdown.
HTML
JavaScript
x
11
11
1
<div class="form-group">
2
<label class="col-sm-2 col-form-label">Select Page Size</label>
3
<select name = 'pageSelector' class="col-sm-3">
4
<option value ="">Select Page Size</option>
5
<option value ="84.1|118.9">A0</option>
6
<option value = "59.4|84.1">A1</option>
7
<option value = "7.4|10.5">A7</option>
8
<option value = "custom">Select Custom</option>
9
</select>
10
</div>
11
PHP
JavaScript
1
29
29
1
if(isset($_POST["pageSelector"]))
2
{
3
$result = $_POST['pageSelector'];
4
if($result == "")
5
{
6
echo "<script>alert('Please select the Page')</script>";
7
}
8
9
$result_explode = explode('|', $result);
10
$width_page = $result_explode[0];
11
$height_page = $result_explode[1];
12
13
14
// Converting the string variables to integer
15
$width_plate=(double)$width_plate;
16
$height_plate=(double)$height_plate;
17
$width_page=(double)$width_page;
18
$height_page=(double)$height_page;
19
20
21
// To calculate the number of pages that can be print with one selected plate
22
$calculated_width = $width_plate/$width_page;
23
$calculated_height = $height_plate/$height_page;
24
$print_include = (int)$calculated_height*(int)$calculated_width;
25
26
echo "<div class='h1'>Number of Prints in one plate ".$print_include." prints</div> ";
27
28
}
29
I would like if the user selects the custom option then a input text should appear on the screen.
Advertisement
Answer
JavaScript
1
10
10
1
var pageSelector = document.getElementById('pageSelector');
2
var customInput = document.getElementById('customInput');
3
4
pageSelector.addEventListener('change', function(){
5
if(this.value == "custom") {
6
customInput.classList.remove('hide');
7
} else {
8
customInput.classList.add('hide');
9
}
10
})
JavaScript
1
5
1
.hide {
2
width: 0;
3
height: 0;
4
opacity: 0;
5
}
JavaScript
1
11
11
1
<div class="form-group">
2
<label class="col-sm-2 col-form-label">Select Page Size</label>
3
<select name = 'pageSelector' class="col-sm-3 page" id="pageSelector">
4
<option value ="">Select Page Size</option>
5
<option value ="84.1|118.9">A0</option>
6
<option value = "59.4|84.1">A1</option>
7
<option value = "7.4|10.5">A7</option>
8
<option value = "custom">Select Custom</option>
9
</select>
10
<input type="text" class="hide" placeholder="Custom Selector" name="custom" id="customInput">
11
</div>