fetch database value to text box based on selected value my code given below pls correct my code

Ads
 

fetch database value to text box based on selected value my code given below pls correct my code

my Code Given below Pls... help me send correct code for me

jsp file...

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ taglib uri="WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="WEB-INF/struts-html.tld" prefix="html" %>
<%@taglib uri="WEB-INF/struts-logic.tld" prefix="logic" %>

<html:html>
<head>
    <html:base/>
    <title>Login page</title>

</head>
<body onload ="getDestArray()">
<html:form action="/dedit" >
<center><table border="1">
        <tbody>
            <tr>
                <td>Destination : </td>
                <td>
                <html:select property="destination" onchange="getPrice()">
                <html:option value="0">?SELECT?</html:option>
                <html:options collection="menuList" property="destination"  />
                </html:select>
                </td>


            </tr>
            <tr>
                <td>Amount   : </td>
                <td id="price"><input type="text" value =" " property= "amount" id='pricecheck'/>
    <html:text value="" property="amount"/></td>
            </tr>
            <tr>
                <td colspan="2" valign="center"><html:submit value="Submit"/></td></tr>
        </tbody>
    </table></center>
</html:form>
</body>
</html:html>

<script>
var destArray=new Array();
function getDestArray(){
<logic:notEmpty name="form" property="arrPriceLis">
  <logic:iterate name="form" property="arrPriceLis" id="priceList ">

   destArray ["<bean:write name= 'priceList' property='destination'/>"] = "<bean:write name= 'pricelist'  property= 'priceList' />";
  </logic:iterate>
</logic:notEmpty>

}

function getPrice(){

var test =<bean:write name="menuBeanList" property="destArray"></bean:write>
//var test = document.forms[0].destination.value;
var price = destArray ["test"];
// try these stuff any one
document.forms[0].amount.value = price;
// else try this if its input tag
//document.getElementById('pricecheck').value= price;
// else IF ITS HYML TAG 
//document.getElementById('price').innerHTML = PRICE

}
</script>

Action class
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fetch;

import java.sql.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import fetch.MenuBean;



public class MenuAction extends Action {
    private final static String SUCCESS = "success";
    public ActionForward execute(ActionMapping mapping, ActionForm  actionform,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

         ArrayList menuList = new ArrayList();

        ArrayList menuBeanList = new ArrayList();

        MenuBean menu = null;
       MenuCombo menucombo = null;
    MenuForm form = new MenuForm();

        HttpSession session = request.getSession();
                session.setAttribute( "menuList", menuList);


// ELSE DO THIS 
    //MenuForm form = (MenuForm)actionform;
// thtas is to cascate  ur form

        try
        {

            Class.forName("oracle.jdbc.driver.OracleDriver");
           Connection                 con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","thiru","thirumal");
           PreparedStatement stmt=con.prepareStatement("select * from destination");
           ResultSet rs=stmt.executeQuery();

           while(rs.next())
            {
    menucombo=new MenuCombo();
    menu = new MenuBean();
                String destination = rs.getString(1);
      String destinationId = rs.getString(1);
     String price = rs.getString(2);
               menucombo.setDestination(destination);
    menucombo.setDestinationId(destinationId );
    menu.setDestination(destination );
    menu.setPrice(price );


    menuList.add(menucombo);
             menuBeanList.add(menu);

             }

    form.setArrPriceList(menuBeanList);
            form.setMenuList(menuList);

        }
        catch(Exception e)
        {

        }
        return mapping.findForward(SUCCESS);
    }
}

bean class
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fetch;

/**
 *
 * @author Thiru
 */
public class MenuBean {


private String destination;
private String price;

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

java class
package fetch;

/**
 *
 */
public class MenuCombo {


private String destination ;
private String destinationId;

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public String getDestinationId() {
        return destinationId;
    }

    public void setDestinationId(String destinationId) {
        this.destinationId = destinationId;
    }
}

DAO class

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fetch;

/**
 *
 * @author Thiru
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.sql.*;
import java.util.ArrayList;
import fetch.MenuBean;

public class MenuData {



    public MenuData() {

    }
    public ArrayList menuList() {



        ArrayList menuList = new ArrayList();

        ArrayList menuBeanList = new ArrayList();

        MenuBean menu = null;
     MenuCombo menucombo = null;

        try
        {
            Class.forName("oracle.jdbc.driver.OracleDriver");
           Connection           con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","thiru","thirumal");
           PreparedStatement stmt=con.prepareStatement("select * from destination");
           ResultSet rs=stmt.executeQuery();

           while(rs.next())
            {
    menucombo=new MenuCombo();
    menu = new MenuBean();
                String destination = rs.getString(1);
      String destinationId = rs.getString(1);
     String price = rs.getString(2);
               menucombo.setDestination(destination);
    menucombo.setDestinationId(destinationId );
    menu.setDestination(destination );
    menu.setPrice(price );


    menuList.add(menucombo);
             menuBeanList.add(menu);

             }



        }
        catch(Exception e)
        {

        }

      return menuList;
    }

}

list getter and setter
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fetch;

import java.util.*;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author Thiru
 */
public class MenuForm extends org.apache.struts.action.ActionForm {

private ArrayList arrPriceList;
private String amount;
private String destination;
private ArrayList menuList;

    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public ArrayList getArrPriceList() {
        return arrPriceList;
    }

    public void setArrPriceList(ArrayList arrPriceList) {
        this.arrPriceList = arrPriceList;
    }

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public ArrayList getMenuList() {
        return menuList;
    }

