views:

52

answers:

6

I have a form, if nothing is submitted then it should't show the table #mytable Only when the form has been submitted is should show the table #mytable

How do i do that?

<form action="" id="myform" method="get">
   <strong>Søg på fritekst :</strong>
   <input type="text" name="searchword" id="searchword" value=""/>
   <input type="submit" id="show" value="Søg"/>
</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 Kode:</th>
<th bgcolor="#313c95" width="350" style="color: #FFF; font-weight:bold; text-align: left;">Beskrivelse:</th>
<th style="display:none;"></th>
<th style="display:none;"></th>
<th style="display:none;"></th>

</tr>
</table>
+2  A: 

Make sure your table with id mytable is hidden (use display: none or something similar), then use this jQuery:

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

Note that this prevents the form action being processed (i.e. POSTed to your server).

Dominic Rodger
On a side note, if you are using .NET and the submit button is an postback this may couse problem in IE since the __doPostBack method invokes the submit event after jQuery tries to stop it.
fredrik
Yeah, but i need to process the form to make a search
Nicky
+1  A: 

You can use the onsubmit attribute in the form to run a javascript function:

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

Then have a javascript function

function showTable()
{
    document.getElementById('mytable').style.visibility = 'visible';//shows the table
    return false; //tells the form not to actaully load the action page
}

That's assuming that the table is initially hidden.

Hope that helps

andythepandy93
A: 

You could use a server side language to check for a post or get variable and if it exists include the table in the html.
You could also do something with javascript and cookies. http://plugins.jquery.com/project/cookie

pferdefleisch
A: 

The easiest way to do this is from your backend code. What language are you using?

If you want to do on a client side you need to add a query param to your action attribute so when the page reloads you can see if the form has been posted.

How are you submitting your form? Do you want to post your data via the form or AJAX? Please elaborate a bit.

..fredrik

fredrik
i havent got the possibility to do it from the backend code - Im using XSLT, HTML, CSS, and Javascript - So it needs to be jQuery or XSLT...Yes, the data should be posted, and the data you search for is then displayed in the table - The reason the table should be hidden from the start is that the table contains 500 showable results...
Nicky
Okey, then in the action attribute add something like "?posted=true" and on $(document).ready check the document.location.hash for the appropriate query param.
fredrik
A: 

First of all, assign "display:none" into your table just like following coding.

<form action="" id="myform" method="get">
    <strong>
        Søg på fritekst : 
    </strong>
    <input type="text" name="searchword" id="searchword" value=""/>
    <input type="submit" id="show" value="Søg"/>
</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 Kode: 
        </th>
        <th bgcolor="#313c95" width="350" style="color: #FFF; font-weight:bold; text-align: left;">
            Beskrivelse: 
        </th>
        <th style="display:none;">
        </th>
        <th style="display:none;">
        </th>
        <th style="display:none;">
        </th>
    </tr>
</table>

After submitting, do like that following coding.

function showTable()
{
    document.getElementById('mytable').style.display = "inline"
}
ppshein
i still need to check if the form is submitted?
Nicky
Regarding your question, it's "Yes". Still need to check.
ppshein
A: 

So you want to be able to change your page after a normal submit without doing anything on the server? I don't think you can (if you're doing a normal post that is).

A normal post will cause a navigation, so you will lose your current client-side state. That makes most of the suggestions here incorrect, I think. So you would have to do it client-side right when the page is loaded. At this point, you'll need to know whether it was loaded as a result of a post, or a normal first-round get. I don't think you can do this without putting something in there in the back-end.

Of course, you could do your submit through ajax. This will not cause a navigation and then you can just display the table client-side. Render the table with display:none set for it's style, then use jQuery('#myTable').show();

Joeri Hendrickx