Solved

Coldfusion drop down box

Posted on 2009-05-15
2
177 Views
Last Modified: 2013-12-24
Hi friends,
I would like to create a form with one dropdown box, and two text boxes.

empno: combobox
emp name: textbox
salary : text box
submit button.

when the form loads, the drop down box should have all the employee numbers populated from database table emp.

And when the user selects any of the emp no from dropdown box, then remaining text boxes, empname, sal should be filled with their corresponding values from database.

And Then I want to change the salary or empname for a selected empno, and save it back to database with modified values.

Can someone tell me how I can do it ?
0
Comment
Question by:Sri10
[X]
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
2 Comments
 
LVL 4

Accepted Solution

by:
galadore earned 500 total points
ID: 24401196
I didn't have time to test it all out, but you get the idea here with two form entries:

<cfif isdefined("finished")>
      <cfquery name="putemp" datasource="#DSName#">
            UPDATE emp
            SET
            (empname='#form.empname#',
            salary='#form.salary#)
            WHERE empno=#form.empno#
      </cfquery>
</cfif>
      <cfparam name="form.empno" default="0">
      <cfquery name="getemps" datasource="#DSName#">
            SELECT * from emp
            <cfif isdefined("select")>
                  WHERE empno = #form.empno#
            </cfif>
      </cfquery>
      <form method="POST">
      <select name="empno" size="1">
        <cfoutput query="getemps">
        <option value="#empno#" <cfif form.empno is #empno#>selected</cfif>>#empno#</option>
        </cfoutput>
        </select>
      <cfif isdefined("finished") or form.empno is 0>
            <input name="select" value="select" type="submit">
      </cfif>
      </form>
      <cfif isdefined("form.empno") and not isdefined("finished") and isdefined("select")>
            <form method="POST">
            Employee Name: <input type="text" name="empname" value="<cfoutput>#getemps.empname#</cfoutput>"><br />
            Salary: <input type="text" name="salary" value="<cfoutput>#getemps.salary#</cfoutput>"><br />
            <input name="finished" value="update" type="submit">
            <input name="empno" type="hidden" value="<cfoutput>#form.empno#</cfoutput>">
            </form>
      </cfif>
0
 
LVL 1

Author Comment

by:Sri10
ID: 24415759
Hi, Thanks for the solution but I do not want 2 buttons..
I need only one submit button and when the user click on the empno from the select, need to fire some function or something then it should populate the other fields.

I have written the code like this.


<cfform id="form1" name="form1" method="post" action="">
<cfquery name="aaa" datasource="site4">
select * from emp
</cfquery>
<cfselect name="select1">
<option value="0" selected="selected">0</option>
<cfoutput query="aaa"> <option value="#empno#">#empno#</option></cfoutput>
</cfselect>

  <p>
    <label>Emp name
      <input type="text" name="empname" id="empname" />
    </label>
  </p>
  <p>
    <label>
      <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
  </p>
</cfform>


I am not understanding how to finish this... now when I execute this code, select is being populated with all empno from table. Now when I click on any empno, then the corresponsing empname should be filled in empname textbox.

thanks for your help.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

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 Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

739 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