2011-12-05 6 views
0

私は、スクリプトの作業Javascript&JQueryの奇妙な問題または何が間違っていましたか?

...もう一つの方法を働いていないが、窓に窓から値を対処するため、この機能を持っています、今この他のスクリプトに

$(document).ready(function(e) { 
    $('#clickit').live({ 
     click: function() { 
      window.opener.document.forms['orderForm']['service'].value = document.forms['GroundRates']['service'].value; 
      window.opener.document.forms['orderForm']['rate'].value = document.forms['GroundRates']['rate'].value; 
      self.close(); 
      return false; 
     } 
    }); 
}); 

を私が何をしました違う?私はここで私の髪を引っ張っています。 .. ..私も試した

$(document).ready(function(e) { 
    $('#clickit').live({ 
     click: function() { 
      var thisservice = document.forms['GroundRates']['service'].value; 
      var thisrate = document.forms['GroundRates']['rate'].value; 
      var thatservice = window.opener.document.forms['orderForm']['service'].value; 
      var thatrate = window.opener.document.forms['orderForm']['rate'].value; 
      $(thatrate) = $(thisrate); 
      $(thatservice) = $(thisservice); 
      self.close(); 
      return false; 
     } 
    }); 
}); 

thatrate = thisrate; 
thatservice = thisservice; 

$(thatrate).val() = $(thisrate).val(); 
$(thatservice).val() = $(thisservice).val(); 

とをしかし、これは動作します:

に動作していない

var service = document.forms['GroundRates']['service'].value; 
var rate = document.forms['GroundRates']['rate'].value; 
window.opener.document.forms['orderForm']['service'].value = service; 
window.opener.document.forms['orderForm']['rate'].value = rate; 

window.openerに正しくvarを割り当てていませんか?

+0

FYI、構文は$(thatrate).val($(thisrate).val()) ' – climbage

答えて

1
var thisservice = document.forms['GroundRates']['service']; 
var thisrate = document.forms['GroundRates']['rate']; 
var thatservice = window.opener.document.forms['orderForm']['service']; 
var thatrate = window.opener.document.forms['orderForm']['rate']; 

thatrate.value = thatservice.value; 
thatservice.value = thisservice.value; 

またはあなたがラップする場合jQueryオブジェクトを持つDOMオブジェクト。

var thisservice = document.forms['GroundRates']['service']; 
var thisrate = document.forms['GroundRates']['rate']; 
var thatservice = window.opener.document.forms['orderForm']['service']; 
var thatrate = window.opener.document.forms['orderForm']['rate']; 

$(thatrate).val($(thatservice).val()); 
$(thatservice).val($(thisservice).val()); 
+0

私は何が間違っているかを見ます。ご協力いただきありがとうございます! – Monty

2

あなたは、新しい値は括弧の内部に入る.val()

$(thatrate).val($(thisrate).val()); 
$(thatservice).val($(thisservice).val()); 

を悪用しています。

1

試してみてください。

var thisservice = document.forms['GroundRates']['service']; 
var thisrate = document.forms['GroundRates']['rate']; 
var thatservice = window.opener.document.forms['orderForm']['service']; 
var thatrate = window.opener.document.forms['orderForm']['rate']; 
thatrate.val(thisrate.val()); 
thatservice.val(thisservice.val()); 
+1

はjQueryオブジェクトが、そのネイティブのDOMオブジェクト'ないthatrate'あなたの例では、 ''覚えています。 「val」は働かないだろう。代わりにユーザ '.value'。 –

+0

ああ、はい、そうです。 – DrXCheng

1

あなたのコンソールはあなたを教えてくれます:ReferenceError: Invalid left-hand side in assignment

$(thatrate) = $(thisrate); 
$(thatservice) = $(thisservice); 

あなたはこのようにそれを実行する必要があります。

var thisservice = document.forms['GroundRates']['service']; 
var thisrate = document.forms['GroundRates']['rate']; 
var thatservice = window.opener.document.forms['orderForm']['service']; 
var thatrate = window.opener.document.forms['orderForm']['rate']; 

thatrate.value = thisrate.value 
thatservice.value = thisservice.value; 
関連する問題