[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Coldfusion drop down box

Posted on 2009-05-15
2
Medium Priority
?
180 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 1500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
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…

656 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