2012-06-08 36 views
0

我有一个字段必须基于表单中的其他字段创建,所以我向提交事件处理程序添加了模态确认,但即使该值正确显示在模式中,也不是张贴到处理程序。有什么我必须做的特别插入一个值到$ _POST对象?jQuery没有提交自定义值

这是我的提交功能:

$('form').submit(function(e){ 
    var occ = $('input:radio:[name=isDoubleOccupancy]:checked').val(), 
      numBeds = $('select[name=numBeds]').val(), 
      numBaths = $('select[name=numBaths]').val(), 
      fpImage = ''; 

    if(parseInt(occ) == 1){ 
     fpImage = fpImage + 'do'; 
    } else if(parseInt(occ) == 2){ 
     fpImage = fpImage + 'to'; 
    } else { 
     fpImage = fpImage + ''; 
    } // end if 

    fpImage = fpImage + numBeds + "X" + numBaths + ".png"; 
    $('input[name=fpImage]').val(fpImage); 

    if (!confirm("Please request floor plan graphics named " + fpImage + " from the development team.")) { 
     return false; 
    } // end if 
}); // end form submit 

一个例子POST的转储:

Array (
[id] => 
[fpName] => Efficiency 
[fpBullets] => Private bedroom with private bathroom; Approximately 1,399 square feet; Spacious walk-in closets 
[fpSubBullets] => 
[numBeds] => 1 
[numBaths] => 4 
[isDoubleOccupancy] => 0 
[fpRate] => 1600 
[payPeriod] => Monthly 
[numInstallments] => 12 
[fpSpecial] => 0 
[fpSpecialText] => 
[showHome] => 
[fpImage] => 
[fpSpecialURL] => 
[isSoldOut] => 
) 

你可以看到,[fpImage]被张贴NULL。我已经在谷歌等几个小时寻找代码似乎是正确的。 Firebug显示没有错误。我正式感到沮丧。

在此先感谢您的帮助。

这里的HTML:

<div id="theEditor"> 
    <h2>EDIT FLOOR PLAN</h2> 

    <form action="http://www.edrpo.com/WEBdev/index.php/conn/create_ind_floor_plan" 
    method="post" accept-charset="utf-8"> 
     <label for="fpName">Floor Plan Name</label> <input type="text" name="fpName" value= 
     "" /><br /> 
     <br /> 
     <label for="fpBullets">Floor Plan Main Bullets</label> 
     <textarea name="fpBullets" cols="40" rows="10"> 
</textarea><br /> 
     <span class="emphasisTxt">The following will display as a bulleted list. To enter, 
     separate each bullet with a semicolon. Do not put a semicolon after the last 
     bullet.<br /> 
     DO NOT USE THE ENTER OR RETURN KEY!</span><br /> 
     <br /> 
     <label for="fpSubBullets">Floor Plan Optional Bullets</label> 
     <textarea name="fpSubBullets" cols="40" rows="10"> 
