PDA

View Full Version : Passing Object Properties


KrazyKid
01-29-2003, 07:39 PM
Hello All,

I want to do something that I am sure is simple, I just can't fathom it at the moment..

Objective:
Pass the object value to a function along with the object property of formname.objectname to null out the text if the condition is met. eg: strObjName.value = ''; strObjName.focus();


Example usage below:


Calling Syntax:
checkTxtField(this.name, this.value);

function checkTxtField(strObjName,strToCheck)
{
if (strToCheck == "some text")
{
alert(strObjName + ': ' + strToCheck)

}
}

Thanks to all that respond!

requestcode
01-29-2003, 07:50 PM
Try changing your function to this:
function checkTxtField(strObjName,strToCheck)
{
if (strToCheck == "test")
{
alert(strObjName.name + ': ' + strToCheck)

}
}

requestcode
01-29-2003, 07:54 PM
Actually I think this would be better:
function checkTxtField(fldobj)
{
if (fldobj.value == "test")
{
alert(fldobj.name + ': ' + fldobj.value)

}
}

<INPUT TYPE="text" NAME="myfld" VALUE="test" onChange="checkTxtField(this)">

KrazyKid
01-29-2003, 08:03 PM
"this" is it!

I was even sorta using it....feels like Monday here!

Anyway thanks for the extra speedy tips!!

All is well now! :o

KrazyKid
01-29-2003, 08:07 PM
checkTxtField(this, 'default text in box');

function checkTxtField(strObjName, strToCheck)
{
if (strObjName.value == strToCheck)
{
strObjName.value = '';
strObjName.focus();

}
}