SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    reading a button

    I am VERY new to Jquery programming and I really need y'alls help...

    I am trying to use the following script to update a page without refreshing if there is a login error :
    Code JavaScript:
     
    $(function(){
    	$("#log").submit(function(){
    		dataString = $("#log").serialize();
    		$.ajax({
    		type: "POST",
    		url: "maintenance.php",
    		data: dataString,
    		dataType: "json",
    		success: function(data) 
    			{
    				$("#log_area").html("Username Password Combination was not found");
    			}
    		});
    		return false;			
    	});
    });

    Here's a form that I have:


    Code HTML:
    <form id="log">
    <label for="username">Username:</label><br/>
    <input type="username" name="username" id="username" /><br/>
    <label for="password">Password:</label><br/>
    <input type="password" name="password" id="password" />
    <input type="submit" name="swvar" value="Login"/>
    <input type="submit" name="swvar" value="Forgot Password" />
    </form>

    It will not allow me to process what's in the value field of the button like when I submit the form using "action" and "method" fields in the form tag.

    I can get it to work by adding a hidden field with the necessary info, but that is only useful when there is only one button in the form. How can I modify this to use the button field values so I can put more than one button on the form?

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Simply change it to this

    Code JavaScript:
    $(function(){
        $("#login-submit").click(function(){
            dataString = $("#log").serialize();
            $.ajax({
                type: "POST",
                url: "maintenance.php",
                data: dataString,
                dataType: "json",
                success: function(data){
                        $("#log_area").html("Username Password Combination was not found");
                }
            });
     
            return false;         
        });
    });

    HTML Code:
    <form id="log">
        <label for="username">Username:</label><br/>
        <input type="username" name="username" id="username" /><br/>
        <label for="password">Password:</label><br/>
        <input type="password" name="password" id="password" />
        <input type="submit" name="swvar" id="login-submit" value="Login"/>
        <input type="submit" name="swvar" value="Forgot Password" />
    </form>

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks man...I appreciate the help

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    No problem


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •