Need some help with submit button & onclick function + other problem....please

Discussion in 'Programming' started by almostfamous, Oct 18, 2012.

  1. #1
    hi i need some help with my code not the best at it but here it goes

    first off here is my code

    i need it to submit the data then do a redirect but the onclick for somereason overrides the submit

    <input type="submit" value="Proceed to Checkout" class="green-btn" onclick="window.location='http://examplewebsite.com'" />

    even if i try action="urlhere" it gives me an error and does nothing error is XMLHttpRequest cannot load [websiteurl] Origin [websiteurl] is not allowed by Access-Control-Allow-Origin.

    also i have another problem

    
    <script type="text/javascript">
        $(document).ready(function(){
            $(".checkout-form .error-message").hide();
            $(".checkout-form .success-message").hide();
            
            $(".checkout-form form[name=contact]").submit(function(){
                $(".checkout-form .success-message").hide();        
            
                message = $(".checkout-form input[name=message]").val();
                email = $(".checkout-form input[name=email]").val();
    
    
     if(message=="ex. http://facebook.com/buylegitlikes" || message==null){ $(".contact-form .error-message").show(); $(".contact-form .error-message").html("Your URL field is required."); return false; } 
                
                if(email=="ex. buylegitlikes@live.com" || email==null){ $(".checkout-form .error-message").show(); $(".checkout-form .error-message").html("We need to get back to you. Enter your email address field is required."); return false; }     
    
    
                if (email.indexOf("@")==-1 ||  email.lastIndexOf(".")==-1){ $(".checkout-form .error-message").show(); $(".checkout-form .error-message").html("Invalid email address."); return false; }            
                
                
                $.post("http://examplesite.com", {message: message, email: email}, function(data){
                    $(".checkout-form .error-message").hide('');
                    $(".checkout-form .success-message").show();
                                    
                    $(".checkout-form textarea[name=message]").val("");
                    $(".checkout-form input[name=email]").val("");
                })
                            
                return false;
            })
        });
    </script>
    <div class="checkout-form">                      <form class="checkout-form clearfix" method="post" name="contact">
      <div class="grid_8">
          <div class="steps"><span class="twitter">Step 1</span> Enter your Information    </div>
        <div class="checkout-block c-user-data pad">
          <label for="user-input">Facebook URL</label>
          <input type="text" value="ex. http://facebook.com/buylegitlikes" id="Facebook_URL"  name="message" class='input' style="color:#7C7C7C;" onfocus="if(this.value == 'ex. http://facebook.com/buylegitlikes'){this.value = ''; this.style.color = '#000000';}"  onblur="if(this.value == ''){this.value = 'ex. http://facebook.com/buylegitlikes'; this.style.color = '#7C7C7C';}"/>
              </div>
        <div class="checkout-block c-user-data pad">
          <label for="user-input">Email Address</label>
          <input type="text" value="ex. buylegitlikes@live.com" id="Facebook_Email" class='input-email' name="email" style="color:#7C7C7C;" onfocus="if(this.value == 'ex. buylegitlikes@live.com'){this.value = ''; this.style.color = '#000000';}"  onblur="if(this.value == ''){this.value = 'ex. buylegitlikes@live.com'; this.style.color = '#7C7C7C';}"  />
        </div>
              <div class="error-message" style="color: #f00; padding:5px 10px;margin:5px 0 10px 0;"></div>
            <div class="success-message" style="color: #333; padding:5px 10px;margin:5px 0 10px 0;">Thank You!</div>
            
    Code (markup):
    for some reason this codes dosnt do what its told either all help would be greatly appriciated
     
    Last edited: Oct 18, 2012
    almostfamous, Oct 18, 2012 IP
  2. udores

    udores Member

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #2
    About the first problem of the form not being submitted all you have to do is

    1. remove the onclick handler from the input tag

    2. Edit the file where your post variables are being submitted to. Note that your must first process the post array - $POST[] before making any redirects

    3. At the point where you've finished processing your POST variable then you can add the redirect script like this:

    ?>
    <script type='text/javascript'>
    window.location="url";
    </script>
    <?php

    note: the first and last line is only needed if you need to break away from any php or server side scripting before making the redirection.

    As for the ajax. It'll take some time to go through your code to find the bug. But i usually recommend some third-party interface in dealing with the intricacies of ajax. Try googling up YUI-Yahoo User Interface. That what i use personally.

    Anyways, i'll still go through your code:)
     
    udores, Oct 21, 2012 IP