简体   繁体   English

选择中的值未显示在输入值中

[英]Value from Select not showing up in input value

The select option is within a fieldset and uses AJAX to Post the data to a Mongodb. select选项位于字段集中,并使用AJAX将数据发布到Mongodb。 For some reason all the other values will show up in the DB except for the location option. 由于某些原因,除location选项外,所有其他值都会显示在数据库中。

Below is the Jade code and JS for the function for adding it. 下面是Jade代码和JS的添加功能。 This is my first project and not sure if I'm just missing something obvious or not. 这是我的第一个项目,不确定我是否只是缺少明显的东西。

Also, when I change the type to number for some inputs it invalidates everything and it posts and entry to the DB with no data attached to it. 另外,当我将某些输入的类型更改为数字时,它会使所有内容无效,并且会在没有附加数据的情况下将其发布和输入数据库。 Any ideas? 有任何想法吗?

 // Add User function addUser(event) { event.preventDefault(); // Super basic validation - increase errorCount variable if any fields are blank var errorCount = 0; $('#addUser input').each(function(index, val) { if($(this).val() === '') { errorCount++; } }); // Check and make sure errorCount's still at zero if(errorCount === 0) { // If it is, compile all user info into one object var newUser = { 'Date_Entered': $('#addUser fieldset input#inputDate_Entered').val(), 'First_Name': $('#addUser fieldset input#inputFirst_Name').val(), 'Last_Name': $('#addUser fieldset input#inputLast_Name').val(), 'Incident_Date': $('#addUser fieldset input#inputIncident_Date').val(), 'Resoulution_Date': $('#addUser fieldset input#inputResolution_Date').val(), 'Location': $('#addUser fieldset input#inputlocation').val(), 'Damage': $('#addUser fieldset input#inputDamage').val(), 'Cost': $('#addUser fieldset input#inputCost').val(), 'Coupon': $('#addUser fieldset input#inputCoupon').val(), 'Vehicle_Year': $('#addUser fieldset input#inputVehicle_Year').val(), 'Make': $('#addUser fieldset input#inputMake').val(), 'Resolution': $('#addUser fieldset input#inputResolution').val(), 'Model': $('#addUser fieldset input#inputModel').val(), 'Comments': $('#addUser fieldset input#inputComments').val(), 'Claim_type': $('#addUser fieldset input#inputClaim_type').val(), 'ManagersName': $('#addUser fieldset input#inputManagersName').val(), 'Resolution_Date': $('#addUser fieldset input#inputResolution_Date').val(), 'CouponQuantity': $('#addUser fieldset input#inputCouponQuantity').val(), 'CouponType': $('#addUser fieldset input#inputCouponType').val(), 'Address': $('#addUser fieldset input#inputAddress').val(), 'City': $('#addUser fieldset input#inputCity').val(), 'State': $('#addUser fieldset input#inputState').val(), 'Zip': $('#addUser fieldset input#inputZip').val(), 'Email': $('#addUser fieldset input#inputEmail').val(), } // Use AJAX to post the object to our adduser service $.ajax({ type: 'POST', data: newUser, url: '/users/adduser', dataType: 'JSON' }).done(function( response ) { // Check for successful (blank) response if (response.msg === '') { // Clear the form inputs $('#addUser fieldset input').val(''); // Update the table populateTable(); } else { // If something goes wrong, alert the error message that our service returned alert('Error: ' + response.msg); } }); } else { // If errorCount is more than 0, error out alert('Please fill in all fields'); return false; } }; 
  // ADD USER h2 Add User #addUser fieldset input#inputDate_Entered(type='date', placeholder='Username') input#inputFirst_Name(type='text', placeholder='Email') br input#inputLast_Name(type='text', placeholder='Full Name') input#inputIncident_Date(type='date', placeholder='Age') br input#inputResolution_Date(type='date', placeholder='Location') p label select#inputlocation(type='text', tabindex='#{tab_index++}') option 11 North Mchenry option 12 Ceres option 13 Turlock option 14 Briggsmore option 15 Merced option 16 Lodi option 18 Dale Road option 19 Oakdale option 20 Riverbank option 21 Atwater option 22 Plaza option 23 Manteca option 24 South Mchenry option 25 Tracy option 26 University option 27 Whitmore br input#inputDamage(type='text', placeholder='Damage Type') input#inputCost(type='text', placeholder='Cost') br input#inputCoupon(type='text', placeholder='Coupon') input#inputVehicle_Year(type='text', placeholder='Year') br input#inputMake(type='text', placeholder='Make') input#inputResolution(type='text', placeholder='Resolution') input#inputModel(type='text', placeholder='Model') input#inputComments(type='text', placeholder='Comments') br input#inputClaim_type(type='text', placeholder='Claim Type') input#inputManagersName(type='text', placeholder='Managers Name') br input#inputResolution_Date(type='text', placeholder='Resolved') input#inputCouponQuantity(type='text', placeholder='Coupon Quantity') br input#inputCouponType(type='text', placeholder='Coupon Type') input#inputAddress(type='text', placeholder='Address') br input#inputCity(type='text', placeholder='City') input#inputState(type='text', placeholder='State') br input#inputZip(type='text', placeholder='Zip') input#inputEmail(type='text', placeholder='Email') button#btnAddUser Add User 

The problem is actually the strange selectors, this 问题实际上是奇怪的选择器,这

$('#addUser fieldset input#inputlocation')

does not match a select element, that would be 与选择元素不匹配,那就是

$('#addUser fieldset select#inputlocation')

but they are both wrong, it should be just 但他们都错了,应该只是

$('#inputlocation')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM