Click here to Skip to main content
15,889,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to get id as a character instead of number in the line

machineCode = $(this).attr('id');


how can i do this?

HTML
<%@page import="java.sql.ResultSet"%>
<%@page import="org.dst.utils.Constants"%>
<%@page import="org.eclipse.jdt.internal.compiler.impl.Constant"%>
<%@page import="org.dst.db.conn.pool.Pool"%>
<%@page import="org.dst.db.conn.pool.DBConnection"%>
<%@page import="org.dst.db.conn.pool.DBConnection"%>
<%@page import="java.sql.Statement"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<jsp:include flush="false" page="header.jsp" xmlns:jsp="#unknown"></jsp:include>
<link rel="stylesheet" href="css/jquery-ui.css">
<script type="text/javascript" src="js/jquery-ui-min.js"></script>
<script>
    machineCode = 'A';
    $(document).ready(function() {
        $( "#fromDate" ).datepicker({ dateFormat: "dd/mm/yy"});
        $( "#toDate" ).datepicker({ dateFormat: "dd/mm/yy"});
        
        // ------------------ For Setting up the Report URL
        // Handle the Submit button
        $("#getReport").click(function() {
            event.preventDefault();
            var urlMade = "/epcserver/MachineWiseService?fromDate=" +
                $("#fromDate").datepicker( "getDate" ).getTime() + "&toDate=" + 
                $("#toDate").datepicker( "getDate" ).getTime() + "&<%=Constants.userId%>=" + 
                <%=String.valueOf(session.getAttribute(Constants.userId))%> + "&<%=Constants.machineCode%>=" + machineCode;
            // View iFrame to the Page/Refresh the iFrame URL
            $("#reportContainer").attr("src", urlMade);
        });    
        $("#_getReport").click(function(){ 
            var urlMade = "/epcserver/MachineWiseService?fromDate=" +
                $("#fromDate").datepicker( "getDate" ).getTime() + "&toDate=" + 
                $("#toDate").datepicker( "getDate" ).getTime() + "&<%=Constants.userId%>=" + 
                <%=String.valueOf(session.getAttribute(Constants.userId))%> + "&<%=Constants.machineCode%>=" + machineCode;
            $("#_getReport").attr("href", urlMade);
        });
        
        // ------------------ For Setting up the MachineCode to the variable
        $(".machineSelector").click(function() {
            $(".machineSelector").removeClass('active');
            machineCode = $(this).attr('id');
            $(this).addClass('active');
        });
     });
</script>
<div id="container">
    <div class="row mywell">
        <div class="span11" style="padding-removed 10px; border-removed #DDD 1px solid;">
            <h2 style="text-align: center;">
                Select Machine ID & Dates to view the Report.
            </h2>
        </div>
        <div class="span11">
            <div class="btn-toolbar span5">
                <div class="btn-group">
                    <%
                        DBConnection dbConn = Pool.getInstance().getDBConnection();
                        Statement statement = dbConn.getConnection().createStatement();
                        ResultSet rs = statement.executeQuery("SELECT ID FROM epcserver.machine where ID_USERS = " + session.getAttribute(Constants.userId));
                        while (rs.next()) {
                            out.print("<button class='btn machineSelector' id=" + (rs.getString("ID")) + ">" + (rs.getString("ID")) + "</button>");
                        }
                        Pool.releaseConnection(dbConn);
                    %>
                </div>
            </div>

            <div class="span5" style="margin-removed 9px;margin-removed 9px;">
                <form class="form-inline" action="">
                    <input id="fromDate" type="text" class="input-small" placeholder="From Date"/>
                    <input id="toDate" type="text" class="input-small" placeholder="To Date"/>
                    <button id="getReport" type="submit" class="btn">Get Report</button>
                    <a id="_getReport" target="_new" class="btn">Get Report In New Tab</a>
                </form>
            </div>
        </div>
    </div>
    <div class="row">
        <iframe class="span12" height="400px" id="reportContainer" src=""/>
    </div>
</div>
<jsp:include flush="false" page="footer.jsp" xmlns:jsp="#unknown"></jsp:include>
Posted
Updated 2-Jul-13 1:39am
v3
Comments
ZurdoDev 2-Jul-13 7:52am    
What do you mean? It is returning a string isn't it?

The id attribute is being copied from the ID field in your resultset. My guess is that this an autonumber field and, hence, is always numeric. If I understand correctly, all that you want to do is to convert that numeric value to a text; in which case, change both instances of rs.getString("ID") to CStr(rs.getLong("ID")). I'd recommend not having fully numeric IDs in HTML attributes and would, hence, suggest changing id=" to (for example) id=X". this would return X<number> in your $(this).attr('id') which you can convert back to a number-as-text by using $(this).attr('id').substring(1) or to a number-as-number by using $(this).attr('id').substring(1).valueOf().
 
Share this answer
 
Comments
Sohushah 4-Jul-13 1:57am    
i used CStr(rs.getLong("ID")) in both the instance....but it shows
"cannot find symbol
symbol: method CStr(long)
location: class SimplifiedJSPServlet
Doh! I hadn't looked hard enough and had missed the fact that it was JSP. Try rs.getLong("ID").toString(). I am, of course, assuming that ID is a column in your table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900