Dinesh Kumar
Dinesh Kumar

Reputation: 1499

vb.net passing a value of text box in javascript function

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

Upvotes: 0

Views: 1856

Answers (1)

KP.
KP.

Reputation: 13730

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;

    ....

}

Upvotes: 2

Related Questions