2012-09-27 160 views
0
$(document).ready(function() { 
    var ttline2 = $('#FIELD_' + FieldIDS['TT_Line2']); 

    ttline2 = $('#FIELD_' + FieldIDS['BadgeHolder']; + $('#FIELD_' + FieldIDS['strap_clip']; + $('#FIELD_' + FieldIDS['Lanyard']; 
    }); 

所以我上面的代碼是這樣的。 我有3個單選按鈕,每個單選按鈕都有一個值,每個值需要添加到輸入字段,輸入字段是TT_Line2。我可以使用$('#FIELD_'+ FieldIDS ['Lanyard'];)打電話給特定的字段,它表示使用點符號會更好。單選按鈕,填充輸入值

問題, 我無法將此傳遞給輸入字段。不過新形成的填充。

這裏是我的HTML代碼

<tbody><tr valign="top" style="width: 125px; "><td style="width: 125px"><input type="radio" name="FIELD_1366" id="FIELD_1366" value="No"><span>No</span> 
    </td> 
    </tr> 
    <tr valign="top" style="width: 125px; "><td style="width: 125px"><input type="radio" checked="" name="FIELD_1366" id="FIELD_1366" value="BadgeHolder"><span>Yes</span> 
    </td> 
    </tr> 
    </tbody> 

    <tbody><tr valign="top" style="width: 125px; "><td style="width: 125px"><input type="radio" name="FIELD_898" id="FIELD_898" value="No"><span>No</span> 
    </td> 
    </tr> 
    <tr valign="top" style="width: 125px; "><td style="width: 125px"><input type="radio" checked="" name="FIELD_898" id="FIELD_898" value="BulldogClip"><span>Yes</span> 
    </td> 
    </tr> 
    </tbody> 

    <tbody><tr valign="top" style="width: 200px; "><td style="width: 200px"><input type="radio" name="FIELD_1276" id="FIELD_1276" value="No"><span>No</span> 
    </td> 
    </tr> 
    <tr valign="top" style="width: 200px; "><td style="width: 200px"><input type="radio" checked="" name="FIELD_1276" id="FIELD_1276" value="White"><span>White</span> 
    </td> 
    </tr> 
    <tr valign="top" style="width: 200px; "><td style="width: 200px"><input type="radio" name="FIELD_1276" id="FIELD_1276" value="Black"><span>Black</span> 
    </td> 
    </tr> 
    </tbody> 

    <div class="fieldSpacer" id="DIV_119"><p class="fieldSpacer">JDELITM</p><p><input value="50-D-EXPKOE-V-F" style="width: 200px; " name="FIELD_119" id="FIELD_119"></p> 
    <script language="javascript"> 
    FieldIDs["JDELITM"] = 119; 
    </script> 
    <div id="VALID_VAR_119" style="display:none" class="validationError"></div> 
    </div> 
+0

我改變了我的周圍看到劇本這裏..仍然沒有運氣。$(文件)。就緒(函數(){VAR = ttline2 $( '#FIELD_' + FieldIDS ['TT_Line2 '])。val; ttline2 = $('#FIELD_'+ FieldIDS ['BadgeHolder'] .val + $('#FIELD_'+ FieldIDS ['strap_clip'] .val + $('#FIELD_'+ FieldIDS ['Lanyard']。val; }); – Cam

回答

0

.VAL是搞亂起來..

應該.VAL(),而不是...你也缺少一些收括號)

而且你正在閱讀textvalue和可變節省...存儲值放入變量,並不意味着該值會自動被更新。您需要明確地設置它。

試試這個代碼

$(document).ready(function() { 
    var ttline2 = $('#FIELD_' + FieldIDS['BadgeHolder']).val() 
     + $('#FIELD_' + FieldIDS['strap_clip']).val() 
     + $('#FIELD_' + FieldIDS['Lanyard']).val(); 

    $('#FIELD_' + FieldIDS['TT_Line2']).val(ttline2); 
});​ 

更新的代碼 如果你想添加你需要首先分析它們的值存儲爲字符串的數字。

var FieldIDS = { 'BadgeHolder' : 'Badge' , 'strap_clip' : 'Clip' , 'Lanyard' : 'Yard' , 'TT_Line2' : 'Line'}; 

$(document).ready(function() { 
    var ttline2 = parseInt($('#FIELD_' + FieldIDS['BadgeHolder']).val()) 
     + parseInt($('#FIELD_' + FieldIDS['strap_clip']).val()) 
     + parseInt($('#FIELD_' + FieldIDS['Lanyard']).val()); 

    $('#FIELD_' + FieldIDS['TT_Line2']).val(ttline2); 
    });​ 

UPDATED DEMO

+0

我在.val中添加了(),但它仍然有問題將值添加到TT_Line2 – Cam

+0

您嘗試了上述代碼 –

+0

您的HTML看起來像什麼 –