Display the table upon completion of the form submission

I am trying to create a form where the table #mytable is only displayed after the form has been submitted. If nothing is entered in the form, the table should remain hidden.

Any suggestions on how I can achieve this?

<form action="" id="myform" method="get">
   <strong>Search by keyword :</strong>
   <input type="text" name="searchword" id="searchword" value=""/>
   <input type="submit" id="show" value="Search"/>
</form>


<table width="100%" id="mytable" class="sortable" border="0" cellpadding="2" cellspacing="2" style="border:1px solid #D4D4D4;">
<tr>
<th bgcolor="#313c95" width="100" style="color: #FFF; font-weight:bold; text-align: left;">EAK Code:</th>
<th bgcolor="#313c95" width="350" style="color: #FFF; font-weight:bold; text-align: left;">Description:</th>
<th style="display:none;"></th>
<th style="display:none;"></th>
<th style="display:none;"></th>

</tr>
</table>

Answer №1

Ensure that your table identified as mytable is not visible (utilize display: none or a similar method), and then apply the following jQuery code:

$('#myform').submit(function() {
  $('#mytable').show();
  return false;
});

Please be aware that this will prevent the form action from being processed (i.e., POSTed to your server).

Answer №2

If you want to trigger a JavaScript function using the onsubmit attribute in a form, follow these steps:

<form ... onsubmit="return displayData();">

Create the following JavaScript function:

function displayData()
{
    document.getElementById('mytable').style.visibility = 'visible'; // This will make the table visible
    return false; // Prevents the form from loading the action page
}

This solution assumes that the table is initially hidden.

I hope this explanation proves helpful!

Answer №3

One approach is to employ a server-side language to verify the presence of a post or get variable, and then embed the table in the HTML document as needed.
Alternatively, you could utilize JavaScript along with cookies for a different implementation. http://plugins.jquery.com/project/cookie

Answer №4

To tackle this issue effortlessly, it's best approached from the backend code. What programming language do you typically use for your projects?

If you're keen on handling this task on the client side, consider appending a query parameter to the action attribute to monitor form submission upon page reload.

How exactly are you planning to submit your form? Are you looking to send your data through traditional form submission or via AJAX? Feel free to provide more details for better assistance.

...with regards, Fredrik

Answer №5

To begin, make sure to set the "display:none" property for your table using the code below.

<form action="" id="myform" method="get">
    <strong>Search by text : </strong>
    <input type="text" name="searchword" id="searchword" value=""/>
    <input type="submit" id="show" value="Search"/>
</form>
<table width="100%" id="mytable" class="sortable" border="0" cellpadding="2" cellspacing="2" style="border:1px solid #D4D4D4; display:none;">
    <tr>
        <th bgcolor="#313c95" width="100" style="color: #FFF; font-weight:bold; text-align: left;">
            EAK Code: 
        </th>
        <th bgcolor="#313c95" width="350" style="color: #FFF; font-weight:bold; text-align: left;">
            Description: 
        </th>
        <th style="display:none;">
        </th>
        <th style="display:none;">
        </th>
        <th style="display:none;">
        </th>
    </tr>
</table>

After submission, use the following code snippet to display the table:

function showTable()
{
    document.getElementById('mytable').style.display = "inline"
}

Answer №6

Are you looking to make changes to your page without having to interact with the server after a standard submission? It seems unlikely if you are using a regular post method.

A standard post request will trigger a navigation, causing the loss of any current client-side data. This renders most suggestions mentioned here invalid. You may need to handle this on the client-side as soon as the page loads. Determining whether it was loaded due to a post or an initial get request will likely require some backend intervention.

Alternatively, you could consider submitting your form via AJAX. By doing so, there won't be any navigation, allowing you to display the table directly on the client-side. Initially render the table with display:none in its style attribute and then reveal it using jQuery('#myTable').show().

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

using javascript to access an opened html div

I am making an AJAX request in A.html and once the response is successful, I want to display a message in B.html. (The message should be displayed in a div with the id='mes_div' which is located in B.html.) How can I access B.html and how do I ac ...

Is there a way to bring my popup closer to my button?

Check out my jsfiddle example here: https://jsfiddle.net/annahisenberg/ft10ersb/34/ Currently, I have the following code: <div id="more_options_popup" style={{ left: this.ref.current.offsetLeft - 140 + "px", top: this.ref.current.offsetTo ...

Using Vue.js to iterate through a nested array from an object key

