admin管理员组文章数量:1405603
I want my form to appear when i click on the button sign up
<div id="signup">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" id="form1">
<input name="user" type="text" placeholder="Username" size="30" >
<input name="pass" type="password" placeholder="Password" size="30" >
<input class="btn" type="submit" value="sign up" name="signup">
</div>
this is the jQuery code:
<script>
$( "#form" ).click(function() {
$( "#signup" ).show( "Clip", 1000 );
});
</script>
I want my form to appear when i click on the button sign up
<div id="signup">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" id="form1">
<input name="user" type="text" placeholder="Username" size="30" >
<input name="pass" type="password" placeholder="Password" size="30" >
<input class="btn" type="submit" value="sign up" name="signup">
</div>
this is the jQuery code:
<script>
$( "#form" ).click(function() {
$( "#signup" ).show( "Clip", 1000 );
});
</script>
Share
Improve this question
edited Mar 31, 2015 at 22:38
scrowler
24.4k10 gold badges64 silver badges96 bronze badges
asked Mar 31, 2015 at 22:34
daniel zeitounydaniel zeitouny
11 gold badge1 silver badge1 bronze badge
1
-
2
Proper code indentation highlights that you haven't closed your form tag (to start with). Secondly, you should bind the click event to the
$('input[name="signup"]')
button, or give the button a unique ID to bind to. I haven't seen anyone binding a click to a form element before... seems wrong. Thirdly, it looks like the button you click to show the form is within the div that you show when you click the button (chicken & egg?) The way I see it, you want something like this – scrowler Commented Mar 31, 2015 at 22:38
2 Answers
Reset to default 2You might want to try something like this...(notice I have added an extra "button" to your HTML and closed the "form" tag
CSS...
#form1 {
display : none;
}
button {
margin-bottom: 10px;
}
HTML...
<div id="signup">
<button id="signup">Click here to sign-up!</button>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" id="form1">
<input name="user" type="text" placeholder="Username" size="30" >
<input name="pass" type="password" placeholder="Password" size="30" >
<input class="btn" type="submit" value="sign up" name="signup">
</form>
</div>
then using JQuery...
$( document ).ready( function() {
$( "#signup" ).click( function() {
$( "#form1" ).toggle( 'slow' );
});
});
JSFiddle
Hope this helps. Good luck!
first of all you haven't closed your form tag, second your targeting an element with a id 'form' and any of the elements you have has such id, now one thing you could do is to give each input element in your form a class(signup_txt for example) and target those elements using css and set the property 'display' to none to hide them like this:
.signup_txt{
display:none
}
then give your submit button an id (signup_btn for example) and do this:
$("#signup_btn").click(function(){
$(".signup_txt").show();
});
and that should do the job here's an demo in jsfiddle: http://jsfiddle/zdksn35f/
本文标签: javascripthow to show form on button click using jqueryStack Overflow
版权声明:本文标题:javascript - how to show form on button click using jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744341901a2601524.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论