Showing and hiding input

Asked

Viewed 56 times

0

I have a button, when I click on it I want a field like input, in this field, when I add some text I want it to go to the database, with a ALTER table. How to do the input appear and how to make it disappear?

1 answer

1

You can use jQuery to do it without much effort:

In html start your input as hidden.

<input type="text" id="seu-input" style="display:none">

Create a button to display the input:

<button id="exibe-input">Meu botão</button>

And finally create a javascript function so that when the button is clicked it displays the field.

<script type="text/javascript">
$('#exibe-input').click(function(){
 $('#seu-input').css("display", "block");  
}
</script>

To hide the field another function can be created with the opposite action.

$('#seu-input').css("display", "none");

Source: The display Property

  • 1

    Friend, depending on the version of Jquery, it will not accept . css( 'property' value ), you will have to pass the CSS values as object, example: . css({ 'display' 'None'}). It’s just an observation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.