hey i would like to show an table when user fills an input.
What I have is:
in <head> section:
<script type="text/javascript">
//hide initially
$("table#mytable").hide();
// show function
function showit() {
$("table#mytable").show();
}
</script>
and the table:
<table id="mytable"><tr><td>FOO</td><td>BAR</td></tr></table>
and a form below(maybe it is important) the table:
<form action="foobar.php">
<input name="example" onselect="showit()" />
<input type="submit" value="Send" />
</form>
I think onselect isn’t perfect but it should do the thing in my case.
The code above doesn’t hide the table at all. I don’t know what I did wrong. Hope some1 can find a mistake – thank you.
EDIT
here is the solution:
head:
<script type="text/javascript">
function show(id) {
document.getElementById(id).style.display = 'block';
}
</script>
and in every element to hide just add style="display: none;" and edit input – add onkeyup="show('id') where id is id of element to hide e.g. #mytable
The reason it isn’t working is because you are calling the javascript before the table element is rendered. There are three ways of doing this:
or
or