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
  • 2
    a maybe stupid idea, but could it be that name is a reserved word in the window namespace?... try to use nameInput or something and then ask for nameInput.value Commented May 4, 2012 at 21:59
  • the name of the form in the html example should be formob (but this is not the problem)
    – ajax333221
    Commented May 4, 2012 at 22:01
  • @TobiasKrogh it is not stupid idea, that solves the problem jsfiddle.net/fGBGc/3 post it as an answer before someone else :O
    – ajax333221
    Commented May 4, 2012 at 22:02
  • You guys are so awesome! :) Just to clear up the formob, the function receives this.form as variable formob, so it's not related to the form name in any way. As you said though, that wasn't the problem. :)
    – Callum M
    Commented May 4, 2012 at 22:16

1 Answer 1

1

if you use the following HTML

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

and check this JavaScript where you do not use nameas variable name it should work imho. formob needs to be a reference to the form of course:

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​

this should work

2
  • Thankyou very much - really silly mistake that was driving me mad. Fixed it, thanks a load! :)
    – Callum M
    Commented May 4, 2012 at 22:13
  • Somehow managed to miss that giant tick, done now. :) Cheers again!
    – Callum M
    Commented May 4, 2012 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.