Solved

Coldfusion drop down box

Posted on 2009-05-15
2
172 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
2 Comments
 
LVL 4

Accepted Solution

by:
galadore earned 500 total points
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

EE introduced a new rating method known as Level, which displays in your avatar as LVL. The new Level is a numeric ranking that is based on your Points. This article discusses the rationale behind the new method and provides the mathematical formula…
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 add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

728 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