Clearing input field value and getting back the same
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 01:44 AM
Hi Everyone!
I have a requirement to clear an input field value using a button and get the same value with the click of another button.
Basically, I have one Input field and two buttons(click1 and click2).
When I click the click1 button, the value is getting cleared but when I click the click2 button, it is showing true instead of the value, could anyone please guide me?
c.click = function(){
c.filterName = '';
}
c.clicks = function(){
c.filterName = !'';
}
<input ng-model="c.filterName" >
<button ng-click = "c.click()">Click 1</button>
<button ng-click = "c.clicks()">Click 2</button>
I have tried the above code, it is working but I want the exact value and not the boolean value.
Thanks
Srinivas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 04:41 AM
Hi @Srinivas_S ,
c.click = function(){
c.currentVal = c.filterName;
c.filterName = '';
}
c.clicks = function(){
c.filterName = c.currentVal;
}
Try this code.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 08:58 PM
Hi @SudhirG, thanks for the update!
The above code is working only when we click the first button click and then the second button clicks.
If I click the second button first by name clicks and then the first button by name click, it again clears the value and shows boolean value.
It is working only when I click first button and then the second button.
Could you please guide me with this issue?
Thanks
Srinivas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 09:41 PM
Try this one
c.click = function() {
c.filterName = '';
}
c.clicks = function() {
alert("Input value: " + c.filterName);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 09:55 PM
Hi @Rahul Mane2, thanks for the update, but I wanted to update on the input field only so I cannot try with an alert message. I have given HTML as well.
Thanks
Srinivas