0

I have 2 input elements which I select start and end date using JavaScript:

<form name="form" method="POST" action="accesari.php">
<p>FROM:
<input type="text" id="min" name="min">
</p>
<p>TO:
<input type="text" id="max" name="max">
</p>
<input type="submit" name="submit"/>
</form>
 </head>
 <body>
 <script>
 $(document).ready(function() {
 $("#min").datepicker({
 dateFormat: 'd-mm-yy',
 onSelect: function(dateText, inst) {
 $("#min").text(dateText);
 }
 });
});
</script>
<script>
$(document).ready(function() {
 $("#max").datepicker({
 dateFormat: 'd-mm-yy',
 onSelect: function(dateText, inst) {
 $("#max").text(dateText);
 }
 });
});
 </script>

Then, in php I have another form which I use to select the client from a dropdown list filled with values from a SQL table:

echo ('<form action="accesari.php" method="post">');
$sql=mysqli_query($aBD->con,"SELECT DISTINCT DenClient FROM $tabel WHERE DenClient!='xxxx'");
if(mysqli_num_rows($sql)){
$select= '<select name="select">';
$select.= '<option> </option>';
while($rs=mysqli_fetch_array($sql)){
$select.='<option>'.$rs['DenClient'].'</option>';
 }
}
$select.='</select>';
echo $select;
echo ('<input type="submit" name="submit"/>
</form>');
if ( isset( $_POST['submit'] ) ) {
 ////is submitted
$client = $_POST['select'];
 // //DO STUFF WITH DATA
}

I would like to submit all of it at once. Is that possible? Thanks in advance,

pppp
2311 silver badge11 bronze badges
asked May 25, 2016 at 7:44
1

2 Answers 2

1

just put it all together in the same page:

$sql=mysqli_query($aBD->con,"SELECT DISTINCT DenClient FROM $tabel WHERE DenClient!='xxxx'");
if(mysqli_num_rows($sql)){
$select= '<select name="select">';
$select.= '<option> </option>';
while($rs=mysqli_fetch_array($sql)){
$select.='<option>'.$rs['DenClient'].'</option>';
 }
}
$select.='</select>';
if ( isset( $_POST['submit'] ) ) {
 ////is submitted
$client = $_POST['select'];
 // //DO STUFF WITH DATA
} ?>
<form name="form" method="POST" action="accesari.php">
<p>FROM:
<input type="text" id="min" name="min">
</p>
<p>TO:
<input type="text" id="max" name="max">
</p>
<? echo $select;?>
<input type="submit" name="submit"/>
</form>
</head>
 <body>
<script>
 $(document).ready(function() {
 $("#min").datepicker({
 dateFormat: 'd-mm-yy',
 onSelect: function(dateText, inst) {
 $("#min").text(dateText);
 }
 });
 });
</script>
<script>
$(document).ready(function() {
 $("#max").datepicker({
 dateFormat: 'd-mm-yy',
 onSelect: function(dateText, inst) {
 $("#max").text(dateText);
 }
 });
});
</script>
answered May 25, 2016 at 8:34
Sign up to request clarification or add additional context in comments.

Comments

1

You may have to embed all the Fields in one Form Tag as shown below. First Build up the Select in PHP at the top of your File (Perhaps even before the opening HTML Tag...

 <?php
 $sql = mysqli_query($aBD->con,"SELECT DISTINCT DenClient FROM $tabel WHERE DenClient!='xxxx'");
 if(mysqli_num_rows($sql)){
 $select= '<select name="select">';
 $select.= '<option> </option>';
 while($rs=mysqli_fetch_array($sql)){
 $select.='<option>'.$rs['DenClient'].'</option>';
 }
 }
 $select.='</select>';
 // PROCESS YOUR FORM...
 if ( isset( $_POST['submit'] ) ) {
 ////is submitted
 $client = $_POST['select'];
 // //DO STUFF WITH DATA
 }
 ?>
 <html>
 <head>
 <script>
 // NO NEED FOR 2 SCRIPT BLOCK... ONE SHOULD DO.
 $(document).ready(function() {
 $("#min").datepicker({
 dateFormat: 'd-mm-yy',
 onSelect: function(dateText, inst) {
 $("#min").text(dateText);
 }
 });
 $("#max").datepicker({
 dateFormat: 'd-mm-yy',
 onSelect: function(dateText, inst) {
 $("#max").text(dateText);
 }
 });
 });
 </script>
 </head>
 <body>
 <form name="form" method="POST" action="accesari.php">
 <p>FROM:
 <input type="text" id="min" name="min">
 </p>
 <p>TO:
 <input type="text" id="max" name="max">
 </p>
 <!-- EMBED THE SELECT -->
 <p>Select your option:
 <?php echo $select; ?>
 </p>
 <input type="submit" name="submit"/>
 </form>
 </body>
 </html>
answered May 25, 2016 at 8:36

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.