PDA

View Full Version : Changing HTML Content with JavaScript


nystagmus
05-15-2003, 08:18 PM
Hello,

I'm not sure if JavaScript would be the easiest way to do this or not, but let me give a description of what I'm trying to accomplish.

On my company site, I have a feedback section where customers can put in their name, address, etc. I recently realized that I forgot to include an input for their country.

I have created a table with that has the label "Country" and then a drop-down selection to the right with the choices of "United States" and "Other". I have that accomplished.

I would then like to make a JavaScript event handler that will write "City", "State", and "Zip Code" sections onto the page when the user selects the U.S. as their country. If not, I want it to just leave everything normal so the user can put information into the "Address" section. If the user has already selected the U.S. but then selects Other, the code needs to remove the city, state, and zip code sections.

I would like to do this with document.write() etc., but I don't know how to invoke it when the user makes their selection.

Suggestions, comments, or code will be GREATLY appreciated.

Thanks for your time,

- Tim

P.S. - You may visit the work in progress at the following link. The borders are to aid me in lining the tables up correctly and will be removed when the page is completed.

http://www.cruisersplus.com/feedbacktest.htm

P.S.S. - I can use PHP or Perl if need be. It doesn't have to be JavaScript, but that is what I'm leaning towards at the moment. I'm at a stuck spot, so I'll just wait for responses.

stuka
05-16-2003, 12:38 PM
PHP and Perl won't do what you want to do without an extra round trip to the server. You'll have to rely on client-side scripting (like javascript) for this.

nystagmus
05-16-2003, 10:35 PM
What's wrong with the script having to make a trip to the server?

It doesn't really matter. I figured JavaScript would be easier and more convenient for the coder and the user anyway.

Thanks for the advice though.

If anyone else has any suggestions they would be greatly appreciated.


- Tim

stuka
05-27-2003, 11:26 AM
<disclaimer>I don't deal with JavaScript at all</disclaimer>
I suspect the easiest/best way to do this would be to create an invisible layer, and have the JavaScript make it visible if the user selects "United States" in the drop down box.

jamessan
05-27-2003, 01:05 PM
If all you're going to do is making something visible when that selection is made, I think it can be done with CSS (I recall someone doing the menus for their site in a similar fashion). Only problem would be the possibility of browsers not handling it correctly. Also, I'm not positive that it would actually work with the drop-down boxes, but it's worth a try. Here's a couple links to show you to what I'm referring:
http://www.howtocreate.co.uk/tutorials/testMenu.html
http://www.meyerweb.com/eric/css/edge/menus/demo.html

Coliver
04-21-2004, 02:49 AM
You might consider DHTML. This can help you automatically change your form.