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
67 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 52

Expert Comment

by:Julian Hansen
ID: 41833681
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
ID: 41834276
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
ID: 41836769
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 52

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41836834
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
ID: 41836855
Perfect explained.

Thank you for assistance!
0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 41836990
You are welcome.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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)

914 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

17 Experts available now in Live!

Get 1:1 Help Now