SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax form submit problems...

    I'm trying to submit a form using ajax and got it working just fine but 1 problem though...

    I want my submit button to have another value than "Submit", lets say "Next", but if I change this the form is not submitted... Where do I go wrong?
    Code JavaScript:
    $(function() {
    $(".submit").click(function() {
    var address1 = $("#address1").val();
    var zipcode = $("#zipcode").val();
    var city = $("#city").val();
    var cellphone = $("#cellphone").val();
    var phone = $("#phone").val();
     
    var dataString = 'address1='+ address1 + '&zipcode=' + zipcode + '&city=' + city + '&cellphone=' + cellphone + '&phone=' + phone;
     
    if(address1=='' || city=='')
    {
    $('.success').fadeOut(200).hide();
    $('.error').fadeOut(200).show();
    }
    else
    {
    $.ajax({
    type: "POST",
    url: "update.php",
    data: dataString,
    success: function(){
    $('.success').fadeIn(200).show();
    $('.error').fadeOut(200).hide();
    }
    });
    }
    return false;
    });
    });

    Thanks in advance :-)

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,701
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jmansa View Post
    I want my submit button to have another value than "Submit", lets say "Next", but if I change this the form is not submitted... Where do I go wrong?
    None of that code appears to be relevant to the problem at hand.

    What is the HTML code that causes things to fail, and do you have any code anywhere that makes uses the submit button value?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    What is the HTML code that causes things to fail, and do you have any code anywhere that makes uses the submit button value?
    Here is the form:
    Code HTML4Strict:
    <form action="" method="post">
    Address1: <input id="address1" name="address1" type="text" /><br />
    Zipcode: <input id="zipcode" name="zipcode" type="text" /><br />
    City: <input id="city" name="city" type="text" /><br />
    Cellphone: <input id="cellphone" name="cellphone" type="text" /><br />
    Phone: <input id="phone" name="phone" type="text" /><br />
    <input type="submit" value="Submit" class="submit"/>
    </form>
     
    <div>
    <span class="error" style="display:none"> Please Enter Valid Data</span>
    <span class="success" style="display:none"> Registration Successfully</span>
    </div>

    Its if I change "<input type="submit" value="Submit" class="submit"/>" to "<input type="submit" value="Test" class="submit"/>" it goes wrong???

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,701
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jmansa View Post
    Its if I change "<input type="submit" value="Submit" class="submit"/>" to "<input type="submit" value="Test" class="submit"/>" it goes wrong???
    That's very odd. I cannot duplicate the problem with my own test code, so the next step from here is for you to link us to a live test page that exhibits the problem you're having.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    That's very odd. I cannot duplicate the problem with my own test code, so the next step from here is for you to link us to a live test page that exhibits the problem you're having.
    My bad... Had a line in my script without the ";" afterwards... Everything works just fine:-)


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
  •