0

I have this which posts data to an express/node app and then writes to MongoDB All works well except the select customer: $('#custs').val(), which is showing undefined. This should be simple, No exceptions are throwing either on the client or server side... How do I get the value of the select?

Thanks In Advance!

     function sendIt(){             
             $.ajax({                
            url: "/doIt",
            type: "POST",
            dataType: "json",               
            data: JSON.stringify({                   
                customer: $('#custs').val(),                     
                userID: $('#userID').val(),
                resource: $('#resID').val(),
                ticket: $('#ticketID').val(),
                issueDate: $('#IssueDate').val(),
                issueTime: $('#IssueTime').val(),
                TechName: $('#TechName').val(),
                Urgent: $('#isUrgent').val(),
                description: $('#descript').val()
            }),                 
            contentType: "application/json",
            cache: false,
            timeout: 5000,

                            <select id="custs">
                             <option value="JSC">JSC Co</option>
                              <option value="AGM">More</option>
                              <option value="SWW">Spunge Work</option>
                              <option value="BBV">BBV Corp</option>
                              <option value="UGL">UGL Corp</option>  
                            </select>
RobD
  • 435
  • 4
  • 11
  • 21

1 Answers1

-1

Shouldn't it be

function sendIt(){             
        // ...               
            customer: $('#custs option:selected').val(),                     
        // ...
        }),                 
        contentType: "application/json",
        cache: false,
        timeout: 5000,

?

Get SELECT's value and text in jQuery

Community
  • 1
  • 1
D4V1D
  • 5,805
  • 3
  • 30
  • 65
  • Although the code you provided would in fact get the value for the `select`, `$('#custs').val()` will, too. – Grinn Apr 16 '14 at 13:39
  • So the code provided will do the same as the OP's, why downvote an answer that is not wrong? – D4V1D Apr 16 '14 at 13:43
  • It is wrong. It's not a correct answer to the OP's question. – Grinn Apr 16 '14 at 13:50
  • Hello all, Thanks for all the help,tried everything, its still not working coming through as undefined??? At this point the only thing I can do is drop the select and have them type it into a text box, yuk! – RobD Apr 16 '14 at 15:27
  • Is your select being ajax-loaded in your page or is it created when the DOM is loaded? – D4V1D Apr 16 '14 at 15:29
  • When the DOM is loaded, for now – RobD Apr 16 '14 at 16:45
  • Ok, I figured out its not on the client its in my app.post, i think its this customerID = req.body.custs, Strange, all the others work fine??? – RobD Apr 16 '14 at 18:41