Need help customizing existing DHTML code.

This is a discussion on "Need help customizing existing DHTML code." within the JavaScript Forum section. This forum, and the thread "Need help customizing existing DHTML code. are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old May 13th, 2004, 19:15
Junior Member
Join Date: May 2004
Location: Kansas City
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Need help customizing existing DHTML code.

Here is the link where DHTML is use at; http://www.waitnot.com/CustHtml/HotWater/howtobuy.htm then take a look at the drop down. This is a really nice feature where you click on the dropdown choice then the address of that city opened up.

Now for mine customized version of it I would like to be able to have two drop down choices for example.

1st drop down choices will have list of States.
2nd drop down will coinside with which States I pick, which show the list of the cities.
Then once you piced that city you get the addresses information display.

Can someone help me with this. I'm not a programmer, but can decipher very well I'm a copy and paste type. Please advise if you can. Thanks.

  #2 (permalink)  
Old May 13th, 2004, 22:18
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,612
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
this should do...
the script is really simple and I coded it in record time but it can always be improved in the future if necessary.

you can copy the code below and save it as a html file so you'll be able to see the script in action, plus it has the basic instructions of what to do....

let me know if you need help.

Code: Select all
<SCRIPT language="JSCript">
/* BEGIN BROWSER HANDLING, DON'T TOUCH */
isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;
function getObj(elementName){
  if(isNS4){ return document.layers[elementName]; }
  else if (isIE4 || isIE5){ return document.all(elementName); }
  else if (isNS6){ return document.getElementById(elementName); }
}
function Show(id){ if(getObj(id)){ getObj(id).style.display = 'block'; } }
function Hide(id){ if(getObj(id)){ getObj(id).style.display = 'none'; } }
/* END BROWSER HANDLING */

/*
we'll need to remeber which item we display so that
we can hide it later on, when we want to display a different item
*/
var previous_state; // this var will hold the id of the current state
var previous_city; // this var will hold the id of the current city

// this function will display a list of cities according to their state
function ShowCities(state){
  this_state = "selCities_" + state;
  if(previous_state){ Hide(previous_state); }
  if(previous_city){ Hide(previous_city); }
  Show(this_state);
  previous_state = this_state;
}

// this function will display the address according to the chosen city
function ShowAddress(city){
  this_city = "divAddress_" + city;
  if(previous_city){ Hide(previous_city); }
  Show(this_city);
  previous_city = this_city;
}
</SCRIPT>

<table width=100% border=1 cellspacing=5>
  <tr>
    <td valign=top width=33%>
      <select name="state" id="state" onChange="ShowCities(this.value);">
        <OPTION value="NY">New York</OPTION>
        <OPTION value="LA">Los Angeles</OPTION>
      </select>
      <HR>
      this list holds all the states.
      we''l use thbe value of this list to display the cities
    </td>
    <td valign=top width=33%>
      <select id="selCities_NY" onChange="ShowAddress(this.value);" style="display:none;">
        <OPTION value="City1">City 1</OPTION>
        <OPTION value="City2">City 2</OPTION>
        <OPTION value="City3">City 3</OPTION>
        <OPTION value="City4">City 4</OPTION>
        <OPTION value="City5">City 5</OPTION>
      </select>
      <select id="selCities_LA" onChange="ShowAddress(this.value);" style="display:none;">
        <OPTION value="City6">City 6</OPTION>
        <OPTION value="City7">City 7</OPTION>
        <OPTION value="City8">City 8</OPTION>
        <OPTION value="City9">City 9</OPTION>
      </select>
      <HR>
      the list of cities will show up here. you can add as many as you want, but
      you MUST set the id attribute to:
      <LI>"selCities_[state id]"
    </td>
    <td valign=top width=33%>

<div class=Address id="divAddress_City1" style="display:none;">
  NY
addres for city 1
111111111
</div>
<div class=Address id="divAddress_City2" style="display:none;">
  NY
addres for city 2
222222222
</div>
<div class=Address id="divAddress_City3" style="display:none;">
  NY
addres for city 3
33333333
</div>
<div class=Address id="divAddress_City4" style="display:none;">
  NY
addres for city 4
44444444
</div>
<div class=Address id="divAddress_City5" style="display:none;">
  NY
addres for city 5
55555555
</div>
<div class=Address id="divAddress_City6" style="display:none;">
  LA
addres for city 6
66666666
</div>
<div class=Address id="divAddress_City7" style="display:none;">
  LA
addres for city 7
7777777
</div>
<div class=Address id="divAddress_City8" style="display:none;">
  LA
addres for city 8
88888888
</div>
<div class=Address id="divAddress_City9" style="display:none;">
  LA
addres for city 9
99999999
</div>
      <HR>
      the addresses will show up here. you can add as many as you want, but
      again, you MUST set the id attribute to:
      <LI>"divAddress_[state id]"
    </td>
  </tr>
</table>
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
  #3 (permalink)  
Old May 14th, 2004, 13:40
Junior Member
Join Date: May 2004
Location: Kansas City
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Man! you are geat spinal007, Thank you sooo much.. I'll make sure to put this code in good use. Thanks a bunch
  #4 (permalink)  
Old May 15th, 2004, 12:09
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,612
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
no worries...
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Closed Thread

Tags
help, customizing, existing, dhtml, code

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Validate Radio Buttons in Existing Code dawgmom JavaScript Forum 6 Jun 3rd, 2008 23:20
help with customizing drop down menus bama Starting Out 7 Apr 24th, 2007 01:35
Hello to existing members! AndyJones Introduce Yourself 3 Sep 18th, 2006 15:26
Customizing table rows AdRock Web Page Design 2 Aug 28th, 2006 09:28
Customizing a certain JavaScript salawi JavaScript Forum 2 May 18th, 2006 19:42


All times are GMT. The time now is 10:29.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

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