1

I have one from through which I am entering project name and sheet name which will be saved in project table. Based on this I am inserting empty values on another table 'Data'. I am using editable table to update these empty values in database. I want to hide this table till project name and sheet name is submitted and once value is submitted then only table will be displayed. I have tried a lot but after clicking submit button my table gets displayed till page is reloaded and disappers when loading is completed. My code parts are like below.

    <script>
     $(function(){
     $('button#showit').on('click',function(){  
    $('#myform').show();
     });
     });
    </script>
    <form class="form-horizontal" action="db.php" id="#form1" 
     onSubmit="function();" method="post">

    <input type="text" class="form-control1" name="projectname" 
   id="projectname" required >
    <input type="text" class="form-control1" name="sheetname" id="sheetname" 
    required >
    <button type="submit" name="submit" id="button" class="btn-
     success btn" >Submit</button>
        </form>
      <div class="tab-content"  id="myform" style="display:none">
     <div class="tab-pane active" id="horizontal-form">
     <?php 

       $s4 = "SELECT * FROM data ORDER BY data_id DESC LIMIT 1";
     $res = mysqli_query($bd, $s4);
    while ($row = mysqli_fetch_array($res))
                                 {
                            ?>  
   <table class="table table-bordered" style="width:50%;">
    <thead>
    <tr>
    <th>Sr.no</th>
    <th>Column Name</th>

       </tr>
     </thead>
     <tbody>

   <tr class="odd">
    <td>1</td>
     <td id="d1:<?php echo $row['data_id']; ?>" contenteditable="true"><?php 
    echo $row['d1']; ?></td>          
   </tr>

   .
   .
    .
   </tbody>
    </table>
   <?php } ?>
   </div>
   </div>
 on db.php I have used to get back on my previous page
    <script>
                    alert('Sheet Created Successfully');
                    window.location.href='index.php?success';

   </script>
phpclever
  • 25
  • 7

2 Answers2

0

I cant help you much in your code, maybe you should readjust some things, but, here´s some help:

$('#firstform').submit(function () {
//handle here a function to send data to db.php, then:
sendData();
$('#firstform').hide();
$('#hidedform').show();
     return false;
    });

If you control the submit button not to refresh the page, you can hide first form and display second one. If you post more code I´ll try to be clearer.

("return false" makes submit function not to refresh the page)

here are another post about not refreshing...maybe it helps

Foo Bar
  • 165
  • 2
  • 14
  • I have database activity on it I cant do it on index.php for security. thats y I am sending data to db.php. and as activity completed it will be back on index.php. but that reloads hide it first. and on refreshing page and cliking submit button table is displayed before db activity completes. actually this is totally wrong – phpclever Jun 09 '17 at 06:54
  • I sent you the link for reason. It specifies that you should use submit button to handle the db.php senddata();, hide() and show() as you need, and then a return false to prevent reload, but doing it on submit button will lead to refresh page. Just willing to help. – Foo Bar Jun 09 '17 at 07:54
  • Thinking out of the box...you could return some value from db.php, that can be "tested" onLoad of index.php and chooses what has to be displayed. – Foo Bar Jun 09 '17 at 08:23
0

<!-- Example of jQuery Reference -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<!-- Your Hiding Script -->
<script type='text/javascript'>
    $(document).ready(function(){
      $("#AddNewRecord").hide();
    });
</script>

<!-- Your Markup -->
<table border="1" cellpadding="2" id="AddNewRecord">
    <tr style="width:25px;">
        <td>Site</td>
    </tr>
</table>
  • # randy its not useful for me – phpclever Jun 09 '17 at 06:51
  • okay say clearly whats ur requirement???? can u explain in a better manner?? @phpclever – Anudep naidu Jun 09 '17 at 06:56
  • I have one form whose value will be added to a table based on this I am inserting data into another table and I want to show added data on the same page where my form is in table format. but it will happen only after my form values are added in table. thats my requirement. – phpclever Jun 09 '17 at 07:03