Neo
Neo

Reputation: 16219

how to clear textbox value on other textbox focus in jquery?

I want to clear a 2nd textbox value when i'm doing focus (or changing value) of 1st textbox using jquery ?

I'm trying to use

 $(document).ready(function () {
validateFocus();
});

function validateFocus() {
    $('#1stTextBox').focus(function () {
        $('2nsTextBox').val('');
    });
}

not working for me help me to correct me thanks

Upvotes: 0

Views: 519

Answers (6)

Somnath Kharat
Somnath Kharat

Reputation: 3610

you have missed the selector here $('2nsTextBox').val('');

function validateFocus() {
    $('#1stTextBox').focus(function () {
        $('#2nsTextBox').val('');// may be # if its id, no need to tell u other selectors by seeing ur rep
    });
}

Upvotes: 0

Shakti Patel
Shakti Patel

Reputation: 3862

can you please check this demo :

[jsfiddle.net/malvaniya_shakti/V25g5/4/][1]

Upvotes: 0

Indra Yadav
Indra Yadav

Reputation: 600

Try this

$(document).ready(function(e) {
$('#txt1').focus(function() {

  $('#txt2').attr('value','');
});

});

Upvotes: 2

See if this works.

$(input[id$='firsttextboxid']).focus(function() {
  $("#secondtextboxid").val('');
  });

Upvotes: 0

Nadeem_MK
Nadeem_MK

Reputation: 7689

The question is quiet unclear.. If you want to clear another textbox, you can simply call it as you did for the txtDate;

if(!checkDate($("#txtDate").val()))
{

$("#txtDate").val("");
$('#txtDate').focus();

$("#Your2ndTextBox").val("");
}

This should be enough..

Upvotes: 0

Dilip Godhani
Dilip Godhani

Reputation: 2174

if(!checkDate($("#txtDate").val()))
          {

            $("#txtDate").val("");
            $('#txtDate').focus();
           }

you forgot # on this $("txtDate").val()

Upvotes: 0

Related Questions