?
Solved

Coldfusion drop down box

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Phishing is at the top of most security top 10 efforts you should be pursuing in 2016 and beyond. If you don't have phishing incorporated into your Security Awareness Program yet, now is the time. Phishers, and the scams they use, are only going to …
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
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.
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.
Suggested Courses

764 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