Automatic filling of textbox with data type String with JavaScript and JSP

0

I have a problem with a filling I do with JavaScript when it comes to the functionality of a form in which I manage the database, it has the buttons to insert, delete, modify and display. When I want to delete or modify I use a function that selects the data from the database and fills them in its respective textbox.

My problem is that at the time that a string type data has a space, I do not directly fill any textbox.

This is my filling method.

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script>
            function llenar(codigo,nombre,precio,pro)
                {
                    document.getElementById("idd").value=codigo;
                    document.getElementById("nombree").value=nombre;
                    document.getElementById("precioo").value=precio;
                    document.getElementById(pro).selected=true;


                }
        </script>
    </head> 

This is the table where I send my method.

<%     
            out.println("<table border=1>"
                    + "<tr>"
                        + "<th>ID</th>"
                        + "<th>NOMBRE</th>"
                        + "<th>PRECIO</th>"
                        + "<th>PROVEEDOR</th>"
                    + "</tr>");                    

            for (Producto m:ar){
                out.println("<tr>"
                        + "<td>"+m.getIdproducto()+"</td>"
                        + "<td>"+m.getNombreproducto()+"</td>"
                        + "<td>"+m.getPrecio()+"</td>"
                        + "<td>"+m.getPro().getNombreprov()+"</td>"
                        + "<td>"
                        + "<a href=javascript:llenar('"+m.getIdproducto()+"','"+m.getNombreproducto()+"',"
                        + "'"+m.getPrecio()+"','"+m.getPro().getIdproveedor()+"')>Seleccionar</a>"
                        + "</td>"
                        + "</tr>");
            }
            out.println("</table>");

            }catch(Exception e){}
        %>

HTML of my form

<tr>
                <td>ID:</td>
                <td><input type="text"  id="idd" name="id" readonly="readonly"></td>
            </tr>
            <tr>
                <td>Nombre:</td>
                <td><input type="text" id="nombree" name="nombre"></td>
            </tr>
            <tr>
                <td>Precio:</td>
                <td><input type="text" id="precioo" name="precio"></td>
            </tr>
            <tr>
                <td>Proveedor:</td>
                <td>
                     <select id="provv" name="prov">
                           <%
                           for(Proveedor m:ar1){
                               out.println("<option id='"+m.getIdproveedor()
                                                    +"' value='"+m.getIdproveedor()
                                                    +"'>"+m.getNombreprov()+"</option>");
                                        }

                                    %>
                                </select>
                            </td>
            </tr>

If in one of the classes it has a data with a space, it does not add anything in any textbox.

But if in the classes that have String values, and do not have a space, if you add them in their respective textbox.

How can I do it so that I can add them if I put two names in a class?

    
asked by DagsDroid 03.11.2017 в 17:34
source

1 answer

1

how are you?

Try to do the following: The idea is to replace the empty spaces in the string with "" so you can try the following:

var text = 'Tu texto con espacios';
var result = text.replace(/ /g, "&nbsp;");
console.log(result); //Tu&nbsp;texto&nbsp;con&nbsp;espacios

Good luck!

    
answered by 03.11.2017 / 22:05
source