Solved

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

Posted on 2016-10-07
6
61 Views
Last Modified: 2016-10-10
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.
0
Comment
Question by:Eduardo Fuerte
  • 3
  • 3
6 Comments
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
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
0
 

Author Comment

by:Eduardo Fuerte
Comment Utility
Hi

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

Accordingly to:
img001

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

Open in new window

0
 

Author Comment

by:Eduardo Fuerte
Comment Utility
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.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
Comment Utility
Then == becomes != and the example output switches around but the principle is the same.

Here is the same sample with the logic inverted - does this make more sense?
0
 

Author Closing Comment

by:Eduardo Fuerte
Comment Utility
Perfect explained.

Thank you for assistance!
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
You are welcome.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now