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 drop down box

Posted on 2009-05-15
2
175 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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.
Gift cards are not a new concept - it's been around for a very long time.  Undoubtedly, over the past you have received such a card or purchased one for a friend or relative.  Are you aware that you've been feeding the machine?  If not, read on :)
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ā€¦
Notifications on Experts Exchange help you keep track of your activity and updates in one place. Watch this video to learn how to use them on the site to quickly access the content that matters to you.

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