Javascript form

This is a discussion on "Javascript form" within the JavaScript Forum section. This forum, and the thread "Javascript form 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 31st, 2004, 22:21
New Member
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Javascript form

I was hoping that someone will be able to help.

What I need is a webpage example of a form whereby the user selects a radio button or dropdown box. Then a reply is provided by whatever means available with a different reply depending on the option selected from the radio buttons or menu.

eg. Radio buttons Football
Rugby
Tennis

Once selected a reply will appear depending on the choice made. Thanks in advance for any help.

  #2 (permalink)  
Old Jun 1st, 2004, 08:42
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
Have a look at the javascript examples over at http://www.irt.org

Im sure they have an article on a dynamic javascript form.
  #3 (permalink)  
Old Jun 1st, 2004, 10:56
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,620
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
the same question was asked just a few weeks ago...
have a look at this:
http://www.webforumz.com/topic.asp?TOPIC_ID=1291

or, if you have any scripting knowledge,this should do:
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)
Closed Thread

Tags
javascript, form

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
Login form using JavaScript and XML niceman JavaScript Forum 2 Apr 1st, 2008 12:44
Javascript Form SH77 JavaScript Forum 1 Mar 23rd, 2007 17:52
Javascript Form error drappendix JavaScript Forum 4 Jan 5th, 2007 00:53
form submission with Javascript ktsirig JavaScript Forum 1 Dec 18th, 2006 21:16
JavaScript 'contact us' form pagey JavaScript Forum 1 Jan 9th, 2006 16:32


All times are GMT. The time now is 23:57.


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