Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Submit Form with out refreshing page Tutorial</title>
- <!-- Meta Tags -->
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <!-- CSS -->
- <link rel="stylesheet" href="css/structure.css" type="text/css" />
- <link rel="stylesheet" href="css/form.css" type="text/css" />
- <!-- Javascript -->
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/
- libs/jquery/1.3.0/jquery.min.js"></script>
- <script type="text/javascript">
- $(function() {
- $(".submit").click(function() {
- var name = $("#name").val();
- var username = $("#username").val();
- var dataString = 'name='+ name + '&ph=' + username;
- if(name=='' || username=='')
- {
- $('.success').fadeOut(200).hide();
- $('.error').fadeOut(200).show();
- }
- else
- {
- $.ajax({
- type: "POST",
- url: "http://funiks.com/invoice/phonebook/submit_new_contact_ajax.php",
- data: dataString,
- success: function(){
- $('.success').fadeIn(200).show();
- $('.error').fadeOut(200).hide();
- }
- });
- }
- return false;
- });
- });
- </script>
- <style type="text/css">
- body{
- background:url(http://s3.amazonaws.com/twitter_production/profile_background_images/6250979/bgtwitter.jpg) no-repeat;
- }
- .error{
- color:#d12f19;
- font-size:12px;
- }
- .success{
- color:#006600;
- font-size:12px;
- }
- </style>
- </head>
- <body id="public">
- <div style="height:30px"></div>
- <div id="container">
- <div style="height:30px"></div>
- <form autocomplete="off"
- enctype="multipart/form-data" method="post" name="form">
- <div class="info" style="padding-left:20px">
- <h2>Submit Form Values with jQuery and Ajax</h2>
- <div>More tutorials <a href="http://9lessons.blogspot.com" style="color:#0066CC; font-weight:bold">http://9lessons.blogspot.com</a> </div>
- </div>
- <ul>
- <li id="foli1" class=" ">
- <label class="desc" id="title1" for="Field1">
- Full Name </label>
- <div>
- <input id="name" name="name" type="text" class="field text medium" value="" maxlength="255" tabindex="1" />
- </div>
- </li>
- <li id="foli3" class=" ">
- <label class="desc" id="title3" for="Field3">
- User-ID </label>
- <div>
- <input id="username" name="username" type="text" class="field text medium" value="" maxlength="255" tabindex="3" />
- </div>
- </li>
- </ul>
- <div class="buttons">
- <input type="submit" value="Submit" style=" background:#0060a1; color:#FFFFFF; font-size:14px; border:1px solid #0060a1; margin-left:12px" class="submit"/><span class="error" style="display:none"> Please Enter Valid Data</span><span class="success" style="display:none"> Registration Successfully.......... Click To <a href="http://9lessons.blogspot.com" style="color:#0066CC; font-weight:bold">http://9lessons.blogspot.com</a></span>
- </div>
- </form>
- <div style="height:20px"></div>
- </div><!--container-->
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement