开发者

Problems with checking textbox val with textbox title

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("");
    }
});


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