Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Object Expected" Error

Status
Not open for further replies.

Coder7

Programmer
Oct 29, 2002
224
US
Good afternoon.

I have editible input = text and I need to validate that txtCommentText is not null or spaces and I'm using the javascript below. I get "object expected" both when I blank out the text and when I leave it unedited during form submission. The alert statement below is returning a screen display that contains the correct values for the text box contents. The line that is highlighted in debug regarding "object expected" is: if ((lAction=="E") && (isWhiteSpace(document.frmCommentsAVED.txtCommentText.value))).

I would appreciate any insight that you can provide. Thank you very much.

------------------------------------


function ValidateFields()
{
// To check if Comment Text field is blank in Edit function.

alert(" txtCommentText value = " + document.frmCommentsAVED.txtCommentText.value ) ;
if ((lAction=="E") && (isWhiteSpace(document.frmCommentsAVED.txtCommentText.value)))
{
alert("The comment text field cannot be blank.") ;
document.frmCommentsAVED.txtCommentText.focus() ;
return false ;
}
else
{
document.frmCommentsAVED.sAction.value = lAction+"SAVE" ;
return true ;
}
}
 
You need to tell your script what lAction is. As it stands, it's undefined in your function.

Just a suggestion... if you're checking for an input filed that is blank, just test it's length. If it's zero, than the field is empty!

if (document.frmCommentsAVED.txtCommentText.value.length == 0) There's always a better way...
 
I do that at the very beginning of my javascript. Sorry that I didn't include all of the javascript code - here it is now. Also I added an alert to confirm that lAction =="E" and is is.

Again, thanks for any insight.

<!------------------------------------------------------------------>
<!-- Begin Client-side Script -->
<!------------------------------------------------------------------>
<script ID=&quot;clientEventHandlersJS&quot; LANGUAGE=&quot;javascript&quot;>
<!--
/*************************************************************************************
Function: fnShowCommentsList()
In 'View' when the reset button is pressed, the 'View' popup window closes
**/

var lAction = &quot;<%=glAction%>&quot;

function fnShowCommentsList()
{
window.close() ;
}

function window_onload()
{
// To focus on the Comment Text field when window is launched.
// After record is saved, form is not part of the document, to avoid that error
// first form is checked and then focus field is checked.
if ( document.frmCommentsAVED && document.frmCommentsAVED.txtCommentText )
{
if ( document.frmCommentsAVED.txtCommentText.type == &quot;text&quot; )
document.frmCommentsAVED.txtCommentText.focus() ;
}
}

function fnShowTblCommentsList()
{
window.close() ;
}

function ValidateFields()
{
// To check if Comment Text field is blank in Edit function.

alert(&quot;laction = &quot; +lAction);
alert(&quot; txtCommentText value = &quot; + document.frmCommentsAVED.txtCommentText.value ) ;
if ((lAction==&quot;E&quot;) && (isWhiteSpace(document.frmCommentsAVED.txtCommentText.value)))
{
alert(&quot;The comment text field cannot be blank.&quot;) ;
document.frmCommentsAVED.txtCommentText.focus() ;
return false ;
}
else
{
document.frmCommentsAVED.sAction.value = lAction+&quot;SAVE&quot; ;
return true ;
}
}

//-->
</script>



 
isWhiteSpace is a Java function, not a Javascript function. Hence the error &quot;Object expected&quot; There's always a better way...
 
I think I have a syntactical error someplace in my javascript. isWhiteSpace is a javascript function that I use in other code and it works fine. Also, isWhiteSpace is a standard in our shop so I have to use it.

This syntax stuff will drive you crazy!!

Thanks for your input.
Coder7
 
In my project I was missing the javascript file that contained the isWhiteSpace function.

I wanted to post this in case someone (another newbie!!) has something similar come up.

Was a good lesson.

Thanks tviman, you've been great!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top