I'm currently using Select2 for my dropdown. When I initiate the dropdown, it renders the original dropdown and the select2 dropdown. How can I fix this?
$('#itemSelect1').select2();
<select class="itemSelect1">
<option value="">Select an item</option>
<?php if (!empty($material)) {?>
<?php foreach ($material as $key => $value) { ?>
<option value="<?php echo $value['material_unique_key']; ?>" data-price="<?php echo $value['material_price']; ?>">
<?php echo $value['material_name'] ?>
</option>
<?php } ?>
<?php } ?>
</select>
I am a beginner to php and am designing student information system where students need to enter 9 subject and its corresponding grade based on the number of sittings. Is there any better way to do this apart from what I have been doing?
These are my codes.
<script type="text/javascript">
function showDiv(select){
if(select.value==2){
document.getElementById('div2a').style.display = "block";
} else{
document.getElementById('div2a').style.display = "none";
}
}
</script>
<style>
.striped-border {
border: 1px solid #0d4115;
margin: auto;
margin-top: 5%;
margin-bottom: 2%;
}
.form2a{
display: none;
}
</style>
<form name="register" method="POST" action="process2.php" >
<div class="col-md-12">
<div class="form-group">
<label>Select Number of Sitting(s)</label>
<select name="sitting" id="sitting" class="form-control" onchange="showDiv(this)">
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
</div>
<div class="output1" id="div1" name="onesitting">
<div class="col-md-6">
<div class="form-group">
<label>School Name</label>
<input type="text" name="schoolname1" id="schoolname" class="form-control" placeholder="School Name" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Exam Type</label>
<select name="examboard1" id="examboard" class="form-control" required>
<option value="">Exam Type</option>
<option value="WAEC">WAEC(SSCE)</option>
<option value="WAEC">WAEC(GCE)</option>
<option value="NECO">NECO(SSCE)</option>
<option value="NECO">NECO(GCE)</option>
<option value="NABTEB">NABTEB(SSCE)</option>
<option value="NABTEB">NABTEB(GCE)</option>
<option value="OTHERS">OTHERS</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Exam Date</label>
<?php
$examyear = range(1960, 2050);
?>
<select class="form-control" name="examdate1" id="examdate" placeholder="Exam Date">
<option value="">Select date</option>
<?php
foreach($examyear as $examdate){
echo '<option value= "' .$examdate.'">'.$examdate.'</option>';
}
?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Exam Number</label>
<input type="text" class="form-control" name="examno1" id="examno" placeholder="Exam Number">
</div>
</div>
<br>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="table table-borderless" id="example">
<tr>
<td width="12%"><label class="control-label">S/NO</label></td>
<td width="53%"><label class="control-label">SUBJECTS</label></td>
<td width="35%"><label class="control-label">GRADE</label></td>
</tr>
<tr>
<td>1</td>
<td>
<?php include("config.php");
$sql = "SELECT * FROM subjects ORDER BY subject_name ASC";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
?>
<select name="subject11" class="form-control" id="subject">
<option value="" selected="selected">Select subject</option>
<?php
if($count > 0){
while($row = mysqli_fetch_assoc($query)){
$subject_id = $row['subject_id'];
$subject_name = $row['subject_name'];
echo "<option>" . $row['subject_name'] . "</option>";
}
}else{
echo "<option value = ''>Subject not available</option>";
}
?>
</select>
</td>
<td>
<select name="grade11" class="form-control">
<option value=""> Select</option>
<option value="A1">A1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C4">C4</option>
<option value="C5">C5</option>
<option value="C6">C6</option>
<option value="D7">D7</option>
<option value="E8">E8</option>
<option value="F9">F9</option> </select>
</td>
</tr>
<tr>
<td>2</td>
<td>
<?php include("config.php");
$sql = "SELECT * FROM subjects ORDER BY subject_name ASC";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
?>
<select name="subject12" class="form-control" id="subject">
<option value="" selected="selected">Select subject</option>
<?php
if($count > 0){
while($row = mysqli_fetch_assoc($query)){
$subject_id = $row['subject_id'];
$subject_name = $row['subject_name'];
echo "<option>" . $row['subject_name'] . "</option>";
}
}else{
echo "<option value = ''>Subject not available</option>";
}
?>
</select>
</td>
<td>
<select name="grade12" class="form-control">
<option value=""> Select </option>
<option value="A1">A1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C4">C4</option>
<option value="C5">C5</option>
<option value="C6">C6</option>
<option value="D7">D7</option>
<option value="E8">E8</option>
<option value="F9">F9</option> </select>
</td>
</tr>
<tr>
<td>3</td>
<td>
<?php include("config.php");
$sql = "SELECT * FROM subjects ORDER BY subject_name ASC";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
?>
<select name="subject13" class="form-control" id="subject">
<option value="" selected="selected">Select subject</option>
<?php
if($count > 0){
while($row = mysqli_fetch_assoc($query)){
$subject_id = $row['subject_id'];
$subject_name = $row['subject_name'];
echo "<option>" . $row['subject_name'] . "</option>";
}
}else{
echo "<option value = ''>Subject not available</option>";
}
?>
</select>
</td>
<td>
<select name="grade13" class="form-control">
<option value=""> Select </option>
<option value="A1">A1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C4">C4</option>
<option value="C5">C5</option>
<option value="C6">C6</option>
<option value="D7">D7</option>
<option value="E8">E8</option>
<option value="F9">F9</option> </select>
</td>
</tr>
<tr>
<td>4</td>
<td>
<?php include("config.php");
$sql = "SELECT * FROM subjects ORDER BY subject_name ASC";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
?>
<select name="subject14" class="form-control" id="subject">
<option value="" selected="selected">Select subject</option>
<?php
if($count > 0){
while($row = mysqli_fetch_assoc($query)){
$subject_id = $row['subject_id'];
$subject_name = $row['subject_name'];
echo "<option>" . $row['subject_name'] . "</option>";
}
}else{
echo "<option value = ''>Subject not available</option>";
}
?>
</select>
</td>
<td>
<select name="grade14" class="form-control">
<option value=""> Select </option>
<option value="A1">A1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C4">C4</option>
<option value="C5">C5</option>
<option value="C6">C6</option>
<option value="D7">D7</option>
<option value="E8">E8</option>
<option value="F9">F9</option> </select>
</td>
</tr>
<tr>
<td>5</td>
<td>
<?php include("config.php");
$sql = "SELECT * FROM subjects ORDER BY subject_name ASC";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
?>
<select name="subject15" class="form-control" id="subject">
<option value="" selected="selected">Select subject</option>
<?php
if($count > 0){
while($row = mysqli_fetch_assoc($query)){
$subject_id = $row['subject_id'];
$subject_name = $row['subject_name'];
echo "<option>" . $row['subject_name'] . "</option>";
}
}else{
echo "<option value = ''>Subject not available</option>";
}
?>
</select>
</td>
<td>
<select name="grade15" class="form-control">
<option value="">Select </option>
<option value="A1">A1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C4">C4</option>
<option value="C5">C5</option>
<option value="C6">C6</option>
<option value="D7">D7</option>
<option value="E8">E8</option>
<option value="F9">F9</option> </select>
</td>
</tr>
</table>
<br>
</div>
<div class="form2a" id="div2a" name="twositting">
<br>
<h4 style="text-align:center; margin-top: 0px; margin-bottom: 5%; background-color:#0d4115; width: auto; color: white;"> SECOND SITTING</h4>
<div class="col-md-6">
<div class="form-group">
<label>School Name</label>
<input type="text" name="schoolname2" id="schoolname" class="form-control" placeholder="School Name" required>
<span id="error_schoolname" class="text-danger"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Exam Type</label>
<select name="examboard2" id="examboard" class="form-control" required>
<option value="">Exam Type</option>
<option value="WAEC">WAEC(SSCE)</option>
<option value="WAEC">WAEC(GCE)</option>
<option value="NECO">NECO(SSCE)</option>
<option value="NECO">NECO(GCE)</option>
<option value="NABTEB">NABTEB(SSCE)</option>
<option value="NABTEB">NABTEB(GCE)</option>
<option value="OTHERS">OTHERS</option>
<span id="error_examboard" class="text-danger"></span>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Exam Date</label>
<?php
$examyear = range(1960, 2099);
?>
<select class="form-control" name="examdate2" id="examdate" placeholder="Exam Date">
<option value="">Select date</option>
<?php
foreach($examyear as $examdate){
echo '<option value= "' .$examdate.'">'.$examdate.'</option>';
}
?>
<span id="error_examdate" class="text-danger"></span>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Exam Number</label>
<input type="text" class="form-control" name="examno2" id="examno" placeholder="Exam Number">
<span id="error_examno" class="text-danger"></span>
</div>
</div>
<br>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="table table-borderless" id="example">
<tr>
<td width="12%"><label class="control-label">S/NO</label></td>
<td width="53%"><label class="control-label">SUBJECTS</label></td>
<td width="35%"><label class="control-label">GRADE</label></td>
</tr>
<tr>
<td>1</td>
<td>
<?php include("config.php");
$sql = "SELECT * FROM subjects ORDER BY subject_name ASC";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
?>
<select name="subject21" class="form-control" id="subject">
<option value="" selected="selected">Select subject</option>
<?php
if($count > 0){
while($row = mysqli_fetch_assoc($query)){
$subject_id = $row['subject_id'];
$subject_name = $row['subject_name'];
echo "<option>" . $row['subject_name'] . "</option>";
}
}else{
echo "<option value = ''>Subject not available</option>";
}
?>
</select>
</td>
<td>
<select name="grade21" class="form-control">
<option value=""> Select</option>
<option value="A1">A1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C4">C4</option>
<option value="C5">C5</option>
<option value="C6">C6</option>
<option value="D7">D7</option>
<option value="E8">E8</option>
<option value="F9">F9</option> </select>
</td>
</tr>
<tr>
<td>2</td>
<td>
<?php include("config.php");
$sql = "SELECT * FROM subjects ORDER BY subject_name ASC";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
?>
<select name="subject22" class="form-control" id="subject">
<option value="" selected="selected">Select subject</option>
<?php
if($count > 0){
while($row = mysqli_fetch_assoc($query)){
$subject_id = $row['subject_id'];
$subject_name = $row['subject_name'];
echo "<option>" . $row['subject_name'] . "</option>";
}
}else{
echo "<option value = ''>Subject not available</option>";
}
?>
</select>
</td>
<td>
<select name="grade22" class="form-control">
<option value=""> Select </option>
<option value="A1">A1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C4">C4</option>
<option value="C5">C5</option>
<option value="C6">C6</option>
<option value="D7">D7</option>
<option value="E8">E8</option>
<option value="F9">F9</option> </select>
</td>
</tr>
<tr>
<td>3</td>
<td>
<?php include("config.php");
$sql = "SELECT * FROM subjects ORDER BY subject_name ASC";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
?>
<select name="subject23" class="form-control" id="subject">
<option value="" selected="selected">Select subject</option>
<?php
if($count > 0){
while($row = mysqli_fetch_assoc($query)){
$subject_id = $row['subject_id'];
$subject_name = $row['subject_name'];
echo "<option>" . $row['subject_name'] . "</option>";
}
}else{
echo "<option value = ''>Subject not available</option>";
}
?>
</select>
</td>
<td>
<select name="grade23" class="form-control">
<option value=""> Select </option>
<option value="A1">A1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C4">C4</option>
<option value="C5">C5</option>
<option value="C6">C6</option>
<option value="D7">D7</option>
<option value="E8">E8</option>
<option value="F9">F9</option> </select>
</td>
</tr>
<tr>
<td>4</td>
<td>
<?php include("config.php");
$sql = "SELECT * FROM subjects ORDER BY subject_name ASC";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
?>
<select name="subject24" class="form-control" id="subject">
<option value="" selected="selected">Select subject</option>
<?php
if($count > 0){
while($row = mysqli_fetch_assoc($query)){
$subject_id = $row['subject_id'];
$subject_name = $row['subject_name'];
echo "<option>" . $row['subject_name'] . "</option>";
}
}else{
echo "<option value = ''>Subject not available</option>";
}
?>
</select>
</td>
<td>
<select name="grade24" class="form-control">
<option value=""> Select </option>
<option value="A1">A1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C4">C4</option>
<option value="C5">C5</option>
<option value="C6">C6</option>
<option value="D7">D7</option>
<option value="E8">E8</option>
<option value="F9">F9</option> </select>
</td>
</tr>
<tr>
<td>5</td>
<td>
<?php include("config.php");
$sql = "SELECT * FROM subjects ORDER BY subject_name ASC";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
?>
<select name="subject25" class="form-control" id="subject">
<option value="" selected="selected">Select subject</option>
<?php
if($count > 0){
while($row = mysqli_fetch_assoc($query)){
$subject_id = $row['subject_id'];
$subject_name = $row['subject_name'];
echo "<option>" . $row['subject_name'] . "</option>";
}
}else{
echo "<option value = ''>Subject not available</option>";
}
?>
</select>
</td>
<td>
<select name="grade25" class="form-control">
<option value="">Select </option>
<option value="A1">A1</option>
<option value="B2">B2</option>
<option value="B3">B3</option>
<option value="C4">C4</option>
<option value="C5">C5</option>
<option value="C6">C6</option>
<option value="D7">D7</option>
<option value="E8">E8</option>
<option value="F9">F9</option> </select>
</td>
</tr>
</table>
</div>
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
</form>
The above is my HTML and JavaScript codes. Am using that JavaScript to display form based on the no of sittings selected.
Below is my PHP code
$sitting = mysqli_real_escape_string($conn, $_POST['sitting']);
$schoolname1 = mysqli_real_escape_string($conn, $_POST['schoolname1']);
$examboard1 = mysqli_real_escape_string($conn, $_POST['examboard1']);
$examdate1 = mysqli_real_escape_string($conn, $_POST['examdate1']);
$examno1 = mysqli_real_escape_string($conn, $_POST['examno1']);
$subject11 = mysqli_real_escape_string($conn, $_POST['subject11']);
$grade11 = mysqli_real_escape_string($conn, $_POST['grade11']);
$subject12 = mysqli_real_escape_string($conn, $_POST['subject12']);
$grade12 = mysqli_real_escape_string($conn, $_POST['grade12']);
$subject13 = mysqli_real_escape_string($conn, $_POST['subject13']);
$grade13 = mysqli_real_escape_string($conn, $_POST['grade13']);
$subject14 = mysqli_real_escape_string($conn, $_POST['subject14']);
$grade14 = mysqli_real_escape_string($conn, $_POST['grade14']);
$subject15 = mysqli_real_escape_string($conn, $_POST['subject15']);
$grade15 = mysqli_real_escape_string($conn, $_POST['grade15']);
$schoolname2 = mysqli_real_escape_string($conn, $_POST['schoolname2']);
$examboard2 = mysqli_real_escape_string($conn, $_POST['examboard2']);
$examdate2 = mysqli_real_escape_string($conn, $_POST['examdate2']);
$examno2 = mysqli_real_escape_string($conn, $_POST['examno2']);
$subject21 = mysqli_real_escape_string($conn, $_POST['subject21']);
$grade21 = mysqli_real_escape_string($conn, $_POST['grade21']);
$subject22 = mysqli_real_escape_string($conn, $_POST['subject22']);
$grade22 = mysqli_real_escape_string($conn, $_POST['grade22']);
$subject23 = mysqli_real_escape_string($conn, $_POST['subject23']);
$grade23 = mysqli_real_escape_string($conn, $_POST['grade23']);
$subject24 = mysqli_real_escape_string($conn, $_POST['subject24']);
$grade24 = mysqli_real_escape_string($conn, $_POST['grade24']);
$subject25 = mysqli_real_escape_string($conn, $_POST['subject25']);
$grade25 = mysqli_real_escape_string($conn, $_POST['grade25']);
$enter = "INSERT INTO applicants(sitting, schoolname1, examboard1,
examdate1, examno1, subject11, grade11, subject12, grade12, subject13,
grade13, subject14, grade14, subject15, grade15, schoolname2, examboard2,
examdate2, examno2, subject21, grade21, subject22, grade22, subject23,
grade23, subject24, grade24, subject25, grade25) VALUES('$sitting',
'$schoolname1', '$examboard1', '$examdate1', '$examno1', '$subject11',
'$grade11', '$subject12', '$grade12', '$subject13', '$grade13',
'$subject14', '$grade14', '$subject15', '$grade15','$schoolname2',
'$examboard2', '$examdate2', '$examno2', '$subject21', '$grade21',
'$subject22', '$grade22', '$subject23', '$grade23', '$subject24',
'$grade24', '$subject25', '$grade25')";
$result = mysqli_query($conn, $enter);
if($result){
echo "<script type='text/javascript'>alert('Details Uploaded !!');
</script>";
header('location: success.php');
}else{
echo "<script type='text/javascript'>alert('Details Failed !!');</script>";
}
}
Is there any better way to do this without repeating all those subjects and grades?
You're getting into a pickle with your form names. PHP makes this a little bit easier by allowing you to specify array names in forms:
<?php
if ($_POST)
{
echo "<pre>";
print_r($_POST);
echo "</pre>";
}
?>
<form method="post">
Grades:
<input name="grade[]" type="text">
<input name="grade[]" type="text">
<input name="grade[]" type="text">
<hr>
<input type="submit" value="Submit">
</form>
This produces this post output, which is easy to loop over:
Array
(
[grade] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
)
That works for lists of data, but your use-case has an additional dimension, which makes this harder. You have:
a first-order list containing school name, exam board, exam date, and exam number
a second-order list belonging to the first one, which contains subjects and grades
However, PHP will support that too, by letting you specify which sub-list the second-order lists belong to:
<?php
if ($_POST)
{
echo "<pre>";
print_r($_POST);
echo "</pre>";
}
?>
<form method="post">
Board: <input name="board[]" type="text">
Grades:
<input name="grade[0][]" type="text">
<input name="grade[0][]" type="text">
<input name="grade[0][]" type="text">
<hr>
Board: <input name="board[]" type="text">
Grades:
<input name="grade[1][]" type="text">
<input name="grade[1][]" type="text">
<input name="grade[1][]" type="text">
<hr>
<input type="submit" value="Submit">
</form>
This produces this arrangement:
Array
(
[board] => Array
(
[0] => a
[1] => b
)
[grade] => Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[1] => Array
(
[0] => 4
[1] => 5
[2] => 6
)
)
)
You can see here that the 0th entry in board is the exam board (first order list) and the 0th entry in grade is a list in itself (second order list pertaining to the 0th board).
I will leave it to you as a valuable exercise to add the other elements to the first and second-order lists here.
In relation to the table, that is a broad enough topic to merit another question on its own. The structure of this needs to be normalised, so you hold exam boards, exams, students and grades in separate tables. The "grade" is probably the central table, since that requires an exam and a student, and the exam in turn requires a board.
I searched a lot about this topic and found difficult approaches mostly not working. I have 2 Select boxes (class & student) which should be dynamically generated. After selecting the Class, the 2nd Select Box should show the Option Values from the Students Table.
<form action="" class="form-horizontal" method="POST">
<h4>Issue Book: </h4><hr>
<label class="control-label" for="class">Class</label>
<select id="class" name="class" class="form-control">
<option value="">Select Class</option>
<?php
$class_query = "SELECT * FROM `classes` ";
$class_result = mysql_query($class_query);
do{
$class_row = mysql_fetch_array($class_result);
if($class_row){
$class_id = $class_row['id'];
$class_name = $class_row['class'];
?>
<option value="<?php echo $class_id; ?>"><?php echo $class_name; ?></option>
<?php
}
}while($class_row);
?>
</select>
<label class="control-label" for="student">Student</label>
<select id="student" name="student" class="form-control">
<option value="">Select Student</option>
</select>
<!-- Submit -->
<button type="submit" name="issue_book">Issue Book</button>
</form>
Kindly help with this, I have no knowledge of JS or JQuery. I shall be very thankful.
first this is your html code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<form action="" class="form-horizontal" method="POST">
<h4>Issue Book: </h4>
<hr>
<label class="control-label" for="class">Class</label>
<select id="class" name="class" class="form-control" onchange="getStudentOption(this)">
<option value="">Select Class</option>
<option value="class1">Class 1</option>
<option value="class2">Class 2</option>
<option value="class3">Class 3</option>
<option value="class4">Class 4</option>
</select>
<label class="control-label" for="student">Student</label>
<select id="student" name="student" class="form-control">
<option value="">Select Student</option>
</select>
<!-- Submit -->
<button type="submit" name="issue_book">Issue Book</button>
</form>
added a onchange function
<script>
function getStudentOption(input) {
var class_name = input.value;
$.ajax({
type: "GET",
data: 'class=' + class_name,
url: 'demo.php',
dataType: 'text',
success: function (text) {
$('#student').html(text);
},
});
}
</script>
here demo is the file name which file give you all student data so you can change this file name and path also
and this is your demo file content
<?php
if (isset($_GET) && ($_GET['class'] != '')) {
/*$class_value = $_GET['class'];
$query = "SELECT * FROM students WHERE class_name=" . $class_value;
$result = mysql_query($query);
$total_refs = mysql_num_rows($result);
if ($total_refs > 0) {
?>
<option value="">Select Student</option>
<?php
while ($line = mysql_fetch_array($result)) {
$student_name = $line['student_name'];
$student_id = $line['student_id'];
?>
<option
value="<?php echo $student_id; ?>"><?php echo $student_name; ?></option>
<?php
}
?>
<?php
} else { ?>
<option value="">Select Student</option>
<?php
}*/?>
<option value="">Select Student</option>
<option value="1">Student 1</option>
<option value="2">Student 2</option>
<option value="3">Student 3</option>
<?php }
?>
i have added some demo content you can update data which code i have added, i am not sure which your table structure so just update condition value and filed value
Drop down, when item of dropdown is selected I need it to go to download page based on the advanced custom fields value.
Code:
<select name="download" onChange="download(this.value)">
<option value="0">Select template to download</option>
<option value="<?php the_field('download_template_1_link', 'option'); ?>"><?php the_field('download_template_1_title', 'option'); ?></option>
<option value="<?php the_field('download_template_2_link', 'option'); ?>"><?php the_field('download_template_2_title', 'option'); ?></option>
<option value="<?php the_field('download_template_3_link', 'option'); ?>"><?php the_field('download_template_3_title', 'option'); ?></option>
<option value="<?php the_field('download_template_4_link', 'option'); ?>"><?php the_field('download_template_4_title', 'option'); ?></option>
<option value="<?php the_field('download_template_5_link', 'option'); ?>"><?php the_field('download_template_5_title', 'option'); ?></option>
<script>
function download(val) {
window.location
}
</script>
</select>
use window.location.href to go to download page.
<script>
function download(val) {
window.location.href = val;
}
</script>
function download(url) {
if (url.length !== 0) {
window.location.href = url;
}
}
<select onChange="download(this.value)">
<option value="">-- Select --</option>
<option value="http://apple.com">Apple</option>
<option value="http://bing.com">Bing</option>
</select>
The code to populate combo box from database
<td>Item Name:</td>
<td><select name="items">
<option value="0" selected="selected"> Choose</option>
<?php
while($row = mysql_fetch_assoc($query))
{
$category = $row["ItemName"];
echo "$category";
?>
<option value= <?php $category ?> > <?php echo $category ?> </option>
<?php
}?>
</select></td>
Code for submit
<td><input type="submit" name="newItem" value="New Item"/></td>
PHP code is:
<?php
if(isset($_POST['newItem']))
{
$item=$_POST['items'];
$sel=mysql_query("select ItemID from itemmaster where ItemName='$item'");
while($row2 = mysql_fetch_array($sel))
{
//code
}
Value should be inside quotes
change:
<option value= <?php $category ?> > <?php echo $category ?> </option>
to
<option value= "<?php $category ?> "> <?php echo $category ?> </option>