</textarea><br /> 
     <span class="emphasisTxt">The optional bullets will display as a bulleted list at 
     the bottom of the Floor Plans Info page. Use these to add temporary or suplemental 
     information such as seasonal rates, etc. To enter, separate each bullet with a 
     semicolon. Do not put a semicolon after the last bullet.<br /> 
     DO NOT USE THE ENTER OR RETURN KEY!</span><br /> 
     <br /> 
     <label for="numBeds">Number of Bedrooms</label> <select name="numBeds"> 
     <option value=""> 
      Please Select ... 
     </option> 

     <option value="0"> 
      Efficiency 
     </option> 

     <option value="1"> 
      One 
     </option> 

     <option value="2"> 
      Two 
     </option> 

     <option value="3"> 
      Three 
     </option> 

     <option value="4"> 
      Four 
     </option> 

     <option value="6"> 
      Dorm-style 
     </option> 
     </select><br /> 
     <br /> 
     <label for="numBaths">Number of Bathrooms</label> <select name="numBaths"> 
     <option value=""> 
      Please Select ... 
     </option> 

     <option value="1"> 
      One 
     </option> 

     <option value="2"> 
      Two 
     </option> 

     <option value="3"> 
      Three 
     </option> 

     <option value="4"> 
      Four 
     </option> 

     <option value="0"> 
      Dorm-style 
     </option> 
     </select><br /> 
     <br /> 
     <label for="isDoubleOccupancy">Unit Type</label> <input type="radio" name= 
     "isDoubleOccupancy" value="0" checked="checked" id="isDoubleOccupancy" style= 
     "margin:10px" />&nbsp;&nbsp;<span class='likeLabel'>Single-Occupancy</span> 
     <input type="radio" name="isDoubleOccupancy" value="1" id="isDoubleOccupancy" 
     style="margin:10px" />&nbsp;&nbsp;<span class='likeLabel'>Double-Occupancy</span> 
     <input type="radio" name="isDoubleOccupancy" value="2" id="isDoubleOccupancy" 
     style="margin:10px" />&nbsp;&nbsp;<span class= 
     'likeLabel'>Triple-Occupancy</span><br /> 
     <br /> 
     <label for="fpRate">Rate</label> <input type="text" name="fpRate" value="" style= 
     "width:80px;" /><br /> 
     <br /> 
     <label for="payPeriod">Pay Period</label> <select name="payPeriod"> 
     <option value=""> 
      Please Select ... 
     </option> 

     <option value="Monthly"> 
      Monthly 
     </option> 

     <option value="Semester"> 
      Semester 
     </option> 

     <option value="Biannual"> 
      Biannual 
     </option> 

     <option value="Annual"> 
      Annual 
     </option> 
     </select><br /> 
     <br /> 
     <label for="numInstallments">Number of Installments</label> <input type="text" 
     name="numInstallments" value="" style="width:80px;" /><br /> 
     <br /> 
     <input type="radio" name="fpSpecial" value="1" id="fpSpecial" style= 
     "margin:10px" />&nbsp;&nbsp;<span class='likeLabel'>Floor Plan Special ON</span> 
     <input type="radio" name="fpSpecial" value="0" checked="checked" id="fpSpecial" 
     style="margin:10px" />&nbsp;&nbsp;<span class='likeLabel'>Floor Plan Special 
     OFF</span><br /> 
     <br /> 
     <label for="fpSpecialText">Floor Plan Special Text</label> 
     <textarea name="fpSpecialText" cols="40" rows="10"> 
</textarea><br /> 
     <span class="emphasisTxt">Floor Plan Special Text will display on the Floor Plans 
     Info page for this floor plan.</span><br /> 
     <br /> 
     <label for="fpImage">Floor Plan Image</label> <input type="text" name="fpImage" 
     value="" disabled="disabled" style="width:80px;" /><br /> 
     <br /> 

     <p style='text-align:center;'><input type="image" name="submit" value="" src= 
     "http://www.edrpo.com/WEBdev/assets/images/update.png" /></p> 
    </form> 

    <p><br /></p> 
    </div><!-- END theEditor DIV --> 
+1

fpImage是什么类型的输入? –

+0

我们可以看到HTML代码吗? – Joey

+0

你可以发布萤火虫/谷歌浏览器的网络截图吗? –

回答

1

你的HTML标记显示重复的ID和其他问题。

<label for="isDoubleOccupancy">Unit Type</label> 

<input type="radio" name="isDoubleOccupancy" value="0" checked="checked" id="isDoubleOccupancy" style="margin:10px" />&nbsp;&nbsp; 

<span class='likeLabel'>Single-Occupancy</span> 

<input type="radio" name="isDoubleOccupancy" value="1" id="isDoubleOccupancy" style="margin:10px" />&nbsp;&nbsp; 

<span class='likeLabel'>Double-Occupancy</span> 

<input type="radio" name="isDoubleOccupancy" value="2" id="isDoubleOccupancy" style="margin:10px" />&nbsp;&nbsp; 

<span class='likeLabel'>Triple-Occupancy</span> 

可以肯定的是,任何ID只能使用一次。同上id="fpSpecial"和使用的任何其他ID。

编辑:每您邮件中我的注释部分:

这也适用于您的name attributes

它们也都一样,当你的函数设置变量为var occ = $('input:radio:[name=isDoubleOccupancy]:checked').val()时,它将无法正常工作,因为该值始终为0

因为它总是0,自定义值将永远提交。我的回答描述了为什么你有这个问题,因为fpImage = fpImage + '';将永远是这种情况,因此没有图像。

解决方案:使用唯一的idname属性并相应地修改您的脚本。

+0

我正在使用codeigniter,并且这些无线电正在有条件地确定它是否是更新页面或创建页面。我没有意识到这个代码重复了这个id。我不需要ID,所以我会摆脱所有这些以防止重复。 – jgravois

+0

请参阅本答复的答复编辑,谢谢。 – arttronics

0

你需要一个domready中的功能,使所有的元素和变化,可以发现:

$(function() {//domready 
    $('#form').submit(function() { 
        // DO STUFF 
        return true; // return false to cancel form action 
    }); 
}); 
+0

我确实有一个。我刚刚粘贴了自调用匿名domready函数的提交功能。 – jgravois