2012-12-11 22 views
0

這工作,但只有當值存在時加載窗體:JQuery的串聯

$('CSZ').val(
$('City').val() + ', ' + 
$('State').val() + ' ' + 
$('Zip']).val() 

我想這樣的功能,試圖串聯的字段將被填充,但沒有奏效。

$('CSZ').blur(function() { 
$('City').val() + ', ' + 
$('State').val() + ' ' + 
$('ZipCode').val()}); 

但是沒有得到任何結果。有任何想法嗎?

謝謝。

OK this works. Is there any simpler way to write this? 

function SetMainLine() {var csz = 
$(spec['V08_City']).val() + ', ' + 
$(spec['V09_State']).val() + ' ' + 
$(spec['V10_ZipCode']).val(); 
$(spec['V01_Mainline']).val(csz); 
} 

spec['V08_City'].onchange = SetMainLine; 
spec['V09_State'].onchange = SetMainLine; 
spec['V10_ZipCode'].onchange = SetMainLine; 

The spec[''] is just calling a form field from a database. 

回答

3

.blur功能從來沒有真正賦予新的價值:

var val = $('City').val() ... 
$(this).val(val); 

meder指出,你可能會丟失一些選擇語法了。