JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 5th, 2008, 09:39 AM
brandonryall brandonryall is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 1 brandonryall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 33 sec
Reputation Power: 0
Need some quick help

I'm having some issues retrieving a single variable...

i have a drop down box part of a form control a div layer that shows once the drop down has been changed.

The variables in the drop down change are for the layer id and the value of the town.

My issue is getting the town id pulled over to the div layer's link.

This is the code for the switch which is in my head.
Code:
Code:
<script language="javascript">
function showhide(id,towns){
var town = towns;
   if (document.getElementById){
   obj = document.getElementById(id);
      if (obj.style.display == "none"){
         obj.style.display = "";
      } else {
         obj.style.display = "";
      }
   }
}
</script>



Here is my div currently where I am trying to pull the town id:
Code:

Code:
        <div style="display: none;" id="script">
         <img src="sac.jpg" border="0"><br>
         <script language="javascript">document.write(town);</script><input type="button" name="category4" value="40" onClick="submitform();"> BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH
         <br><br>
         </form>
         </div>



Anybody have a suggestion?

Reply With Quote
  #2  
Old May 5th, 2008, 12:48 PM
Ebot's Avatar
Ebot Ebot is offline
Meatball Surgeon
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Elbow deep in code
Posts: 1,040 Ebot User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Ebot User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Ebot User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Ebot User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Ebot User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Ebot User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Ebot User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Ebot User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Ebot User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Ebot User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Ebot User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 10015 Folding Title: Novice Folder
Time spent in forums: 1 Week 3 Days 3 h 37 m 17 sec
Reputation Power: 462
Am i reading this line right?

if (document.getElementById){

and where are you defining obj?

and what is the pont of var town = towns;?
__________________
The liver is evil and must be punished!

Reply With Quote
  #3  
Old May 5th, 2008, 01:12 PM
GameYin GameYin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Whiteford, MD
Posts: 348 GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level)GameYin User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 11 h 54 m
Warnings Level: 5
Reputation Power: 60
Send a message via AIM to GameYin
MySpace
Quote:
<script language="javascript">document.write(town)


It would be so much easier to just write out towns. That's just worthless coding there. Also, if javascript is turned off. Bye bye to that.
__________________
Adwords Professional
You can give me

Reply With Quote
  #4  
Old May 6th, 2008, 04:32 AM
Joseph Taylor's Avatar
Joseph Taylor Joseph Taylor is offline
Text Ninja
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2005
Location: Vancouver, British Columbia, Canada
Posts: 596 Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level)Joseph Taylor User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 1 h 12 m 43 sec
Reputation Power: 107
Send a message via Skype to Joseph Taylor Send a message via XFire to Joseph Taylor
I noticed several problems.
  1. You seem to be trying to expose "town" as a global variable.
  2. Yes, I ended the above point exactly as intended. Global variables are uncool. Also, you're doing it wrong. Preceding a variable instantiation with "var" will make it scope local. Drop the "var" keyword, and it becomes one of those yucky global variable things.
  3. <script language="javascript">document.write(town);</script> I hope you're not expecting that code to update itself after subsequent calls to showhide. If you call document.write() after a page is loaded, it will wipe the contents of the page and output the first argument. You probably wanted the DOM.
  4. If I were a JavaScript compiler, I'd optimize this:
    Code:
          if (obj.style.display == "none"){
             obj.style.display = "";
          } else {
             obj.style.display = "";
          }
    to this:
    Code:
    obj.style.display = "";
    Thankfully, I'm not a JavaScript compiler, and my gray matter is telling me that what you really meant is this:
    Code:
          if (obj.style.display == "none"){
             obj.style.display = "";
          } else {
             obj.style.display = "none";
          }

Last edited by Joseph Taylor : May 6th, 2008 at 04:34 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Need some quick help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway