c# - Enable or Disable Button Based On TextBox.Text Text Changes - Stack Overflow

I am creating a web application for my pany. My application has a button and a textbox.What I want to d

I am creating a web application for my pany. My application has a button and a textbox.

What I want to do is entering some value into the textbox and then when i click the button the application will process the value based on the input in the textbox.

Now here is the tricky part.

After the button is clicked once and the text in textbox remains, the button shall disappear.

However if there is modification in the textbox.text, the button shall reappear.

But if the textbox.tex somehow return to original value, the button shall disappear again.

Please its quite urgent, I have tried my best to do it already, yet so far unsuccessful. I also did a lot of research in Google, but so far none of my findings suit my case.

Your help is appreciated.

I am creating a web application for my pany. My application has a button and a textbox.

What I want to do is entering some value into the textbox and then when i click the button the application will process the value based on the input in the textbox.

Now here is the tricky part.

After the button is clicked once and the text in textbox remains, the button shall disappear.

However if there is modification in the textbox.text, the button shall reappear.

But if the textbox.tex somehow return to original value, the button shall disappear again.

Please its quite urgent, I have tried my best to do it already, yet so far unsuccessful. I also did a lot of research in Google, but so far none of my findings suit my case.

Your help is appreciated.

Share Improve this question asked Nov 17, 2011 at 8:12 rofans91rofans91 3,00611 gold badges47 silver badges60 bronze badges 3
  • if you'll include the code samples the answer may be far more useful – danyloid Commented Nov 17, 2011 at 8:15
  • original value? is that the value once the button has been pressed? – david Commented Nov 17, 2011 at 8:43
  • original value of the textbox is empty, user must key in some text first. when button pressed, the value of textbox unchanged, instead it will hide the button itself, the button only showed again upon the changing in the textbox – rofans91 Commented Nov 17, 2011 at 8:50
Add a ment  | 

4 Answers 4

Reset to default 2

You got it here http://jsfiddle/ywe9G/

var ori = '';
$(document).ready(function(){
    $('button').hide();
    $('input').keyup(function(){
        if($(this).val() != ori){
                $('button').show();
        }else{
            $('button').hide();
        }
    });
    $('button').click(function(){
        ori  = $('input').val();
        $(this).hide();
    });
});
    private string oldTextboxValue = "";
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        if (textBox1.Text != oldTextboxValue)
        {
            button1.Visible = true;
        }
        else
        {
            button1.Visible = false;
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        oldTextboxValue = textBox1.Text;
        button1.Visible = false;
    }

to disable button you can do this-

var oldvalue="";
$('#buttonid').click(function(){
//your code
oldvalue = $("#textBox").text();
this.hide();
}

$("#textBoxId").keypress(function(){
if(this.value!=oldvalue){
this.show();
}
}

Demo here

HTML

<textarea id='mytext' rows='4' cols='20'></textarea>
<br>
<input type="button" id='my_button' value="click">
<input type="hidden" id="my_hidden">

jQuery

var clicked=false;
jQuery(document).ready(function() {
    $("#my_button").click(function(){
        $("#my_hidden").val($("#mytext").val());
        $(this).hide();
        clicked=true;
    });

    $("#mytext").keyup(function(){
       if(clicked==true && $(this).val()==$("#my_hidden").val()) {
           $("#my_button").hide();
       }else if(clicked==true){
           $("#my_button").show();
       }
    });

});

You can similarly enable/disable button instead of show/hide

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744792184a4593982.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信