lundi 6 juillet 2015

How to window.location.href using if

I making "select" which options are 'Edit', 'Delete'. When I click "Edit", the page goes to the "edit_product.jsp" well. But when I click "Delete", the page goes to the "edit_product.jsp" again, not "delete_product.jsp". I want to just click select option, which is going other page -"Edit" is "edit_product.jsp", and "Delete" is "delete_product.jsp"-.

Here is the code.

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<% request.setCharacterEncoding("utf-8"); %>
<%@ page language="java" import="java.sql.*,java.util.*" %>

<jsp:include page="../basis/basis.jsp" flush="false"  />

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ift.tt/kTyqzh">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" charset="UTF-8">
<link rel="StyleSheet" href="product.css" type="text/css">
<script src="../basis/basis.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $(".all_check").click(function() { //select all
        ..
    });

    $('.edit_select').change(function() {
        if ($('.edit_select option[name=edit]:selected')) {
            window.location.href="edit_product.jsp?code="+$('.edit_select option[name=edit]:selected').val();
            return;
        } else if ($('.edit_select option[name=delete]:selected')) {
            window.location.href="delete_product.jsp?code="+$('.edit_select option[name=delete]:selected').val();
            return;
        }
    });
});
</script>
</head>
<body>

<div class="hhh">
    All Products
</div>
<div class=" add_btn btn-group" role="group">
    ..
</div>

<center>
<div class="all_product">
    <table class="table" data-toggle="table">
        <tr>
            <th></th>
            <th>
                check <br />
                <input type="checkbox" name="all_check" class="all_check" />
            </th>
            <th>Product Code</th>
            <th>Image</th>
            <th>Price</th>
            <th>Status</th>
            <th>Business Group</th>
            <th>Category</th>
            <th>Stock</th>
            <th>Supplier</th>
            <th>Marketplaces</th>
            <!--
            <th>Added Time</th>
            <th>Added User</th>
            <th>Modified Time</th>
            <th>Modified User</th>
            -->
        </tr>
                <%
                    Vector product_code = new Vector();
                    Vector image = new Vector();
                    Vector price_cny = new Vector();
                    Vector status = new Vector();
                    Vector bus_grp = new Vector();
                    Vector category = new Vector();
                    Vector stock = new Vector();
                    Vector supplier = new Vector();
                    Vector market = new Vector();

                    Connection con= null;
                    Statement st =null;
                    ResultSet rs =null;

                    String img = "";
                    String url = "http://localhost/Becomeus/Scripts/Products/image/";

                    try {
                        Class.forName("org.gjt.mm.mysql.Driver");
                    } catch (ClassNotFoundException e ) {
                        out.println(e);
                    }

                    try{
                        con = DriverManager.getConnection("jdbc:mysql://localhost/becomeus?useUnicode=true&characterEncoding=utf8","root","qlzjadjtm!2");
                    } catch (SQLException e) {
                        out.println(e);
                    }

                    try {
                        st = con.createStatement();
                        String sql = "select * from new_product";
                        rs = st.executeQuery(sql);

                        if (!rs.next()) {
                            out.println("No Product.");
                        } else {
                            do {
                                product_code.addElement(rs.getString("product_code"));
                                image.addElement(rs.getString("image"));
                                price_cny.addElement(new Integer(rs.getInt("price_cny")));
                                status.addElement(rs.getString("status"));
                                bus_grp.addElement(rs.getString("business_group"));
                                category.addElement(rs.getString("category"));
                                stock.addElement(new Integer(rs.getInt("stock")));
                                supplier.addElement(rs.getString("supplier"));
                                market.addElement(rs.getString("marketplaces"));
                            } while(rs.next());
                            int totalrows = product_code.size();

                            for (int j=0; j<=(totalrows-1); j++) {
                                String pro_code = (String)product_code.elementAt(j);

                                out.println("<tr>");
                                out.println("<td>"); //select
                                out.println("<select name='edit_select' class='edit_select selectpicker' data-width='100px'>");
                                out.println("<option data-hidden='true'>-Select-");
                                out.println("<option name='edit' value="+product_code.elementAt(j)+">Edit");
                                out.println("<option name='delete' value="+product_code.elementAt(j)+">Delete");
                                out.println("<option value='duplicate'>Duplicate");
                                out.println("<option value='print'>Print");
                                out.println("<option value='viewrecord'>View Record");
                                out.println("</select>");
                                out.println("</td>");
                                out.println("<td>"); //check box
                                out.println("<input type='checkbox' name='check'  />");
                                out.println("</td>");
                                out.println("<td><a href='#' class='product_code'>"+product_code.elementAt(j)+"</a></td>");
                                out.println("<td><img width=100 height=100 src='image/"+image.elementAt(j)+"'   /></td>");
                                out.println("<td>"+price_cny.elementAt(j)+"</td>");
                                out.println("<td>"+status.elementAt(j)+"</td>");
                                out.println("<td>"+bus_grp.elementAt(j)+"</td>");
                                out.println("<td>"+category.elementAt(j)+"</td>");
                                out.println("<td>"+stock.elementAt(j)+"</td>");
                                out.println("<td>"+supplier.elementAt(j)+"</td>");
                                out.println("<td>"+market.elementAt(j)+"</td>");
                                out.println("</tr>");
                            }
                            rs.close();
                        }
                        st.close();
                        con.close();
                    } catch (java.sql.SQLException e) {
                        out.println(e);
                    }
                %>
    </table>
</div>
</center>
</body>
</html>

I using jQuery and jsp. Can "window.location.href" use only one? I using "if-else if", but no action to "else if". How can I use? Please answer to me. Thanks.

Aucun commentaire:

Enregistrer un commentaire