John Davidson

php - Is there a way to make a second Input field?

0 comments
Message:


Is there a way to make a second Input field so that the 1st time value is in one input field and the second is in the other? I am trying to post the times to a database so I need then in separate fields.


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" />

<div class='amount-time-sch'>

<label for="amount-time">Time</label>
<input type="text" name="amount-time" id="amount-time" style="border: 0; color: #666666; font-weight: bold;" value="10:00 - 20:00"/>
<div id="slider-time"></div><br>
</div>

<script>jQuery(function() {
jQuery('#slider-time').slider({
range: true,
min: 0,
max: 1000,
step: 15,
values: [ 600, 1200 ],
slide: function( event, ui ) {
var hours1 = Math.floor(ui.values[0] / 60);
var minutes1 = ui.values[0] - (hours1 * 60);

if(hours1.length < 10) hours1= '0' + hours;
if(minutes1.length < 10) minutes1 = '0' + minutes;

if(minutes1 == 0) minutes1 = '00';

var hours2 = Math.floor(ui.values[1] / 60);
var minutes2 = ui.values[1] - (hours2 * 60);

if(hours2.length < 10) hours2= '0' + hours;
if(minutes2.length < 10) minutes2 = '0' + minutes;

if(minutes2 == 0) minutes2 = '00';

jQuery('#amount-time').val(hours1+':'+minutes1+''+hours2+':'+minutes2 );
}
});
});

</script>



My Answer:
Yes, you can create a second input field for the second time value by simply adding another input element in your HTML form. Here is an example code snippet:

html











In this form, there are two input fields named "time1" and "time2" where users can input their time values. When the form is submitted, the values entered in these input fields will be sent to the server-side script (process.php) for further processing.

In your PHP script (process.php), you can access these time values using the $_POST superglobal array:

php
$time1 = $_POST['time1'];
$time2 = $_POST['time2'];

// Now you can insert these values into your database using SQL queries


By following these steps, you can have two separate input fields for the time values and store them in separate fields in your database.

Rate this post

4 of 5 based on 2266 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us