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
69 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 55

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 55

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 55

Expert Comment

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

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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)

808 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