how to clear data attribute from input using javascript - javascript

How do I clear the userid attribute of a specific input field? Even when I clear the field the userid is not cleared, because I am fetching the data on the basis of the ID in input field of the textbox, it also fetches the data of the userid which is not present in the textbox because it gets stored and is removed only after refresh(f5).
<input id="inputField_0"
type="text"
class="inputClass ui-autocomplete-input"
autocomplete="off"
userid="10018" />

You can leverage jQuery's removeAttr method.
$("#inputField_0").removeAttr("userid");
Or if you need a vanilla JS option, you can leverage the element's removeAttribute method.
document.getElementById("inputField_0").removeAttribute("userid");

You can remove userid attribute from input field using JQuery.
Try the below link.
Visit [https://jsfiddle.net/gmk9zotq/3/]

Related

How to fill a form field with no id or class using imacros?

I am working on a website I need to submit a lot of data so I am using imacros to fill but one field remains blank. This is because it has no id or class and has a changeable "name". This value can change on every reload.
How do I fill this field with imacros.
<input value="" size="20" max-length="6" name="122637" type="text">
I hope using XPATH will solve you problem.. Find the Xpath of that field, and use it in the TAG, like below
TAG XPATH="//form[#id='demo']/fieldset[1]/ol/li[1]/input[1]" CONTENT="Gulam"
I don't know how imacros works, but try matching against all attributes
document.querySelector('input[value][size="20"][max-length="6"][type=text]')

How to maintain two values of single field in html

I have a requirement, where i need to show rounded decimal value for the fields in the page. But if user doesn't change the field's value then i need to post the original value of field instead of rounded value and my external library will be called with this posted values.
For example if a have a field 'Initial Temperature' and its value 12.892433 in database, when i populate the field in the page it will be 12.9. Now if user doesnt change this value then i need to post the actual value which is 12.892433.
Can anyone suggest me the best way to do this. I dont want to pull data from the database once i have the posted data.
You can use the data-* attribute, which is used to store custom data private to the page. For example:
<span id="span" data-val="12.892433">12.9</span>
And you can get the value with JS:
var value = $("#span").data("val");
And if you want the value on the server side you can use an input hidden, something like this:
<input type="hidden" name="value" id="value" value="12.892433">

Hide an input value on the Front end While maintaining the value on the Back

I am trying to hide an input value. I want to use an input text type as sort of a password input field. I dont want the values to be displayed though. How to go about hiding the value after an insertion has been made? I would like the values to be hidden.
I have tried a few methods but no luck. I still need to access this in jquery/AJAX so I can pass it into SQL for password verification. Any help is most appreciated. Thanks
HTML
<input type=text id=num1 onclick="hideValue()">
Javascript
function hidevalue(){
document.getElementById('num1').value.visibility="hidden";
}
You just need to tell it theat it is a password field.
<input type="password" id="num1">
Use field type as password to mask entry made by user.
To hide that field on click use the following in the function
document.getElementById('num1').style.display = 'none';

Capture browser cached data dropdown onclick

I'm having some problems adding a dropdownlist with ajax and stuff using jQuery. When you click or you type on the input text a method creating the jQuery dropdownlist will be called. However if you already submitted this form, when you type you get the typical browser simple dropdown with previous submitted data. I'm having a hard time figuring what event do trigger clicking in that dropdownlist element.
Just add
autocomplete="off"
attribute to your input fields, for example:
<input type="text" name="myField" autocomplete="off">

(Javascript) Can i set "autocomplete=off" for Single Inputbox?

Inside a <form> I want to use multiple Password type fields but.. I want to make some of them not to be remembering the value of it.
Normally i can use autocomplete=off inside <form> tag.
But this affects over every single fields inside.
Edited: Got Simple Solution Now
<input autocomplete="off" ....... />
Yes, you can (set autocomplete="off" on individual inputs).
You can set autocomplete on a single field by using:
#Html.TextBoxFor(x => x.Property, new {autocomplete = "off"})
If you're using DisplayForModel than you will have to create a custom Edit Template.
You can set it on individual fields, but it's a non-standard HTMl extension and will cause your pages to fail validation: Is there a W3C valid way to disable autocomplete in a HTML form?

Categories