Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 10-04-2008, 10:34 AM   #1 (permalink)
Registered User
 
Join Date: Apr 2007
Posts: 20
OS: XP Home (Service Pack 3)


What is the best method to dynamically changing form content?

I am building a form for clients to use to request a project. However, because I specialize in a wide variety of projects, the form will need to be different depending on which type of project is needed.

I thought I had this figured out with Javascript, but it doesn't seem to be working right.

I had the following Javascript code to add/remove a CSS "display:none" class called hide depending on which option was selected.

The code looked like this:

Code:
<script type="text/javascript">
	function showSelection () {
		var e, i = 0;
		while (e = document.getElementById ('projectType').options [i++]) {
			document.getElementById (e.value).className = 'hide'
		}
		document.getElementById (document.getElementById ('projectType').options [document.getElementById ('projectType').selectedIndex].value).className = '';
	}

	if (document.getElementById) onload = function () {
		showSelection ();
		document.getElementById ('projectType').onchange = showSelection;
	}
</script>
and then below it (this was in the 'body'), was:

HTML Code:
<select id="projectType">
<option selected value="none"> -- Select Project Type -- </option>
<option value="logo_design">Logo Design</option>
<option value="web_design">Web Design</option>
<option value="print">Print Design</option>
<option value="powerpoint">PowerPoint Presentation</option>
<option value="corpid">Corporate ID</option>
<option value="other">Other</option>
</select>

<p id="none"></p>

<!-- Start Logo Design Content -->
<p id="logo_design">LOGO</p>


<!-- Start Web Design Content -->
<p id="web_design">WEB</p>


<!-- Start Print Design Content -->
<p id="print">PRINT</p>


<!-- Start PowerPoint Content -->
<p id="powerpoint">POWERPOINT</p>


<!-- Start Corporate ID Content -->
<p id="corpid">CORPORATE ID</p>


<!-- Start Other Type Content -->
<p id="other">OTHER</p>
This works fine too. However, when I try adding to the <p> content (i.e. adding some radio buttons or textareas, they are displayed regardless of which option is selected.

Is there a flaw in my code, or is this not the right method to do this?

I thought maybe trying to change the src of an iframe based on what option was selected, but I'm not sure if/how that would work (i.e. where would I call the form?).

I also thought of using PHP and submitting it to itself, which would mean I would have to submit the selection before the form is displayed. This is not the most ideal way, but it would be more versatile and would definitely work, I guess.

What about a client-side include? I have never used this, but if this method would work, I am up for the challenge!

Does anyone have any suggestions? Please provide some code too.. I'm no developer!

Thanks,
Antoine

Last edited by Antoine; 10-04-2008 at 10:36 AM.
Antoine is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 10-04-2008, 10:58 AM   #2 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,884
OS: Vista, various linux distros


Re: What is the best method to dynamically changing form content?

hey what about:
Code:
Javascript:
function changeContent(projectTypeValue){
  //get a handle of the content <p> element
  var contentToChange = document.getElementById("content");
  //change it's innerHTML depending on the value input
  if(projectTypeValue=="logo_design"){
    contentToChange.innerHTML = "the html to go inside the paragraph element when logodesign is selected";
  }
//..and so on for each type

}

...
HTML:
<select id="projectType" onchange="changeContent(this.value);">
<option selected value="none"> -- Select Project Type -- </option>
<option value="logo_design">Logo Design</option>
<option value="web_design">Web Design</option>
<option value="print">Print Design</option>
<option value="powerpoint">PowerPoint Presentation</option>
<option value="corpid">Corporate ID</option>
<option value="other">Other</option>
</select>
<p id="content"><!--Starts empty --></p>
or you could use a string-indexed array to store the values:
Code:
var values = new Array();
values["none"]        = "Please select a project type above";
values["logo_design"]        = "<input type='text' />";
values["web_design"]        = "...code to use when webdesign is selected";
values["print"]        = "...code to use when print is selected";
values["powerpoint"]        = "...code to use when powerpoint is selected";
values["corpid"]        = "...code to use when corpid is selected";
values["other"]        = "...code to use when other is selected";

function changeContent(projectTypeValue){
  //get a handle of the content <p> element
  var contentToChange = document.getElementById("content");
  //change it's innerHTML depending on the value input
  contentToChange.innerHTML = values[projectTypeValue];
}
Give them a try.

Cheers,
Jamey
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-04-2008, 11:13 AM   #3 (permalink)
Registered User
 
Join Date: Apr 2007
Posts: 20
OS: XP Home (Service Pack 3)


Re: What is the best method to dynamically changing form content?

Hmm...

Thanks Jamey for the quick reply, and the code! That's a big help!

However, it doesn't seem to work. I added the code and inserted "logoform.html" into the value and when I clicked on the logo design option, my entire body div seemed to disappear (just a header and footer) and I saw the text "logoform.html". I also tried "index.html" and got the same response...

Did I input the code correctly?

I was wondering if it would be just as efficient to make the select tag self submit to PHP and call up the form content that way..?

Thanks again!
Antoine is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-04-2008, 11:16 AM   #4 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,884
OS: Vista, various linux distros


Re: What is the best method to dynamically changing form content?

Hey, could you post your latest code?

It could be easier to self-submit the select element but it would be a slower process(to the end user)
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


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 Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 01:29 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85