반응형
jqueryphp.com 에서 퍼온 소스임.
* jquery
- <script language="javascript">
- $(document).ready(function(){
- //global vars
- var userName = $("#name"); //name field
- var userEmail = $("#email"); //email field
- var userTxt = $("#txt"); //comment field
- var targetDiv = $("#targetDiv"); //target div to print results
- //function to check name and comment field
- function checkCommentsForm(){
- if(userName.attr("value") && userTxt.attr("value"))
- return true;
- else
- return false;
- }
- //When form submitted
- $("#form1").submit(function(){
- if(checkCommentsForm()){
- targetDiv.show('fast');
- //send to test.php
- $.ajax({
- type: "POST", url: 'test.php', data: "name="+userName.val()+"&email="+userEmail.val()+"&txt="+userTxt.val(),
- complete: function(data){
- //print results as appended
- targetDiv.append(data.responseText);
- //print result in targetDiv
- //targetDiv.html(data.responseText);
- }
- });
- }
- else alert("Please fill required fields!");
- return false;
- });
- });
- </script>
* html
- <div>
- <form id="form1" name="form1" method="post" action="" onsubmit="return false;">
- <input type="text" name="name" id="name">
- Name
- <input type="text" name="email" id="email">
- <input type="text" name="txt" id="txt">
- Comment
- <input type="submit" name="button" id="button" value="go go...">
- <span onclick="$('#targetDiv').html('')" style="cursor:pointer;">Clear result</span>
- </form>
- </div>
- <div id="targetDiv" style="display:none;">
- </div>
이렇게 해서 입력받은 데이터를 넘기고, php나 jsp 등에서 쿼리를 날리면 될듯. +_+
반응형
'개발 > jquery' 카테고리의 다른 글
샘플예제 연습1 (0) | 2011.02.08 |
---|---|
2011-01-13, [1.5 DOM요소의 래퍼 집합 필터링하기 실습] (0) | 2011.01.13 |
2011-1-1 (0) | 2011.01.01 |
jQuery 관련링크모음 (0) | 2010.12.30 |
2010-12-28 (0) | 2010.12.29 |