0

MotherTongueTxtBox.Attributes.Add("onblur","val_Length(MotherTongueTxtBox.text,"hi friends",Length);")

in the above statement val_length s a javascript function in tat function the first parameter shd b the contents of the text box ,the second parameter s a string type, is the statement correct i think it s wrong can u suggest a correct valid statement please

1 Answer 1

2

I had a little trouble understanding your question, but I think you're asking that the first parameter be the textbox text, and the second be the length of the textbox text. This I think should work:

MotherTongueTxtBox.Attributes.Add("onblur","val_Length(this.value,this.value.length)");

Remember that the above will render the html like:

<input type="text" onblur="val_Length(this.value, this.value.length)" />

In your original statement, the resulting (incorrect) html would have been something like:

<input type="text" onblur="val_Length(,0)"/>

Since MotherTongueTxtBox.Text and .Length would have been string.empty and 0 respectively (unless it already had initial values...)

EDIT:

Thanks for marking as solution. Just as a side note, one thing you may want to consider, is you don't need to pass this.value.length in as a parameter, since you're already passing in this.value. You could determine the length within your function. Just an idea though like this:

MotherTongueTxtBox.Attributes.Add("onblur","val_Length(this.value, 'Hi')");

And then in your javascript function:

function val_Length(value, myString) {

    var length = value.length;

    ....

}
Sign up to request clarification or add additional context in comments.

2 Comments

friend i need to pass a string value too , along with other parameters
MotherTongueTxtBox.Attributes.Add("onblur","val_Length(this.value,"hi",this.value.length)"); here am passing a string"hi" along with it now is the syntax correct

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.