Link to home
Start Free TrialLog in
Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil

asked on

Could you point how to make a control initially not visible to be presented since it has a value?

Hi Experts

Could you point how to make a control initially not visible to be presented since it has a value?

 <div class="col-xs-4 mb20 custo" style="display: none;">
	<label for="custo" class="field-label text-muted mb10">Custo</label>
	<div class="input-group">
		<span class="input-group-addon">
			<i class="fa fa-money c-gray"></i>
		</span>
		<span class="validar">
			<input type="text" name="custo" class="custo form-control gui-input br-light light" placeholder="">
		</span>
	</div>
</div>
</div>

Open in new window


Then in jQuery - the value isn't presented.
if ($('.custo').val()) $('.custo').show();   

Open in new window


Any workaround?

Thanks in advance.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

if ($('.custo').val() == '') $('.custo').show();

Open in new window

BUT
Be careful because your selector is a class. If you have two controls with class .custo then the above will check the first one - and if it is blank will show all of them
Consider these two examples
HTML 1
  <input type="text" class="test" style="display: none" value="3" />
  <input type="text" class="test" style="display: none" />

Open in new window

HTML 2
  <input type="text" class="test2" style="display: none" />
  <input type="text" class="test2" style="display: none" value="3" />

Open in new window

jQuery
$(function() {
  if ($('.test').val() == '') $('.test').show();
  if ($('.test2').val() == '') $('.test2').show();
});

Open in new window

In the first both will be hidden.
In the second both will be visible.
Working sample here
Avatar of Eduardo Fuerte

ASKER

Hi

I use the textbox as a class in 02 modals - since the values will be the same, no matter.

Accordingly to:
User generated image

 if ($('#edit. custo').val() != '0')
         {
            $('#edit .custo').show();
         }
    else 
    {
        $('#edit .custo').hide(); 
    }

Open in new window

Hi Julian

After a better read on you example.
Just one thing that confused me a little.

The value must be presented if it has a value and doesn't if it hasn't a value.

So the comprehension must to be inverted.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect explained.

Thank you for assistance!
You are welcome.