/    Sign up×
Community /Pin to ProfileBookmark

this.form.variable is null or not an object

Hello;
The input field named with this variable already exists in my form.
How do I get rid of the error message:
“this.form.variable is null or not an object”?

Can you help me?
Thank-You.
?

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@JonaJul 21.2005 — [font=Trebuchet MS]Care to give a link to the page or post a li’l code?[/font]
Copy linkTweet thisAlerts:
@UltimaterJul 22.2005 — Until you do what Jona says, I'll take a wild guess:

If [b]variable[/b] is indeed a variable, then: [b]this.form[variable][/b]
Copy linkTweet thisAlerts:
@rbleskow999authorJul 22.2005 — I am trying to alter the price of a course - putting at a sale price, when the 1st character of the variable "class_description" starts with a * (star)...

[B]ALL code here below, is inside <BODY><FORM>:[/B]
==================================================


<script language="javascript" >

<!--

function discount(i) {

var t= i.substring(i, 1)

if (t=='*'){

this.form.class_price2.value="88.00";} [COLOR=Navy] // alert('star'); }[/COLOR]

else{

this.form.class_price2.value="n/a";} [COLOR=Navy] // alert('no star'); }[/COLOR]

}

//-->

</script>

(by the way, [COLOR=Navy]the 2 test-ALERTS [/COLOR] [U]work perfectly[/U] by themselves).

It's the "this.form.class_description" that gives me the error:

"this.form.class_description [COLOR=DarkRed]is null or not an object[/COLOR]".
==================================================


This calls the function:

<select name="selectpa" disabled="1" onChange="this.form.class_description.value=this.value;discount(this.value)">
==================================================


The is the destination input field:

<input type="text" name="class_price2" size="5" maxlength="5" onFocus="this.blur()" value="n/a">

? [FONT=Verdana]H E L P ![/FONT] ?
Copy linkTweet thisAlerts:
@KorJul 22.2005 — you have not sensed what the [b]this[/b] self reference is.

in

<select name="selectpa" disabled="1" onChange="this.form.class_description.value=this.value;discount(this.value)">

[b]this[/b] replaces the object which contains the handler, the select element.

but in

function discount(i) {

var t= i.substring(i, 1)

if (t=='*'){

this.form.class_price2.value="88.00";} // alert('star'); }

else{

this.form.class_price2.value="n/a";} // alert('no star'); }

}

which is the sense of [b]this[/b]? Beeing written in the javascript code, it replaces the [b]window[/b] object. but window.form has no meaning...

So that you should use probably

function discount(i) {

var t= i.substring(i, 1)

if (t=='*'){

document.forms[0].class_price2.value="88.00";} // alert('star'); }

else{

document.forms[0].class_price2.value="n/a";} // alert('no star'); }

}
Copy linkTweet thisAlerts:
@JonaJul 22.2005 — <i>
</i>&lt;script type="text/javascript"&gt;&lt;!--
function discount(f,i) {
var t= i.substring(i, 1)
if (t=='*') {
f.class_price2.value="88.00";}
else {
f.class_price2.value="n/a";
}
}
//--&gt;&lt;/script&gt;


<i>
</i>&lt;select name="selectpa" disabled="1" onChange="this.form.class_description.value=this.value;discount(this.form,this.value)"&gt;
Copy linkTweet thisAlerts:
@JonaJul 22.2005 — [font=Trebuchet MS]Sorry, Kor. Didn&#8217;t see your reply.[/font]
Copy linkTweet thisAlerts:
@rbleskow999authorJul 23.2005 — [B][COLOR=DarkGreen]Thanks Guys, THAT PROBLEM IS SOLVED!... but...[/COLOR][/B]

I only need to do one more thing...

I need to display a variable as a number [FONT=Verdana][B][COLOR=Purple][U]to 2 decimal places[/U][/COLOR] [/B][/FONT] (rounded up).

This is how it looks at the moment:
========================================


function discount_YES() {

val1 = document.forms[0].class_price.value;

zz = document.forms[0].class_price.value * .9;

val2 = [B][COLOR=DarkRed]zz[/COLOR][/B];

document.forms[0].class_price.value = this.val1;

document.forms[0].class_price2.value = this.val2;

}

function discount_NO() {

val1 = document.forms[0].class_price.value;

document.forms[0].class_price.value = this.val1;

document.forms[0].class_price2.value = " n/a";

}
========================================


All I need to do is make the result into a number

like.........[B][COLOR=DarkRed]76.58[/COLOR][/B]

not like....76.5763
Copy linkTweet thisAlerts:
@blah1985Jul 23.2005 — Do a search, I'm sure I already saw the rounding program
Copy linkTweet thisAlerts:
@UltimaterJul 23.2005 — <i>
</i>function mathFloat() {
if(arguments.length!=2)return false
if(arguments[0]+1!=arguments[0]-0+1){arguments[0]-=0}
if(arguments[1]&lt;=0)return Math.round(arguments[0]);
return parseFloat(arguments[0].toFixed(arguments[1]));
}

mathFloat(76.5763,2)
×

Success!

Help @rbleskow999 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...