bollo
bollo

Reputation: 1634

jquery post undefined in firebug

On 2 of my elements in a form, I am receiving 'undefined' in firebug. I have tried to trace the error, but keep hitting a brick wall, hence the post. One of the areas with the error is in the divId block and the other is the #company in the form. I would be grateful if someone could check my code and point out my error. Thanks

// Function to add box

function addbox() {

    $("#boxform").dialog({
        autoOpen: false,
        resizable: true,
        modal: true,
        title: 'Submit a box intake request',
        width: 470,
        beforeclose: function (event, ui) {
            $("#addbox").html("");
            $("#divId").html("");

        }

    });

    $('#boxsubmit').click(function () {

        var company = $('.company').val();
        var box = $('.box').val();
        var service = $('#service').val();
        var authorised = $('.authorised').val();
        var address = $('.address').val();
        var data = 'company=' + company + '&box=' + box + '&authorised=' + authorised + '&service=' + service + '&address=' + address;
        $.ajax({
            type: "POST",
            url: "boxesadd.php",
            data: data,
            success: function (data) {
                $("#boxform").get(0).reset();
                $('#addbox').html(data);
                //$("#form").dialog('close');
                $("#flex1").flexReload();

            }
        });
        return false;

    });

    $("#boxform").dialog('open');

}

html

<script language="javascript" type="text/javascript">
      $(function() {
    $("#company").live('change', function() { if ($(this).val()!="")
    $.get("../../getOptions.php?customer=" + $(this).val(), function(data) {
    $("#divId").html(data); }); }); 
      });
</script

<form id="boxform" method="post" class="webform" name="boxform" />

        <label for="company">Select a Company:</label>
        <select name="company" id="company" />
          <option SELECTED VALUE="">Select a Company</option>
          <?php
           do {  
           ?>
          <option value="<?php echo $row_Recordsetcust['customer']?>"><?php echo $row_Recordsetcust['customer']?></option>
          <?php

          } 
          while ($row_Recordsetcust = mysql_fetch_assoc($Recordsetcust));
          $rows = mysql_num_rows($Recordsetcust);
          if($rows > 0)

         {
          mysql_data_seek($Recordsetcust, 0);
          $row_Recordsetcust = mysql_fetch_assoc($Recordsetcust);
                    }

          ?>
          </select>

          <!--- displays the address from the change function -->
          <div id="divId"></div>

Upvotes: 0

Views: 368

Answers (3)

SeanCannon
SeanCannon

Reputation: 77966

Try changing

<form id="boxform" method="post" class="webform" name="boxform" />

to

<form id="boxform" method="post" class="webform" name="boxform"> 

and

<select name="company" id="company" />

to

<select name="company" id="company">

and

var company = $('.company').val();

to

var company = $('#company').val();

Upvotes: 4

Joe Flynn
Joe Flynn

Reputation: 7204

In your #boxsubmit click handler, you use dot instead of hash for #company.

Change

    var company = $('.company').val();

to

    var company = $('#company').val();

and remove the self close / on non-empty elements.

Upvotes: 1

ShankarSangoli
ShankarSangoli

Reputation: 69905

<select name="company" id="company" /> should be <select name="company" id="company"> Then form tag is also not closed correctly.

Upvotes: 1

Related Questions