This is a complex v-for loop nested inside another v-for. It displays a list of questions along with the corresponding answers for each question. The key for the question will be used as the key for grouped_answers. The structure of the v-for loop is show ...

Build a custom Angular2 pipe to convert JSON data into an array through iteration

I am attempting to take the JSON data provided below and convert it into an array for use with *ngFor='let item of items', which will allow me to display data as item.name, etc... This is what I have tried: var out = []; for(var key1 in object) ...

Web scraping with Cheerio in Node.js sometimes yields undefined results

When attempting to extract data from NSE website, I initially tried using the inspect element console: (Edited the question) https://i.sstatic.net/Xq8mZ.png objs = $('div[class="table-wrap"] > table > tbody > tr > td').slic ...

What is the best way to center align all elements using a wrapper in CSS grid?

I am working on designing a layout that looks like this: https://i.sstatic.net/jAaXL.jpg I have set the wrapper as a class and aim to center everything on the screen. Aside from the wrapper, I also want to make the text and form equal sizes. Here is th ...

In IE7, the string comparison in jQuery exhibits unique behavior

When using the following code snippet with a jQuery UI autocomplete element (#search), it works as expected in Firefox, Chrome, and other browsers, always returning true for the selected element. However, Internet Explorer 7 does not behave as expected. $ ...

Retrieving an item from AsyncStorage produces a Promise

Insight I am attempting to utilize AsyncStorage to store a Token after a successful login. The token is obtained from the backend as a response once the user clicks on the Login button. Upon navigating to the ProfileScreen, I encounter difficulties in ret ...

Facing difficulties in resetting the time for a countdown in React

I've implemented the react-countdown library to create a timer, but I'm facing an issue with resetting the timer once it reaches zero. The timer should restart again and continue running. Take a look at my code: export default function App() { ...

jQuery only works partly with IE

I am attempting to utilize jQuery to modify some css styles when the screen size is smaller than a specific threshold (essentially, recreating "@media screen and (max-width: 1024px)", but with consideration for older versions of IE that do not support this ...

Is it possible to construct an IFrame using URL parameters?

Looking to implement an iframe that displays a page provided as a parameter in the URL using ASP.NET MVC4. Here's the approach I have in mind: Updated the code but it still doesn't seem right to me. <?php if(!isset($_GET['link'] ...

CSS fluid layout with three columns

I am attempting to create a 3-column layout where each column has a fluid width of 33% and height of 50%. However, when I add padding to the columns, it causes the last div to move to the next line. How can I resolve this issue? Example HTML: <div id= ...

How to send data from JavaScript to ASP.NET

$(document).ready(function () { $("#MainContent_ddlFieldName").on("change", function () { var id = $(this).val(); var name = $(this + "option:selected").text(); $('#<%= lblValue.ClientID %> ...

Triggering the Bootstrap modal multiple times with each increment

I am experiencing an issue with Bootstrap Modal where the action fires up multiple times upon clicking. <div id="loginModal" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> ... & ...

Locate button elements with the class "button" that do not have any images inside them

Below is the code I am currently using for buttons (I prefer not to change it): <a href="#" class="button"> Button text <img src="someimage.png" /> </a> This CSS styled code creates a sleek button with an icon. To round the left sid ...

Leverage environment variables in React JS to define distinct API URLs for production and development environments

For my React app, I started with create-react-app as the boilerplate. To make a request to my local server, I'm using fetch. fetch("http://localhost:3000/users") .then(function(res){ return res.json() }) .then(function(res){ return res.data }) ...

Could someone kindly clarify the workings of this jQuery script for me?

I found this code online, but I'm struggling to comprehend its functionality. In order to make any edits for my needs, I need to understand how it operates. The purpose of this script is to close a panel with an upward slide animation when the "x" but ...

Issue with sticky positioning not functioning properly with overlapping scrolling effect

When the user scrolls, I want to create an overlapping effect using the 'sticky' position and assign a new background color to each div (section). However, despite setting 'top' to 0 for the 'sticky' position, the divs still s ...

Launch the file explorer using JavaScript/HTML

Is there a way to launch a real explorer window instead of the browser's directory look? For example, like the windows key + e window... Is there a method using html or JavaScript? I've noticed it in a Firefox add-on called new tab king, but I c ...

Node.js: Leveraging Express to Compare URL Parameters and Handle Delete Requests with Array Values

Having some issues with the Express routes I set up for an array of objects and CRUD operations. Everything works smoothly except for the "Delete" operation. I am trying to delete an object by matching its URL parameter ID with the value of its key. Howev ...