[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 01-03-2007, 04:26 AM   #1 (permalink)
NamePros Regular
 
asgsoft's Avatar
 
Join Date: Sep 2005
Location: At Home
Posts: 846
45.10 NP$ (Donate)

asgsoft is just really niceasgsoft is just really niceasgsoft is just really niceasgsoft is just really niceasgsoft is just really nice


Show and hide a textfield based on a selectbox

I am using this JS to show and hide a textbox when the value for the select box changes.

It shows the textbox alright, but when I want to hide it it won't.

Here is what I have:

Code:
function showField(email_div)
{
 var txt = "";
 if(document.form1.type.value = "Banner Impressions")
 {
   txt += "<p>Banner Location:<input type='text' name='bannerloc' value='<?php echo $firstname; ?>' onfocus=\"this.value='';\" /></p>";
 document.getElementById(email_div).innerHTML = txt;
 }
 else
 {
 txt = null;
  document.getElementById(email_div).innerHTML = nill;
 }

}
Where have I gone wrong?
asgsoft is offline  
Old 01-03-2007, 04:37 AM   #2 (permalink)
Stud Sausage
 
Join Date: Dec 2006
Location: England
Posts: 1,546
34.41 NP$ (Donate)

Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of

Adoption Breast Cancer Breast Cancer Cancer Survivorship
Hi asgsoft. Can i assume email_div is the layer you wish to hide?

Technically you are not hiding anything here, in affect you are you are removing it. Remember that is is null not nill btw

PHP Code:
function showField(email_div)
{
    if(document.form1.type.value = "Banner Impressions")
    {
          var txt = '<p>Banner Location:<input type="text" name="bannerloc" value="<?php echo $firstname; ?>" onfocus="this.value=\'\';" /></p>';
        document.getElementById(email_div).innerHTML = txt;
    }
    else
    {
          document.getElementById(email_div).innerHTML = null;
          /*     This line would actually *hide* the div instead of erasing the contents
          @    document.getElementById(email_div).style.display = 'none';
          */
    }
}
Try that. If not can your provide an example of how you are using this please.
__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline  
Old 01-03-2007, 04:40 AM   #3 (permalink)
NamePros Regular
 
asgsoft's Avatar
 
Join Date: Sep 2005
Location: At Home
Posts: 846
45.10 NP$ (Donate)

asgsoft is just really niceasgsoft is just really niceasgsoft is just really niceasgsoft is just really niceasgsoft is just really nice


It still doesn't hide the div.
asgsoft is offline  
Old 01-03-2007, 04:51 AM   #4 (permalink)
Stud Sausage
 
Join Date: Dec 2006
Location: England
Posts: 1,546
34.41 NP$ (Donate)

Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of

Adoption Breast Cancer Breast Cancer Cancer Survivorship
Quote:
Originally Posted by Matthew.
Try that. If not can your provide an example of how you are using this please.
__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline  
Old 01-03-2007, 05:07 AM   #5 (permalink)
NamePros Regular
 
beaver6813's Avatar
 
Join Date: May 2005
Location: England
Posts: 349
65.50 NP$ (Donate)

beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough


Smile

Code:
function showField(email_div) 
{ 
    if(document.form1.type.value = "Banner Impressions") 
    { 
          var txt = '<p>Banner Location:<input type="text" name="bannerloc" value="<?php echo $firstname; ?>" onfocus="this.value=\'\';" /></p>'; 
        document.getElementById(email_div).innerHTML = txt; 
        document.getElementById(email_div).style.display = 'block';
     } 
     else 
     { 
          document.getElementById(email_div).style.display = 'none';
     } 
}
If the value is Banner impressions it will fill email_div with the txt and make the div display and show. If it isn't then the div will not display and will be hidden.
__________________
-Beaver6813.com V5 Soon!
beaver6813 is offline  
Old 01-03-2007, 05:28 AM   #6 (permalink)
NamePros Regular
 
asgsoft's Avatar
 
Join Date: Sep 2005
Location: At Home
Posts: 846
45.10 NP$ (Donate)

asgsoft is just really niceasgsoft is just really niceasgsoft is just really niceasgsoft is just really niceasgsoft is just really nice


Still doesn't work.

Here is a link http://asgsoft.net/form/form.php
asgsoft is offline  
Old 01-03-2007, 05:41 AM   #7 (permalink)
Stud Sausage
 
Join Date: Dec 2006
Location: England
Posts: 1,546
34.41 NP$ (Donate)

Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of

Adoption Breast Cancer Breast Cancer Cancer Survivorship
Right that helped

Look at your option again:
Code:
<option value="banner">Banner Impressions</option>
See the value is actually banner not Banner Impressions, so we change this line:
Code:
if(document.form1.type.value = "Banner Impressions")
To:
Code:
if(document.form1.type.value == "banner")
(also note the == which we both missed)

PHP Code:
function showField(email_div)
{
    if(
document.form1.type.value == "banner")
    {
          var
txt = '<p>Banner Location:<input type="text" name="bannerloc" value="" onfocus="this.value=\'\';" /></p>';
        
document.getElementById(email_div).innerHTML = txt;
        
document.getElementById(email_div).style.display = 'block';
     }
     else
     {
          
document.getElementById(email_div).style.display = 'none';
     }
}
__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline  
Old 01-03-2007, 07:41 AM   #8 (permalink)
NamePros Regular
 
asgsoft's Avatar
 
Join Date: Sep 2005
Location: At Home
Posts: 846
45.10 NP$ (Donate)

asgsoft is just really niceasgsoft is just really niceasgsoft is just really niceasgsoft is just really niceasgsoft is just really nice


thanks a lot. That's fixed now.

Can you have a look at the price section?

http://asgsoft.net/form/form.php

It should make the price change, it only works when i have one price set, when I have all of them then it doesn't work.


Where have i gone wrong?

Last edited by asgsoft; 01-03-2007 at 08:00 AM.
asgsoft is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 07:46 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85