NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Show and hide a textfield based on a selectbox

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 01-03-2007, 05:26 AM THREAD STARTER               #1 (permalink)
NamePros Regular
 
asgsoft's Avatar
Join Date: Sep 2005
Location: At Home
Posts: 881
asgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of light
 



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, 05:37 AM   #2 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
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;
????: NamePros.com http://www.namepros.com/programming/276316-show-and-hide-textfield-based-selectbox.html
          /*     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.
Matthew. is offline  
Old 01-03-2007, 05:40 AM THREAD STARTER               #3 (permalink)
NamePros Regular
 
asgsoft's Avatar
Join Date: Sep 2005
Location: At Home
Posts: 881
asgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of light
 



It still doesn't hide the div.
asgsoft is offline  
Old 01-03-2007, 05:51 AM   #4 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
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
Originally Posted by Matthew.
Try that. If not can your provide an example of how you are using this please.
Matthew. is offline  
Old 01-03-2007, 06:07 AM   #5 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 





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 is offline  
Old 01-03-2007, 06:28 AM THREAD STARTER               #6 (permalink)
NamePros Regular
 
asgsoft's Avatar
Join Date: Sep 2005
Location: At Home
Posts: 881
asgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of light
 



Still doesn't work.

Here is a link http://asgsoft.net/form/form.php
asgsoft is offline  
Old 01-03-2007, 06:41 AM   #7 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
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
????: NamePros.com http://www.namepros.com/showthread.php?t=276316

    if(
document.form1.type.value == "banner"
    { 
          var 
txt '<p>Banner Location:<input type="text" name="bannerloc" value="" onfocus="this.value=\'\';" /></p>'
????: NamePros.com http://www.namepros.com/showthread.php?t=276316
        
document.getElementById(email_div).innerHTML txt
        
document.getElementById(email_div).style.display 'block';
     } 
     else 
     { 
          
document.getElementById(email_div).style.display 'none';
     } 

Matthew. is offline  
Old 01-03-2007, 08:41 AM THREAD STARTER               #8 (permalink)
NamePros Regular
 
asgsoft's Avatar
Join Date: Sep 2005
Location: At Home
Posts: 881
asgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of lightasgsoft is a glorious beacon of light
 



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 09:00 AM.
asgsoft is offline  
Closed Thread


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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 10:34 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger