Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Coldfusion multiple forms in one page

Posted on 2009-05-15
2
159 Views
Last Modified: 2013-12-24
Hi friends,
I have created a form with 3 fileds empno, empname, sal and a submit  button.
empname and sal fields are read only. one can only enter empno and click submit.

When I enter existing empno in the text field and click on SUBMIT, the query should retrieve corresponding values from table and display in the remaining form fileds..

my table has 3 columns. empno, empname, sal.

until retrieval part, I have done(below code), but after retrieving how do I display values in the remaining fileds..
<cfif isdefined("form.view")>
   <cfquery name="bbb" datasource="site4">
   select * from emp where empno = #form.empno2#
   </cfquery>
 
  
   <cfoutput query="bbb"> #empname# </cfoutput>
   <cfabort>
   
   <cfelse>
     <form id="form2" name="form2" method="post" action="test1.cfm">
       <p>
         <label>Emp No
           <input type="text" name="empno2" id="empno2" />
         </label>
       </p>
       <p>
         <label>Emp Name
           <input name="empname2" type="text" id="empname2" readonly="readonly" />
         </label>
       </p>
       <p>
         <label>Salary
           <input name="sal2" type="text" id="sal2" readonly="readonly" />
         </label>
       </p>
       <p>
         <label>
           <input type="submit" name="view" id="view" value="Submit" />
         </label>
       </p>
</form>
     </cfif>

Open in new window

0
Comment
Question by:Sri10
2 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24399216
you may wanto consider using AJAX for this, so once you enter the value into the first field it will prepopulate the values into the rest
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 24399300
If you prefer submitting the form, you could use cfparam to create an empty query.  So it will always exist, whether the form was submitted or not.  Then use it to populate the fields. Though you should also consider using ajax.

Note, replace the columns "EmpNo, EmpName, Sal" with your actual column names.
<cfif isdefined("form.view")>
   <!--- avoid using SELECT * --->
   <cfquery name="bbb" datasource="site4">
	   SELECT	EmpNo, EmpName, Sal
	   FROM		emp 
	   <!--- use cfqueryparam for all parameters --->
	   WHERE	empno = #form.empno2#
   </cfquery>
</cfif> 
 
<!--- create an empty query if the form was not submitted --->
<cfparam name="variables.bbb" default="#QueryNew('empName,empNo,sal')#">
 
<cfoutput>
     <form id="form2" name="form2" method="post" action="test1.cfm">
       <p>
         <label>Emp No
           <input type="text" name="empno2" id="empno2" value="#bbb.empNo#" />
         </label>
       </p>
       <p>
         <label>Emp Name
           <input name="empname2" type="text" id="empname2" value="#bbb.empName#" readonly="readonly" />
         </label>
       </p>
       <p>
         <label>Salary
           <input name="sal2" type="text" id="sal2" value="#bbb.sal#" readonly="readonly" />
         </label>
       </p>
       <p>
         <label>
           <input type="submit" name="view" id="view" value="Submit" />
         </label>
       </p>
	</form>
</cfoutput>	

Open in new window

0

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Facebook question on friends 3 58
Change size 15 53
Supermicro 91 error 8 34
Conversion Question 7 24
Originally published Entrepreneur.com Booming numbers of freelancing professionals are changing the face of work. In the United States alone last year, the number of workers freelancing grew from 700,000 to 54 million, according to a Freelancers’…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
Where to go on the main page to find the job listings. How to apply to a job that you are interested in from the list that is featured on our Careers page.

856 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