1

using jquery to post a value to php file but the value is not being posted (COMPANY_NAME). Code below works for multiple values but not when it's changed to post single values? Any tips?

$(function() {
    $( "#dialog:ui-dialog" ).dialog( "destroy" );

    var COMPANY_NAME = $( "#COMPANY_NAME" ),
        allFields = $( [] ).add( COMPANY_NAME ),
        tips = $( ".validateTips" );

$( "#dialog-form5" ).dialog({
        autoOpen: false,
        height: 200,
        width: 350,
        modal: true,
        buttons: {
            "ok": function() {
                var bValid = true;
                allFields.removeClass( "ui-state-error" );

                if ( bValid ) {
                    $.post("setCompany.php", {
                                                    COMPANY_NAME:$(this).val()
                     }, function(data) {
                                                    if(data=='no')
                                                    {    $("#msgbox").fadeTo(200,0.1,function()
                                                                 { 
                                                                        $(this).html(data).addClass('messageboxerrorAdd').fadeTo(900,1);
                                                                 });            
                                                    } else if (data=='wrong') {
                                                                 $("#msgbox").fadeTo(200,0.1,function()
                                                                 { 
                                                                     $(this).html("fjdhffh").addClass('messageboxerrorAdd').fadeTo(900,1);
                                                                 });
                                                    } else {
                                                                $("#msgbox").fadeTo(200,0.1,function()
                                                                 { 
                                                                       $(this).html(data).addClass('messageboxerrorAdd').fadeTo(900,1);
                                                                 });
                                                    }
                                            });
                $( this ).dialog( "close" );
                }
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        },
        close: function() {
            allFields.val( "" ).removeClass( "ui-state-error" );
        }
    });
});

2 Answers 2

3

Try this :

$.post("setCompany.php",{"COMPANY_NAME":COMPANY_NAME.val()}, function(data)...

JSON objects require keys to be surrounded by double quotes

Sign up to request clarification or add additional context in comments.

Comments

2
COMPANY_NAME:$(this).val()

I don't think that $(this) points to the company name field. Try this:

"COMPANY_NAME" : COMPANY_NAME.val()

(as mentioned before, JSON keys need to be in double quotes)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.