0

hello, iam very new in jQuery. Need help asap please. on my asp.net page I want to use two jQuery functions.

1. Clears textBox when user clicks on it.
2. Clears all inputs when user clicks on btnCancel button.

I made two functions

//clears value from onclicked input
        $(document).ready(function () {
            $("input").click(function () {
                $(this).val(""); //clears value from onclicked input
            });
        });

        //Clears all when reset button is pressed
        $(document).ready(function () {
            $("#btnCancel").click(function () {
                $('input').val("");
            });
        });

The problem that this code won't work together. Perhaps I do not combine it in the right way? Please help!

Edited by Nfurman: n/a

3
Contributors
10
Replies
11
Views
6 Years
Discussion Span
Last Post by pritaeas
0

Dumb question but are you sure you gave the cancel button an id of btnCancel?

Also you should have that first function check to see if the user has entered text. You should also change .click to .focus on the first function because if for some reason they click the input field even if it is focused it will erase the text.

Edited by xylude: n/a

0

Check the ID as xylude states. ASP.NET changes them when you run you're page. You're better off using a class.

0

thank you for answer

function check to see if the user has entered text.

No need because textbox already has value (hint what is this)

You should also change .click to .focus on the first function because if for some reason they click the input field even if it is focused it will erase the text.

Changed. It works the same way. At least in Safari. What is strange for me...is why they won't work toger. I mean when they stay like now none of them work.

P.S The jQuery placed in masterpage. in <head> section.

0

Check the ID as xylude states. ASP.NET changes them when you run you're page. You're better off using a class.

Pardon, what's that?

0

xylude hinted on the id of your link.

I noticed when working with asp.net and jquery that using a class to reference items, instead of their id, often works better.

0

xylude hinted on the id of your link.

I noticed when working with asp.net and jquery that using a class to reference items, instead of their id, often works better.

can you give me an example?

0

Add class="btnCancel" to your link and use $(".btnCancel").click(...); Also, though not a problem, one document ready function will suffice.

Edited by pritaeas: n/a

0

Add class="btnCancel" to your link and use $(".btnCancel").click(...); Also, though not a problem, one document ready function will suffice.

<asp:Button ID="btnCancel" runat="server" CssClass="btnCancel" Text="בטל" />

this is the code of my button. Do you mean to add class="btnCancel" ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.