When is an object not an object!

Results 1 to 3 of 3

Thread: When is an object not an object!

  1. #1
    Join Date
    Dec 1969

    Default When is an object not an object!

    Arrrrgghhhhh, sorry - just releasing my frustration!!!<BR><BR>I have a JavaScript Problem that&#039;s causing me hassel, can anyone help?<BR><BR>I&#039;m trying to return a value from a form to a Jscript variable. Here is a snippet of my code:<BR><BR>&#060;Form method="POST" action="Process.asp" name="frmAssocDetails"&#062;<BR>&#060;input type="text" name="StaffNo" onchange="ValidateData();" value="&#060;% =StaffNo %&#062;"&#062;<BR>&#060;/form&#062;<BR><BR>I am tryng to read the value in StaffNo into a Jscript variable using: var checkStr = frmAssocDetails.StaffNo.value;<BR><BR>...but i&#039;m getting the following error: StaffNo.value is null or not an object.<BR><BR>The whole purpose of the exercise is to check for invalid characters in the form, hence i&#039;m using an onchange event of the StaffNo text box. The value should not be null because i&#039;m entering &#039;invalid&#039; chars into the textbox in order to test it - has anyone got any bright ideas!???<BR>

  2. #2
    Mike Shaffer Guest

    Default RE: When is an object not an object!

    What happens if you refer to the field as:<BR><BR>document.forms[&#039;frmAssocDetails&#039;].StaffNo.value

  3. #3
    Join Date
    Dec 1969

    Default Two possibilities...plus...

    (1) You *really* should use<BR>var checkStr = document.frmAssocDetails.StaffNo.value;<BR><BR>Net scape does *not* see the named form unless you precede it with "document.". I doubt this is your problem, but...<BR><BR>(2) Do you possibly have TWO fields named "StaffNo" in that form? If you do, then (even if they are of different types!) they will be converted into an *array* of fields.<BR><BR>A little debugging here helps:<BR><BR>In you ValidateDate function, first thing you do is something like:<BR>&nbsp; &nbsp; alert(document.frmAssocDetails.StaffNo.type);<BR>t o see what kind of thing JS thinks it is dealing with.<BR><BR>**************<BR>And one further hint:<BR><BR>Try doing this:<BR><BR>&#060;input type="text" name="StaffNo" onchange="ValidateData(this);" value="&#060;% =StaffNo %&#062;"&#062;<BR><BR>and then<BR><BR>function ValidateDate(txt)<BR>{<BR>&nbsp; &nbsp; var checkStr = txt.value;<BR>&nbsp; &nbsp; ...<BR>}<BR><BR>When you use "this" to pass a reference directly to the appropriate form field, then there is never a possibility of ambiguity as to which field is meant. You don&#039;t need its name; it doesn&#039;t matter if there are several of the same name; etc., etc.<BR><BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts