Solved

automatically filling form fields based on user selection

Posted on 2004-03-28
16
170 Views
Last Modified: 2013-12-24
Hi

I am relatively new to Cold Fusion and would appreciate some help in formulating code to do the following.

I am trying to create an action page that will allow users to select a "year" with a set of corresponding subjects and subject codes.  The idea is that after the user has selected their year (#Year#) on one part of the form, they are presented with a drop-down list of subject names that apply only to that year.  The subject names, codes and offered years are stored in an Oracle table with the fields "title", "subject" and "year" (respectively).  I want it so that the user need only select the "title" and then subject name and code will automatically enter on-screen table that will accept up to 12 entries.  The names of the table fields are "SubjectName1" through to "SubjectName12" and "SubjectCode1" through to "SubjectCode12".  I only want the year to be saved into the earlier mentioned Year field.  

Further to this, I would like to find a way in which I can restrict the number of entries into these "SubjectName" and "SubjectCode" fields.  On another section of the field, there is an option where the user chooses the "duration".  Code for this is


<table width=80%><div style="text-align: left;"><tr>       
<th align=left width="200">Duration of Program</th>
<td> <input type="radio" name="Duration" value="One Semester">One Semester</input> </td>
<td>  <input type="radio" name="Duration" value="Two Semesters">Two Semesters</input> </td>
<td></td>
<td></td>
</tr></div>

It should be that if the "one semester " option is selected, the number of entries in subject names and codes is restricted to six (6); otherwise no restiction is imposed.

Help on the creation of this code is greatly appreciated.

0
Comment
Question by:jainesteer
  • 7
  • 6
16 Comments
 
LVL 5

Expert Comment

by:M256
ID: 10704776
On your action page, use this code:

<cfif form.duration is "One Semester">
<!--- One Semester Code --->
<cfelseif form.duration is "Two Semesters">
<!--- Two Semesters Code --->
<cfelse>
You didn't choose a Semester!
</cfif>

Matthew
0
 
LVL 5

Expert Comment

by:M256
ID: 10704955
I am guessing you have some HTML worked out, the way you want your page to look.
If you could post that, it would help me understand what you want to do.

Matthew
0
 

Author Comment

by:jainesteer
ID: 10709445
Thanks for your response Matthew but unfortunately it does little to fix my problem.  The duration is one of the fields that must be filled in by the user - and because both the duration and the subjects stuff is all on the same page, an error occurs

Error Diagnostic Information

An error occurred while evaluating the expression:


 form.duration is "One Semester"



Error near line 291, column 20.
--------------------------------------------------------------------------------
Error resolving parameter FORM.DURATION
The specified form field cannot be found. This problem is very likely due to the fact that you have misspelled the form field name.

The error occurred while processing an element with a general identifier of (CFIF), occupying document position (291:1) to (291:38).

Date/Time: 03/30/04 09:27:59
Browser: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Remote Address: 137.219.65.11



Also this is only part of my problem - still have the issue about wanting only those subject names and codes that apply to the year that the user selects to show up in the drop-down.  


The idea is to have a table with two columns.  Entry into these columns is from


<CFQUERY NAME="QSubject" DATASOURCE="CORPDB">
      SELECT      distinct title, subject, year
      FROM       t_local_MASTER_SCHEDULE_SUBJEC
      WHERE (subject not like 'FP%%%%')
      order by title;
</CFQUERY>


The format of the table is

<table width="800" cellspacing="5" cellpadding="1" border="2" >      <tr>      
<td ><b>      Subject name                  </b>            </td>
<td > <b>      Subject Code                  </b>        </td>
</tr>
<tr>      <td > <div style="line-height: normal;""font-weight: lighter;">
Example: Anthropology 1A: Discovering Anthropology</div>      </td>
<td > AN1001:03     </td>
      </tr>
      

<td><select name="SubjectName1"
            size="1" width="20%">
            <option value=1></option>
            <CFLOOP Query="QSubject">
            <CFOUTPUT><option value=#title#>#title#</option></CFOUTPUT>
            </CFLOOP>
        </select>  
</td>


</table>


However, the way that this comes out is that the user selects for the first column and then has to find the corresponding entry in the second column.  I DO NOT want the user to have to select from column 2 at all - instead I want it to be populated automatically using the data that comes from the query.

Then we come into the second part that is that when the user has selected the duration as one semester, there are only 6 options for them to fill in; or 12 for 2 semesters.  Incidentally, this is just what I would hope for and is certainly not essential - I can leave it so that there are just 12 table entries with no restrictions to the number that can be filled in.


Also just on the formatting - for which I seem to have no end of trouble, I would like the overall column widths to be about 90/10%.

Thanks

I look forward to any comments/help.




0
 
LVL 5

Expert Comment

by:M256
ID: 10709910
Sorry about the error with my code above; try this instead:

<cfif not isDefined("form.duration">
You didn't choose a Semester!
<cfelseif form.duration is "One Semester">
<!--- One Semester Code --->
<cfelseif form.duration is "Two Semesters">
<!--- Two Semesters Code --->
<cfelse>
Error!
</cfif>

Now, on to the next problem.  Try out the following code, and tell me what you still need help with.

Matthew

<CFQUERY NAME="QSubject" DATASOURCE="CORPDB">
     SELECT     distinct title, subject, year, id
     FROM      t_local_MASTER_SCHEDULE_SUBJEC
     WHERE (subject not like 'FP%%%%')
     order by title;
</CFQUERY>
<html>
<head>
<script language="JavaScript">
<!-- Hide from older browsers
function updateTable()  {
if(SubjectName1.value=="1") document.getElementById('code').innerHTML="Please choose something.";
<CFOUTPUT query="QSubject">if(SubjectName1.value=="#URLEncodedFormat(title)#") document.getElementById('code').innerHTML="#title#"; <!--- Change "#title#" at left to whatever variable you want "automaticaly updated". --->
</cfoutput>}
// Done hiding -->
</script>
</head>
<body>
<table width="800" cellspacing="5" cellpadding="1" border="2" >
<tr>    
 <td width="90%"><b>Subject Name</b></td>
 <td width="10%"><b>Subject Code</b></td>
 <!-- Note that if you have a word longer than the 10%,
 your table will expand to accomodate it. You could make it
 80%/20%, or play with it to get it right. -->
</tr>
<tr>
 <td><div style="line-height: normal;""font-weight: lighter;">
 Example: Anthropology 1A: Discovering Anthropology</div>
 </td>
 <td>AN1001:03</td>
</tr>
<tr>
 <td><select name="SubjectName1" onChange="updateTable()" size="1" width="20%">
  <option value="1"></option>
  <CFOUTPUT query="QSubject">
  <option value="#URLEncodedFormat(title)#">#title#</option>
  </CFOUTPUT>
  </select>  
 </td>
 <td id="code">Please choose somthing.</td>
<!--- I am not sure what variable you want in this box; go up to the JavaScript section to change it. --->
</tr>
</table>
</body>
</html>
0
 
LVL 17

Expert Comment

by:anandkp
ID: 10711982
0
 

Author Comment

by:jainesteer
ID: 10719893
I will respond to both postings separately

Anand

I had a look at these sites, and given my limited knowledge of CF and non-existent of Java, I must say I am extremely overwhelmed - hats off to you lot for being able to conquer this stuff.

None of the sites seem to do what I need - I am not looking at the second box having a number of options from which the user can select, the idea is that the first selection automatically populates the on-sceen table and the table that is behind it all with the corresponding information.

Matthew

Thanks very much for your posting.  The page is starting to take shape but I definitely still have problems.  The first part (6 for 1 semester/12 for 2 semesters) just doesn't want to work - but as I said earlier it is the least of my problems - I will just have the 12 rows on the table (and maybe later consider working out some way of spitting up a warning that the user can only put in six if they have selected one semester).

The subject title/code situation works well for a single row (ie subject1/code1), but I am having problems in duplicating it through to 12 entries.  I can get the new rows to appear, but when I apply the page, I do not get a new code corresponding to each title - they all just want to overwrite the first one.  I have included the code that I have been working on (with 3 rows).  Hopefully one of my heroes out there can help me get this to do what I want it to.

Thanks so far!!







<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- shtml nonsecure xhtml header built Fri Mar 21 09:28:58 2003 -->


<html>
<head>
<CFQUERY NAME="QSubject" DATASOURCE="CORPDB">
     SELECT     distinct title, subject, year
     FROM      t_local_MASTER_SCHEDULE_SUBJEC
     WHERE (subject not like 'FP%%%%')
     order by title;
</CFQUERY>

<script language="JavaScript">
<!-- Hide from older browsers
function updateTable1()  {
if(SubjectName1.value=="1") document.getElementById('code').innerHTML="Please choose something.";
<CFOUTPUT query="QSubject">if(SubjectName1.value=="#URLEncodedFormat(title)#") document.getElementById('code').innerHTML="#subject#"; <!--- Change "#title#" at left to whatever variable you want "automaticaly updated". --->
</cfoutput>}
function updateTable2()  {
if(SubjectName2.value=="1") document.getElementById('code').innerHTML="Please choose something.";
<CFOUTPUT query="QSubject">if(SubjectName2.value=="#URLEncodedFormat(title)#") document.getElementById('code').innerHTML="#subject#"; <!--- Change "#title#" at left to whatever variable you want "automaticaly updated". --->
</cfoutput>}
function updateTable3()  {
if(SubjectName3.value=="1") document.getElementById('code').innerHTML="Please choose something.";
<CFOUTPUT query="QSubject">if(SubjectName3.value=="#URLEncodedFormat(title)#") document.getElementById('code').innerHTML="#subject#"; <!--- Change "#title#" at left to whatever variable you want "automaticaly updated". --->
</cfoutput>}
// Done hiding -->
</script>
</head>
<body>
<table width="800" cellspacing="5" cellpadding="1" border="2" >
<tr>    
 <td width="90%"><b>Subject Name</b></td>
 <td width="10%"><b>Subject Code</b></td>
 <!-- Note that if you have a word longer than the 10%,
 your table will expand to accomodate it. You could make it
 80%/20%, or play with it to get it right. -->
</tr>
<tr>
 <td><div style="line-height: normal;""font-weight: lighter;">
 Example: Anthropology 1A: Discovering Anthropology</div>
 </td>
 <td>AN1001:03</td>
</tr>
</table>
<table width="800" cellspacing="5" cellpadding="1" border="2" >
<tr>
 <td><select name="SubjectName1" onChange="updateTable1()" size="1" width="20%">
  <option value="1"></option>
  <CFOUTPUT query="QSubject">
  <option value="#URLEncodedFormat(title)#">#title#</option>
  </CFOUTPUT>
  </select>  
 </td>
 <td id="code"></td>
<!--- Go up to the JavaScript section to change this option. --->
</tr>
<tr>


 <td><select name="SubjectName2" onChange="updateTable2()" size="1" width="20%">
  <option value="1"></option>
  <CFOUTPUT query="QSubject">
  <option value="#URLEncodedFormat(title)#">#title#</option>
  </CFOUTPUT>
  </select>  
 </td>
 <td id="code"></td>
<!--- Go up to the JavaScript section to change this option. --->
</tr>


<tr>
 <td><select name="SubjectName3" onChange="updateTable3()" size="1" width="20%">
  <option value="1"></option>
  <CFOUTPUT query="QSubject">
  <option value="#URLEncodedFormat(title)#">#title#</option>
  </CFOUTPUT>
  </select>  
 </td>
 <td id="code"></td>
<!--- Go up to the JavaScript section to change this option. --->
</tr>
</table>
</body>
</html>
0
 
LVL 5

Accepted Solution

by:
M256 earned 250 total points
ID: 10720925
jainesteer,

I think we are getting closer to the goal.

Try this code, and let me know if I left anything out.
Note that this assumes that the "subject name" portion of the form is on top.  If there are other form fields before it in your final page, I need to make some changes.

Matthew

<CFQUERY NAME="QSubject" DATASOURCE="CORPDB">
     SELECT     distinct title, subject, year, id
     FROM      t_local_MASTER_SCHEDULE_SUBJEC
     WHERE (subject not like 'FP%%%%')
     order by title;
</CFQUERY>
<html>
<head>
<script language="JavaScript">
<!-- Hide from older browsers
function updateTable(num)
{
if(document.forms[0].elements[num-1].value=="1") {document.getElementById("code" + num).innerHTML="&nbsp;"}
<CFOUTPUT query="QSubject">if(document.forms[0].elements[num-1].value=="#URLEncodedFormat(title)#") {document.getElementById("code" + num).innerHTML="#subject#";}
</cfoutput>}
function deactivate()  {
i=5
while(i<11){
i=i+1
document.forms[0].elements[i].disabled=true
  }
}
function reactivate()  {
i=5
while(i<11){
i=i+1
document.forms[0].elements[i].disabled=false
  }
}
// Done hiding -->
</script>
</head>
<body>
<form name="form1">
<table width="800" cellspacing="5" cellpadding="1" border="2" >
<tr>    
 <td width="90%"><b>Subject Name</b></td>
 <td width="10%"><b>Subject Code</b></td>
</tr>
<cfoutput>
<cfloop from="1" to="12" index="x">
<tr>
 <td><select name="SubjectName#x#" onChange="updateTable('#x#')" size="1" width="20%">
  <option value="1"></option>
  <cfloop query="QSubject">
  <option value="#URLEncodedFormat(title)#">#title#</option>
  </cfloop>
  </select>  
 </td>
 <td id="code#x#">&nbsp;</td>
</tr>
</cfloop>
</cfoutput>
</table>
<input type="radio" onClick="deactivate()" id="one" name="semister"><label for="one">One Semister</label>
<input type="radio" onClick="reactivate()" id="more" name="semister"><label for="more">Two Semisters</label>
</form>
</body>
</html>
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:jainesteer
ID: 10721514
I am still working on it - but my first problem seems to be that unless the table comes in directly after my cfform tag, it will not populate.

I will look at it further tomorrow - but in the meantime if you have any idea on how to fix this, help is once again appreciated.
0
 
LVL 5

Expert Comment

by:M256
ID: 10723206
That's odd.  You should be able to just copy and paste the code from above.

If you have done that, please post the code that doesn't work so I can look at it.

Matthew
0
 

Author Comment

by:jainesteer
ID: 10738603
Matthew

Things are all over the place here.  As I said if I move it from anywhere but the start of the body it won't bring up the subject code.  Also, if I do leave the code at the beginning, my echo page spits back the warning


Subject preferences: Subject name Subject code
20th%20Century%20French%20Theatre%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20  

--------------------------------------------------------------------------------
Error Occurred While Processing Request
Error Diagnostic Information

An error occurred while evaluating the expression:


#Form.Subjectcode1#



Error near line 258, column 34.
--------------------------------------------------------------------------------

Error resolving parameter FORM.SUBJECTCODE1


The specified form field cannot be found. This problem is very likely due to the fact that you have misspelled the form field name.

The error occurred while processing an element with a general identifier of (#Form.Subjectcode1#), occupying document position (258:33) to (258:51).

Date/Time: 04/02/04 15:15:42
Browser: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Remote Address: 137.219.65.11
HTTP Referrer: http://************/SAAppsubject.cfm

 
--------------------------------------------------------------------------------


The %20 occurrences have something to do with the spaces in the title


Also, one of my other selections (radio button) echoes back that it has not been selected - even when it has been

Are you sure that you still want to look further??!!
0
 
LVL 5

Expert Comment

by:M256
ID: 10766716
I would be delighted to look into the problem further.

I apologize for the delay; I was out of town.

All of the %20 should not be a problem; if you would like we could get rid of all the ones on the end by changing #URLEncodedFormat(title)# to #trim(URLEncodedFormat(title))#.  Note that there are two of them to change in my code.

As for the error message:
An error occurred while evaluating the expression:
#Form.Subjectcode1#
Error near line 258, column 34.

This is a vague way of telling you that form name does not exist.  I think if you go to line 258 and change #Form.Subjectcode1# to #Form.SubjectName1#, that would fix your problem.
Something I have found very helpful is the <cfdump> tag.  On your action page for the form, save the whole page under another name and put just this line of code:
<cfdump var="#form#">
This will show you all the variables available in the "form" structure.

Let me know if you run into any more problems.

Matthew
0
 

Author Comment

by:jainesteer
ID: 10771864
Hi Matthew

Thanks for your suggestions but I definitely still have problems.

I have added the trim statement and the cfdump tag to my code - both to no avail.  However, I suspect that my problem could well be associated with my echo page.

I have included the code for both.  FYI: the cfdump statement gives a list of variables

subjectname1 subjectcode1
subjectname2 subjectcode2
subjectname3 subjectcode3
....
subjectname12 subjectcode12

The action page code is

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<CFQUERY NAME="QSubject" DATASOURCE="CORPDB">
     SELECT     distinct title, subject, year
     FROM      t_local_MASTER_SCHEDULE_SUBJEC
     WHERE (subject not like 'FP%%%%')
     order by title;
</CFQUERY>

<html lang="en">
<head>

<script language="JavaScript">
<!-- Hide from older browsers
function updateTable(num)
{
if(document.forms[0].elements[num-1].value=="1") {document.getElementById("subjectcode" + num).innerHTML="&nbsp;"}
<CFOUTPUT query="QSubject">if(document.forms[0].elements[num-1].value=="#trim(URLEncodedFormat(title))#") {document.getElementById("subjectcode" + num).innerHTML="#subject#";}
</cfoutput>}
function deactivate()  {
i=5
while(i<11){
i=i+1
document.forms[0].elements[i].disabled=true
  }
}
function reactivate()  {
i=5
while(i<11){
i=i+1
document.forms[0].elements[i].disabled=false
  }
}
// Done hiding -->
</script>


</head>
<body>



<!-- start content -->

<form name="App" ACTION="Echo.cfm" method="POST">

<table width="800" cellspacing="5" cellpadding="1" border="2" >
<tr>    
 <td width="90%"><b>Subject Name</b></td>
 <td width="10%"><b>Subject Code</b></td>
</tr>
<cfoutput>
<cfloop from="1" to="12" index="x">

<cfdump var="subjectname#x#">
<cfdump var="subjectcode#x#">

<tr>
 <td><select name="SubjectName#x#" onChange="updateTable('#x#')" size="1" width="20%">
  <option value="1"></option>
  <cfloop query="QSubject">
  <option value="#trim(URLEncodedFormat(title))#">#trim(title)#</option>
  </cfloop>
  </select>  
 </td>
 <td id="subjectcode#x#">&nbsp;</td>
</tr>
</cfloop>
</cfoutput>
</table>
<input type="radio" onClick="deactivate()" id="one" name="semister"><label for="one">One Semister</label>
<input type="radio" onClick="reactivate()" id="more" name="semister"><label for="more">Two Semisters</label>



<hr><table>    <p>
      <INPUT TYPE="Submit" VALUE="Submit"></INPUT>
      <INPUT TYPE="Reset" VALUE="Reset">
    </p>
    </table>

</form>
</body>
</html>


The echo page code is

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="FORMATTER" content="">
<meta name="GENERATOR" content="">
<title></title>
</head>


<hr size=25 NOSHADE>
<table width="60%">

<tr>
       <th align=left valign=center>Subject preferences:</th>
      <td>
            <table width="100%">
            <CFOUTPUT>
                  <tr>
                        <th align=center>Subject name</th>
                        <th align=center>Subject code</th>
                  </tr>

                  <tr>
                        <td align=center  valign=top>#Form.Subjectname1#</td>
                  <td align=center valign=top>#Form.Subjectcode1#</td>
                  </tr>
                  <tr>
                        <td align=center  valign=top>#Form.Subjectname2#</td>
                        <td align=center valign=top>#Form.Subjectcode2#</td>
                  </tr>
                  <tr>
                        <td align=center  valign=top>#Form.Subjectname3#</td>
                  <td align=center valign=top>#Form.Subjectcode3#</td>
                  </tr>
                  <tr>
                        <td align=center  valign=top>#Form.Subjectname4#</td>
                        <td align=center valign=top>#Form.Subjectcode4#</td>
                  </tr>
                  <tr>
                        <td align=center  valign=top>#Form.Subjectname5#</td>
                        <td align=center valign=top>#Form.Subjectcode5#</td>
                  </tr>
                  <tr>
                        <td align=center  valign=top>#Form.Subjectname6#</td>
                        <td align=center valign=top>#Form.Subjectcode6#</td>
                  </tr>
                  <tr>
                        <td align=center  valign=top>#Form.Subjectname7#</td>
                        <td align=center valign=top>#Form.Subjectcode7#</td>
                  </tr>
                  <tr>
                        <td align=center  valign=top>#Form.Subjectname8#</td>
                        <td align=center valign=top>#Form.Subjectcode8#</td>
                  </tr>
                  <tr>
                        <td align=center  valign=top>#Form.Subjectname9#</td>
                        <td align=center valign=top>#Form.Subjectcode9#</td>
                  </tr>
                  <tr>
                        <td align=center  valign=top>#Form.Subjectname10#</td>
                        <td align=center valign=top>#Form.Subjectcode10#</td>
                  </tr>
                  <tr>
                        <td align=center  valign=top>#Form.Subjectname11#</td>
                        <td align=center valign=top>#Form.Subjectcode11#</td>
                  </tr>
                  <tr>
                        <td align=center  valign=top>#Form.Subjectname12#</td>
                        <td align=center valign=top>#Form.Subjectcode12#</td>
                  </tr>
                  
            </CFOUTPUT>
            </table>
      </td>
</tr>


</table>
<hr>

<form name="Echo" ACTION="Submit.cfm" method="POST">

<CFOUTPUT>


      <INPUT TYPE="Hidden" NAME="SubjectName1"       VALUE="trim(#Form.SubjectName1#)"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode1"       VALUE="#Form.SubjectCode1#"></INPUT>
      <INPUT TYPE="Hidden" NAME="SubjectName2"       VALUE="#Form.SubjectName2#"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode2"       VALUE="#Form.SubjectCode2#"></INPUT>
      <INPUT TYPE="Hidden" NAME="SubjectName3"       VALUE="#Form.SubjectName3#"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode3"       VALUE="#Form.SubjectCode3#"></INPUT>
      <INPUT TYPE="Hidden" NAME="SubjectName4"       VALUE="#Form.SubjectName4#"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode4"       VALUE="#Form.SubjectCode4#"></INPUT>
      <INPUT TYPE="Hidden" NAME="SubjectName5"       VALUE="#Form.SubjectName5#"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode5"       VALUE="#Form.SubjectCode5#"></INPUT>
      <INPUT TYPE="Hidden" NAME="SubjectName6"       VALUE="#Form.SubjectName6#"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode6"       VALUE="#Form.SubjectCode6#"></INPUT>
      <INPUT TYPE="Hidden" NAME="SubjectName7"       VALUE="#Form.SubjectName7#"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode7"       VALUE="#Form.SubjectCode7#"></INPUT>
      <INPUT TYPE="Hidden" NAME="SubjectName8"       VALUE="#Form.SubjectName8#"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode8"       VALUE="#Form.SubjectCode8#"></INPUT>
      <INPUT TYPE="Hidden" NAME="SubjectName9"       VALUE="#Form.SubjectName9#"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode9"       VALUE="#Form.SubjectCode9#"></INPUT>
      <INPUT TYPE="Hidden" NAME="SubjectName10"       VALUE="#Form.SubjectName10#"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode10"       VALUE="#Form.SubjectCode10#"></INPUT>
      <INPUT TYPE="Hidden" NAME="SubjectName11"       VALUE="#Form.SubjectName11#"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode11"       VALUE="#Form.SubjectCode11#"></INPUT>
      <INPUT TYPE="Hidden" NAME="SubjectName12"       VALUE="#Form.SubjectName12#"></INPUT>            
      <INPUT TYPE="Hidden" NAME="SubjectCode12"       VALUE="#Form.SubjectCode12#"></INPUT>
      
      
</CFOUTPUT>

<center>
<INPUT TYPE="Submit" VALUE="Submit"></INPUT>
</center>

</form>
<hr>
<hr size=25 NOSHADE>
</body>
</html>



The "view source" information that is behind the action page is

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html lang="en">
<head>

<script language="JavaScript">
<!-- Hide from older browsers
function updateTable(num)
{
if(document.forms[0].elements[num-1].value=="1") {document.getElementById("subjectcode" + num).innerHTML="&nbsp;"}
if(document.forms[0].elements[num-1].value=="20th%20Century%20French%20Novel%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {document.getElementById("subjectcode" + num).innerHTML="FR4415";}
if(document.forms[0].elements[num-1].value=="20th%20Century%20French%20Novel%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {document.getElementById("subjectcode" + num).innerHTML="FR4415";}
if(document.forms[0].elements[num-1].value=="Zoology%20Honours%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20") {document.getElementById("subjectcode" + num).innerHTML="ZL4000";}
if(document.forms[0].elements[num-1].value=="e%2DBusiness%20and%20e%2DCommerce%20for%20Managers%20%20%20%20%20%20%20%20%20%20%20%20") {document.getElementById("subjectcode" + num).innerHTML="BU5121";}
}
function deactivate()  {
i=5
while(i<11){
i=i+1
document.forms[0].elements[i].disabled=true
  }
}
function reactivate()  {
i=5
while(i<11){
i=i+1
document.forms[0].elements[i].disabled=false
  }
}
// Done hiding -->
</script>


</head>
<body>


<!-- start content -->
<form name="App" ACTION="Echo.cfm" method="POST">

<table width="800" cellspacing="5" cellpadding="1" border="2" >
<tr>    
 <td width="90%"><b>Subject Name</b></td>
 <td width="10%"><b>Subject Code</b></td>
</tr>

      <script language="JavaScript">
      function cfadumpswitch(source) {
            target = source.parentElement.cells[1].style;
            if (target.display == 'none') {
                  source.style.fontStyle = 'normal';
                  source.style.backgroundColor = 'aaaaee';
                  target.display = '';
            } else {
                  source.style.fontStyle = 'italic';
                  source.style.backgroundColor = 'silver';
                  target.display = 'none';
            }
      }
      </script>
      
      
      subjectname1
      subjectcode1

<tr>
 <td><select name="SubjectName1" onChange="updateTable('1')" size="1" width="20%">
  <option value="1"></option>
 
  <option value="20th%20Century%20French%20Novel%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20">20th Century French Novel</option>
  <option value="20th%20Century%20French%20Novel%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20">20th Century French Novel</option>
  <option value="Zoology%20Honours%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20">Zoology Honours</option>
  <option value="e%2DBusiness%20and%20e%2DCommerce%20for%20Managers%20%20%20%20%20%20%20%20%20%20%20%20">e-Business and e-Commerce for Managers</option>
  </select>  
 </td>
 <td id="subjectcode1">&nbsp;</td>
</tr>


      subjectname2
      subjectcode2

<tr>
 <td><select name="SubjectName2" onChange="updateTable('2')" size="1" width="20%">
  <option value="1"></option>
 
  <option value="20th%20Century%20French%20Novel%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20">20th Century French Novel</option>
  <option value="20th%20Century%20French%20Novel%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20">20th Century French Novel</option>
  <option value="Zoology%20Honours%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20">Zoology Honours</option>
  <option value="e%2DBusiness%20and%20e%2DCommerce%20for%20Managers%20%20%20%20%20%20%20%20%20%20%20%20">e-Business and e-Commerce for Managers</option>
  </select>  
 </td>
 <td id="subjectcode2">&nbsp;</td>
</tr>

      

etc up to subjectname12 subjectcode12



</table>
<input type="radio" onClick="deactivate()" id="one" name="semister"><label for="one">One Semister</label>
<input type="radio" onClick="reactivate()" id="more" name="semister"><label for="more">Two Semisters</label>



<hr><table>    <p>
      <INPUT TYPE="Submit" VALUE="Submit"></INPUT>
      <INPUT TYPE="Reset" VALUE="Reset">
    </p>
    </table>

</form>
</body>
</html>


Any help is much appreciated

Jaine
0
 
LVL 5

Expert Comment

by:M256
ID: 10772224
OK, I think I see what's going on now.

Try this for your form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<CFQUERY NAME="QSubject" DATASOURCE="CORPDB">
     SELECT     distinct title, subject, year
     FROM      t_local_MASTER_SCHEDULE_SUBJEC
     WHERE (subject not like 'FP%%%%')
     order by title;
</CFQUERY>

<html lang="en">
<head>
<script language="JavaScript">
<!-- Hide from older browsers
function updateTable(num)  {
if(document.forms[0].elements[num-1].value=="1") {document.getElementById("subjectcode" + num).innerHTML="&nbsp;"}
<CFOUTPUT query="QSubject">if(document.forms[0]["SubjectName" + num].value=="#URLEncodedFormat(trim(title))#") {document.getElementById("subjectcode" + num).innerHTML="#subject#"; document.forms[0]["subjectcode" + num].value="#subject#";}
</cfoutput>}
function deactivate()  {
i=11
while(i<23){
i=i+1;
var dnum = (i / 2);
var inum = (Math.round(dnum));
if (inum == dnum) {
document.forms[0].elements[i].disabled=true
    }
  }
}
function reactivate()  {
i=1
while(i<23){
i=i+1
document.forms[0].elements[i].disabled=false
  }
}
// Done hiding -->
</script>
</head>
<body>

<!-- start content -->

<form name="App" ACTION="Echo.cfm" method="POST">

<table width="800" cellspacing="5" cellpadding="1" border="2" >
<tr>    
 <td width="90%"><b>Subject Name</b></td>
 <td width="10%"><b>Subject Code</b></td>
</tr>
<cfoutput>
<cfloop from="1" to="12" index="x">
<tr>
 <td><select name="SubjectName#x#" onChange="updateTable('#x#')" size="1" width="20%">
  <option value="1"></option>
  <cfloop query="QSubject">
  <option value="#URLEncodedFormat(trim(title))#">#trim(title)#</option>
  </cfloop>
  </select>  
 </td>
 <td id="subjectcode#x#">&nbsp;</td><input type="hidden" name="subjectcode#x#" value="">
</tr>
</cfloop>
</cfoutput>
</table>
<input type="radio" onClick="deactivate()" id="one" name="semister" value="one"><label for="one">One Semister</label>
<input type="radio" onClick="reactivate()" id="more" name="semister" value="more"><label for="more">Two Semisters</label>

<hr>
      <INPUT TYPE="Submit" VALUE="Submit"></INPUT>
      <INPUT TYPE="Reset" VALUE="Reset">
</form>
</body>
</html>

The following for the "echo" page:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

<cfif form.semister is "one">
<cfset z = 6>
<cfelse>
<cfset z = 12>
</cfif>
<cfoutput>
<cfloop from="1" to="#z#" index="x">
<cfset "Form.SubjectName#x#" = URLDecode(evaluate("Form.SubjectName" & x))>
</cfloop>
</cfoutput>

<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="FORMATTER" content="">
<meta name="GENERATOR" content="">
<title></title>
</head>


<hr size=25 NOSHADE>
<table width="60%">

<tr>
      <th align=left valign=center>Subject preferences:</th>
     <td>
          <table width="100%">
          <CFOUTPUT>
               <tr>
                    <th align=center>Subject name</th>
                    <th align=center>Subject code</th>
               </tr>

               <tr>
                    <td align=center  valign=top>#Form.Subjectname1#</td>
               <td align=center valign=top>#Form.Subjectcode1#</td>
               </tr>
               <tr>
                    <td align=center  valign=top>#Form.Subjectname2#</td>
                    <td align=center valign=top>#Form.Subjectcode2#</td>
               </tr>
               <tr>
                    <td align=center  valign=top>#Form.Subjectname3#</td>
               <td align=center valign=top>#Form.Subjectcode3#</td>
               </tr>
               <tr>
                    <td align=center  valign=top>#Form.Subjectname4#</td>
                    <td align=center valign=top>#Form.Subjectcode4#</td>
               </tr>
               <tr>
                    <td align=center  valign=top>#Form.Subjectname5#</td>
                    <td align=center valign=top>#Form.Subjectcode5#</td>
               </tr>
               <tr>
                    <td align=center  valign=top>#Form.Subjectname6#</td>
                    <td align=center valign=top>#Form.Subjectcode6#</td>
               </tr>
<cfif isdefined("Form.Subjectname7")>
               <tr>
                    <td align=center  valign=top>#Form.Subjectname7#</td>
                    <td align=center valign=top>#Form.Subjectcode7#</td>
               </tr>
               <tr>
                    <td align=center  valign=top>#Form.Subjectname8#</td>
                    <td align=center valign=top>#Form.Subjectcode8#</td>
               </tr>
               <tr>
                    <td align=center  valign=top>#Form.Subjectname9#</td>
                    <td align=center valign=top>#Form.Subjectcode9#</td>
               </tr>
               <tr>
                    <td align=center  valign=top>#Form.Subjectname10#</td>
                    <td align=center valign=top>#Form.Subjectcode10#</td>
               </tr>
               <tr>
                    <td align=center  valign=top>#Form.Subjectname11#</td>
                    <td align=center valign=top>#Form.Subjectcode11#</td>
               </tr>
               <tr>
                    <td align=center  valign=top>#Form.Subjectname12#</td>
                    <td align=center valign=top>#Form.Subjectcode12#</td>
               </tr>
</cfif>
          </CFOUTPUT>
          </table>
     </td>
</tr>


</table>
<hr>

<form name="Echo" ACTION="Submit.cfm" method="POST">

<CFOUTPUT>


     <INPUT TYPE="Hidden" NAME="SubjectName1"      VALUE="trim(#Form.SubjectName1#)"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode1"      VALUE="#Form.SubjectCode1#"></INPUT>
     <INPUT TYPE="Hidden" NAME="SubjectName2"      VALUE="#Form.SubjectName2#"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode2"      VALUE="#Form.SubjectCode2#"></INPUT>
     <INPUT TYPE="Hidden" NAME="SubjectName3"      VALUE="#Form.SubjectName3#"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode3"      VALUE="#Form.SubjectCode3#"></INPUT>
     <INPUT TYPE="Hidden" NAME="SubjectName4"      VALUE="#Form.SubjectName4#"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode4"      VALUE="#Form.SubjectCode4#"></INPUT>
     <INPUT TYPE="Hidden" NAME="SubjectName5"      VALUE="#Form.SubjectName5#"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode5"      VALUE="#Form.SubjectCode5#"></INPUT>
     <INPUT TYPE="Hidden" NAME="SubjectName6"      VALUE="#Form.SubjectName6#"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode6"      VALUE="#Form.SubjectCode6#"></INPUT>
<cfif isdefined("Form.Subjectname7")>
     <INPUT TYPE="Hidden" NAME="SubjectName7"      VALUE="#Form.SubjectName7#"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode7"      VALUE="#Form.SubjectCode7#"></INPUT>
     <INPUT TYPE="Hidden" NAME="SubjectName8"      VALUE="#Form.SubjectName8#"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode8"      VALUE="#Form.SubjectCode8#"></INPUT>
     <INPUT TYPE="Hidden" NAME="SubjectName9"      VALUE="#Form.SubjectName9#"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode9"      VALUE="#Form.SubjectCode9#"></INPUT>
     <INPUT TYPE="Hidden" NAME="SubjectName10"      VALUE="#Form.SubjectName10#"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode10"      VALUE="#Form.SubjectCode10#"></INPUT>
     <INPUT TYPE="Hidden" NAME="SubjectName11"      VALUE="#Form.SubjectName11#"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode11"      VALUE="#Form.SubjectCode11#"></INPUT>
     <INPUT TYPE="Hidden" NAME="SubjectName12"      VALUE="#Form.SubjectName12#"></INPUT>          
     <INPUT TYPE="Hidden" NAME="SubjectCode12"      VALUE="#Form.SubjectCode12#"></INPUT>
</cfif>
     
</CFOUTPUT>

<center>
<INPUT TYPE="Submit" VALUE="Submit"></INPUT>
</center>

</form>
<hr>
<hr size=25 NOSHADE>
</body>
</html>
0
 

Author Comment

by:jainesteer
ID: 10781364
Matthew

This is definitely taking shape now - but still, unfortunately a bit "buggy"

I have been able to incorporate your code into the rest of the form - even though there is still problems with the radio button.  I may just open this up so that there is always 12 fields irrespective of 1 or 2 semesters.

The main problem that I still face is that when the title selection is left blank, the echo page (and entry into the table) is 1.  I really don't care if a 1 gets entered into the table but I don't like it echoing back.  

Another problem is that if the user goes through the submit - echo - and back to the action page, the subject codes do not appear on-screen (they do however show up when you go back to the echo page).  

Another bug is that if a user selects say, 5 subjects, submits, ehcoes, changes their mind and only wants 3 subjects, short of refreshing the whole page and starting again, there is no way of clearing entry 4 and 5. ie. the echo page will still show the codes for subject titles that have been removed.

Next problem, I am on holidays for the next 11 days - well this isn't a problem as such, in fact, I am quite looking forward to it.  Anyway, I will not be able to respond to any comments until I return.  So until that time, thankyou for your continued help.

Jaine
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now