0

Apologies for the unweildy title, this is a very difficult question to put into words. This code will explain it much better.

alert(formob.Nam.value); //i work correctly
alert(formob.Num.value); //and me  

name=formob.Nam; 
console.log(name); //[object HTMLInputElement]
console.log("name set "+name.value); //i return 'name set undefined'

num=formob.Num;
console.log(num); //<input type="text" name="Num">
console.log("num set "+num.value); //i return 'num set [value entered]' correctly

Simplified HTML:

<form method="post" class="well" name="FooterCall">
<input type="text" name="Nam">
<input type="text" name="Num">
<button... onmousedown="subajax(this.form...)"..>

Summary: Two essentially identical fields are being set in a form, but one sets incorrectly when the field is set to a Javascript object.

Thankyou very much in advance for any help that can be offered! :)

4

1 に答える 1

1

次の HTML を使用する場合

<form method="post" name="formob">
<input type="text" name="Nam">
<input type="text" name="Num">
</form>
​

nameそして、変数名として使用しないこのJavaScriptをチェックしてください。私見で動作するはずです。formob はもちろんフォームへの参照である必要があります:

console.log(formob.Nam.value); //i work correctly
console.log(formob.Num.value); //and me  

xname = formob.Nam;
console.log(xname); //[object HTMLInputElement]
console.log("name set " + xname.value); //i return 'name set undefined'

num = formob.Num;
console.log(num); //<input type="text" name="Num">
console.log("num set " + num.value); //i return 'num set [value entered]' correctly​

これはうまくいくはずです

于 2012-05-04T22:06:46.207 に答える