By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,747 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,747 IT Pros & Developers. It's quick & easy.

Hide/Show PHP Values

chunk1978
100+
P: 224
hello,

i would like to know if it's possible to hide PHP values that come back empty (text fields) or have a specific value (select menus)...

on my form, there are input fields that are optional, so when the PHP processes the form, i'd like not to see a blank field with nothing written...

i'm trying to combine JavaScript with DIV displays to make this happen, but of-course, it doesn't work... i'm just a novice afterall...

this is what i have:

javascript code:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. function HideEmptyFields()
  4.     {
  5.     if (document.addressline2.value != "") {document.getElementById('DIVaddressline2').style.display == 'block';
  6.     }
  7.  
  8. </script>
  9.  
then there is an onLoad event handler on the body tag:
Expand|Select|Wrap|Line Numbers
  1. <body onload="HideEmptyFields();">
  2.  
finally... in the PHP portion of the code, i have it written like this:

Expand|Select|Wrap|Line Numbers
  1. <div id="DIVaddressline2" style="display:none;"><?php echo $_POST["addressline2"] ; ?></div><br>
  2.  
is it not possible to hide a DIV with a <?php script inside?

thanks in advance.
Feb 22 '07 #1
Share this Question
Share on Google+
7 Replies


The1corrupted
100+
P: 134
hello,

i would like to know if it's possible to hide PHP values that come back empty (text fields) or have a specific value (select menus)...

on my form, there are input fields that are optional, so when the PHP processes the form, i'd like not to see a blank field with nothing written...

i'm trying to combine JavaScript with DIV displays to make this happen, but of-course, it doesn't work... i'm just a novice afterall...

this is what i have:

javascript code:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. function HideEmptyFields()
  4.     {
  5.     if (document.addressline2.value != "") {document.getElementById('DIVaddressline2').style.display == 'block';
  6.     }
  7.  
  8. </script>
  9.  
then there is an onLoad event handler on the body tag:
Expand|Select|Wrap|Line Numbers
  1. <body onload="HideEmptyFields();">
  2.  
finally... in the PHP portion of the code, i have it written like this:

Expand|Select|Wrap|Line Numbers
  1. <div id="DIVaddressline2" style="display:none;"><?php echo $_POST["addressline2"] ; ?></div><br>
  2.  
is it not possible to hide a DIV with a <?php script inside?

thanks in advance.
Instead of functions, I tend to use more if statements, because to me functions are way too confusing to keep track of. And of course this won't work, I don't think you can embed PHP in Java, try it the other way around.
Feb 22 '07 #2

Motoma
Expert 2.5K+
P: 3,235
Take a look at the raw HTML that comes from the PHP file (in your browser, view source). Does the HTML/XHTML look correct to you? Are there any syntactical errors?
Feb 22 '07 #3

chunk1978
100+
P: 224
Take a look at the raw HTML that comes from the PHP file (in your browser, view source). Does the HTML/XHTML look correct to you? Are there any syntactical errors?
all seems fine to me (well, except for the fact that i don't see any PHP code in the view source for the .php file?)... anyway, i'm way new to PHP, and therefore it all looks good to me (eventhough it doesn't work) ;-)

any guidance would be greatly appreciated...
Feb 22 '07 #4

chunk1978
100+
P: 224
Instead of functions, I tend to use more if statements, because to me functions are way too confusing to keep track of. And of course this won't work, I don't think you can embed PHP in Java, try it the other way around.
hey The1corrupted, thanks for the reply...

how would you write something like that the other way around? i'm very new to PHP...
Feb 22 '07 #5

Motoma
Expert 2.5K+
P: 3,235
all seems fine to me (well, except for the fact that i don't see any PHP code in the view source for the .php file?)... anyway, i'm way new to PHP, and therefore it all looks good to me (eventhough it doesn't work) ;-)

any guidance would be greatly appreciated...
You need to understand how PHP works.
PHP is a program that generates HTML.
When it gets to your web-browser, it will be ENTIRELY HTML (and javascript if you include it).
To your web browser, this is no different then viewing a static HTML page (i.e. a file with a .html extension).
Feb 22 '07 #6

chunk1978
100+
P: 224
You need to understand how PHP works.
PHP is a program that generates HTML.
When it gets to your web-browser, it will be ENTIRELY HTML (and javascript if you include it).
To your web browser, this is no different then viewing a static HTML page (i.e. a file with a .html extension).
hey motoma... thanks for telling me that, its a big help... makes things for me a little more clear...
Feb 22 '07 #7

Motoma
Expert 2.5K+
P: 3,235
hey motoma... thanks for telling me that, its a big help... makes things for me a little more clear...
I hope so.
I consequence of this fact is that you can save the result of a PHP page as HTML, and tinker with it on your local machine until you find the bug in your HTML/Javascript.
Feb 22 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.