- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2018 08:58 PM
i have a field which should have mandatory symbol (*) and when i enter the values it should change from red to grey..
<label>Name : </label>
<input type="text" ng-model="name" id="demo" />
can i use it for the above the code...without using jelly script
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2018 12:24 AM
Here is the full code
HTML
<label for="input1" id="inputLabel" >Name</label>
<input type="text" ng-model="name" onchange="checkMandatory()" id="demo" />
Client script
document.getElementById('inputLabel').setAttribute("class", "required");
function checkMandatory(){
if(document.getElementById('demo')!="")
document.getElementById('inputLabel').setAttribute("class", "notrequired");
}
css
label.required::before {
content: '*';
margin-right: 4px;
color: red;
}
label.notrequired::before {
content: '*';
margin-right: 4px;
color: grey;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2018 11:29 PM
Hi,
HTML
<label for="input1" id="inputLabel" >Name</label>
<input type="text" ng-model="name" id="demo" />
css
label.required::before {
content: '*';
margin-right: 4px;
color: red;
}
label.notrequired::before {
content: '*';
margin-right: 4px;
color: grey;
}
client script
document.getElementById('inputLabel').setAttribute("class", "required");// when empty
document.getElementById('inputLabel').setAttribute("class", "notrequired");// when it has value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2018 11:43 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2018 11:52 PM
That is correct behaviour.
You will run the 'notrequired' code only if that field has some value.
below won't go together.
document.getElementById('inputLabel').setAttribute("class", "required");// when empty
document.getElementById('inputLabel').setAttribute("class", "notrequired");// when it has value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2018 11:57 PM
i used the below code
it didnt work
if(gel(inputLabel).value=="")
{
gel('inputLabel').setAttribute("class", "required");
}
else
{
gel('inputLabel').setAttribute("class", "notrequired");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2018 12:01 AM
Hi,
You are using wrong document id. inputLabel is id of the label, which will never have the value however, demo is the correct id of the element which is type input.
if(gel(demo).value=="")
{
gel('inputLabel').setAttribute("class", "required");
}
else
{
gel('inputLabel').setAttribute("class", "notrequired");
}