0

I am pretty new at ajax/jquery so I've copied and modified my existing code to try and work. I cant seem to get both WO and Comments to post to my php file (which contains SQL). Right now It does nothing. Use of the following only allows it to send the WO but comments remains blank.

data: 'wo='+wo,

I've even tried

data: {'wo='+wo, 'Comment='+Comment},

HTML:

<div class="panel-body">
    <div class="row">
        <div class="col-lg-12">
            <div class="form-group">
                <p>WO notations appear at the top of the work order screen. Only submit useful information that can be provided to builders/centerpoint. Other importation information may include bricks, scaffles, dogs, or home owners preventing installation. Be sure to include phone numbers if available.</p>
                <label>Information</label>
                <div>
                    <input class="form-control" placeholder="Enter more information here" type="text" name="Comment[]">
                </div>
            </div>
            <button type="submit" name="notation" class="btn btn-default" onClick="AddNotation(<?php echo $_POST['results']; ?>);">Submit Button</button>
             <button type="reset" class="btn btn-default">Reset Button</button>
         </div>
    </div>
</div>  

Jquery:

<!-- Notation -->
<script>
function AddNotation(wo)
{
    jQuery.ajax({
        type: "POST",
        url: "functions/woNotation.php",
        data: {wo: wo, Comment: Comment},
        cache: false,
        success: function(response)
        {
            alert("Your notation has been added to this work order");
        }
    });
}
</script>
1
  • In your JQuery code. Where is Comment defined? Commented Apr 26, 2016 at 0:29

2 Answers 2

1

You need to get the comment value from the <input> field. Give the input field a specific class, like

<input class="form-control comment" placeholder="Enter more information here" type="text" name="Comment[]">

And change the HTML for the submit button to pass a reference to itself so the click handler can find related elements.

<button type="submit" name="notation" class="btn btn-default" onClick="AddNotation(this, <?php echo $_POST['results']; ?>);">Submit Button</button>

Then change the function to get the value of the comment in the same row.

function AddNotation(button, wo)
{
    var Comment = $(button).closest(".row").find(".comment").val();
    jQuery.ajax({
        type: "POST",
        url: "functions/woNotation.php",
        data: {wo: wo, Comment: Comment},
        cache: false,
        success: function(response)
        {
            alert("Your notation has been added to this work order");
        }
    });
}
Sign up to request clarification or add additional context in comments.

Comments

0

wo has a value because you pass in a wo object as a parameter in the AddNotation function.

Comment is empty because you are assigning it to a variable Comment which doesn't exist anywhere else in your code. I assume if you do the following you'll see data in your PHP.

data: {
    wo: wo,
    comment: 'Comment'
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.