tags:

views:

18

answers:

1

Hi I got a couple of textboxes, they got title and value set to the same default, like value="email", title="email". On button click if the value is the same as title it suppose to remove the value (for a validation i do) and so far so good cause it does. How ever the problem is comes when I have pressed the button once. When I lets say did not write a email in the contact form but I did write a message. this is the steps

1.Postback
2.The validation say - please enter a email
3.message textbox still got the value of the message written as before AND title is still "message"
4.I write a email
5.press button
6.it clears the message textbox as its value is the same as title

this is the jquery code I use for that, can you see anything that would cause this?

$(".button2").focus(function() {
    $tb = $(".textboxjquery");
    if ($tb.val($tb.title)) {
        $tb.val("");
    }
});
+2  A: 

I am not sure whether I got your question correctly but with this

if ($tb.val($tb.title))

you set the value of the textfield to $tb.title.
I think you want

if ($tb.val() == $tb.attr('title')) // check for equality
Felix Kling
well I tried that code before and it don't work. because the val is title but it act like its not. I have debug this with firebug and val is (function()) and title is (undefined)
Dejan.S
@Dejan.S: Sorry my mistake, use `$tb.attr('title')` to access the `title` attribute. In general, use `attr()` to access any attribute of elements.
Felix Kling
Yea that's it I can not understand how I missed that in the documentation. Thanks Felix Kling
Dejan.S