    public void setMenuList(ArrayList menuList) {
        this.menuList = menuList;
    }

}

thank U

View Answers

Ads









Related Tutorials/Questions & Answers:
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below pls correct my code  my Code Given below Pls... help me send correct code for me jsp file... <%@page contentType="text/html" pageEncoding
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below pls correct my code  my Code Given below Pls... help me send correct code for me jsp file... <%@page contentType="text/html" pageEncoding
Advertisements
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct...  my project has login in whic i should select the company name... value(i.e)company name should match.... pls provide code.... thanx   
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct...  my project has login in which i should select the company name... value(i.e)company name should match.... pls provide code.... thanx   1
jsp code for a drop down box to retrive value from database
jsp code for a drop down box to retrive value from database  my project needs to get the value from database in to the drop down box..... pls give me code for that ..... tan q   1)login.jsp: <html> <script>
pls send code
pls send code   pls send code for set database value into text box based on selected value in struts and jsp   use any database and get its code for getting values from google
I am not able to display the selected value of my combobox
I am not able to display the selected value of my combobox   <?php echo "<select name=\"hello\">\n"; echo "<option value=\"NULL\">...; $select='<select size=1 name="unitcode">'; while($arrayRow = mysql_fetch
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
retrieve the data to text fields from database on clicking the value of combo box
retrieve the data to text fields from database on clicking the value of combo box   retrieve the data to text fields from database on clicking the value of combo box . I am not getting it plz help me out .   hi
How to pass the value of Selected Value of combo box into sql ??
How to pass the value of Selected Value of combo box into sql ??  My SQL Database Name is MHS, user=root, password=admin,table name is sub_comb(regno,sname,sgen). Now i want to select one "regno" from Combobox and then after
my table should be reseted to new value upon the selection of the combo box..
my table should be reseted to new value upon the selection of the combo box... the constructor to initialize the form. * WARNING: Do NOT modify this code.... */ // <editor-fold defaultstate="collapsed" desc="Generated Code">
how to display textbox value based on selected option value?
how to display textbox value based on selected option value?  Hi,I... on first value I finished above code. ID: xx Name:xx xx is baesd on second and first value. But it is that l can't do that. now, l post my code
add text box and select list dynamically and get its value to store it into database using jsp request parameter
add text box and select list dynamically and get its value to store it into database using jsp request parameter  its very helpful when you have only dynamically added text field but want code to retrive value of dynamically
jsp login code ... when username , drop down box and password is correct
value is correct.... the drop down box values should be retrieved from database....... the value is retrieved from database into combo box..... but the validation... but its showing as wrong..... i dont know how to check the combo box selected value
how to know which jList is selected and according to that fetch the value
is selected so that i get the value of employee_id from the correct jList (i.e which is selected) to fetch data from database using selected employee id from selected...how to know which jList is selected and according to that fetch the value 
retrieve value from db in text box + calendar implementation.
there is already a text box..Now i want to get the value retrieved from database...retrieve value from db in text box + calendar implementation.  I have used http://www.roseindia.net/javascript/javascript-calendar.shtml code
if my database(oracle) connection failure means wat is the code to write in exception ?
if my database(oracle) connection failure means wat is the code to write in exception ?  if my database(oracle) connection failure means wat is the code to write in exception
Solve my code
Solve my code  import javax.servlet.*; import javax.servlet.http.... response)throws ServletException, IOException{ response.setContentType("text/html... is the mistake in this code! This is working only one record doesn't work
Probblems with printing if my innput of text file is correct..
Probblems with printing if my innput of text file is correct..  I am trying to make sure this block of code does what I think it will do. Can someone show me with some code how I can print out what is is labled with <----print
How to assign a default value to text box in netbeans
How to assign a default value to text box in netbeans  I have a java application,and i want to assign a default variable to the textbox
populating text box using jsp code
populating text box using jsp code  Sir, How to populate related values in a text box after selecting value from drop down list using JSP and mysql...;%=value%>" selected disabled><%=value%></option> <
Insert value of dynamic generated text box in jsp using javascript
that dynamically generated text box value into database at a time without...Insert value of dynamic generated text box in jsp using javascript  hello sir , i want to generate dynamic text box at run time and i did that using
I need jsp code for how to write text field value into property file.
I need jsp code for how to write text field value into property file.  Hi , I need to set the text field value into property file using jsp code. Example : Username : Valar , I have entered the value "Valar" in the text field
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly
ajax ?my code is below bt i cundt get it properly   index.html <... type="text" name="address" id="address" value=""></td></tr> <... type="text" name="email" id="email" value=""></td></tr> <
code for selected checkbox columns data from database
code for selected checkbox columns data from database  in my page iam... one or more checkboxes i have to get data of that selected columns only. what is the jsp code for this thanks in advance kalyani
What's wrong with my pagination code in JSP?
What's wrong with my pagination code in JSP?  Dear experts, I've...; print("code sample");   JSP Pagination The given code retrieves... whatever lines that NetBean IDE has given me error signal. The resulted page
how to update combobx's selected value to database with respect toselected multiple checkboxes
how to update combobx's selected value to database with respect toselected... values which is selected from form1.jsp String languages=""; String box... to display records from database out.println("<tr><td>"+"<input type
Please help me to modify my java code from php code
Please help me to modify my java code from php code  i want to covert...]); $array[] = $item[1]; } } I tried like this (see below JSP code...; <tr> <td><input type="text" name="bid" value="<
combo box value
combo box value   i want to populate one combo box value based on another combo box value using ajax   1)country.jsp: <%@page...; <script language="javascript" type="text/javascript"> var
. Display JavaScript dropdown selected value
value from dropdown box? I am using javascript.   <html> <...("dropdown").value; alert("You selected : " + dropdownValue); } <... dropdownValue we are storing the selected value by using
how to delete the access database value in jsp
how to delete the access database value in jsp  i loaded my database data into the dropdown list box...now i want to delete the value..plz send the source code to delete the value in dropdown list box and also from database

Ads