TwelvestoneBack End

javascript problem -->


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Mac8myPC
 
2011-03-08

been trying to figure this out for a couple days... still stumped.

using jQuery/php/mysql i'm able to add the correct data from a textarea into a mysql database with this

var details = $('#details').val().replace(/\n/g, '');

converts all the line breaks into tags.

however... for some reason I can't figure out.. when you use JSON to pull the data out of the database, there's no way that seems to work to reverse the process.

I've tried every variation of this...

var reg = new RegExp(""); $.each(data, function(key, val) { details = val['details'].replace(reg, '\n'); }

Javascript won't recognize the "" tag for some reason to replace it with the line break.

DontBogartMe
 
2011-03-08

not really answering your question, but can't you do the BR to line break conversion in PHP before encoding to JSON?

poliguin
 
2011-03-09

also, perhaps enable the m and g flags for the regular expression?

Mac8myPC
 
2011-03-10

Thanks for the tip poliguin, that took care of it..

details = val['details'].replace(//g, '\n');

komal_1028
 
2011-08-29

<%-- Document : komal Created on : Aug 23, 2011, 2:30:45 PM Author : komal --%>

<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

JSP Page

        function validate()
        {
            if(document.form1.t1.value=="")
            {
                document.getElementById("error").style.visibility="visible";
            }
            else {
                document.form1.action="index";

            }}
    </script>
</head>
<body>
    <form name="form1" action="" method="get">
        <input type="text" name="t1" value="" />
        <div class="error" id="error" ><font color="red">First Name is compulsory</font></div>

        <input type="submit" value="submit" name="submit" onclick="javascript:validate();"/>
    </form>
</body>

please make this error visible until i press submit button again

komal_1028
 
2011-08-29

<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!-- Designed by CompanyName Base template (without user's data) checked byhttp://validator.w3.org : "This page is valid XHTML 1.0 Transitional" --> Ask Chak De India function validate(form) { var t3 = form.t1.value; alert(t3); <% Connection conn; Statement stmt; int count=0; int count1=0; String ts = "document.writeln(t3)"; ResultSet rs,rs1 = null; Class.forName("com.mysql.jdbc.Driver"); conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/chakdeindia", "root", "root"); stmt = (Statement) conn.createStatement(); rs = stmt.executeQuery("SELECT * FROM borrower where name ='+t3+' "); if (rs.next()) {%> alert('hello'); <%} else {%> alert('bye'); <%}%> } username:

/pls help me its urgent how to compare variable t3 value with name field of borrower table/

Stinky
 
2011-08-29

Har har! Wow, I hope you're a student and not actually working on a real project.

Technomancer
 
2011-08-29

Awww - come on Stinky - we all had to start somewhere...throw a dog a bone huh? Show him what he's doing wrong...

Stinky
 
2011-08-29

I know that probably came off a bit harsh.

Ok here's the rundown

  • First, you should NEVER put database access code in your views.
  • Mixing JSP code with javascript is not going to get you what you want, the template will be compiled server side, before the script is run.
  • The SQL has an error, it should be " name = '" + t3 + "'"
  • BUT that won't work because t3 is a javascript variable

That's the thing, I don't even know where to begin to help without doing it all for him. Plus people who show up and nearly demand help or to "make this work." sort of irk me, especially since they usually don't ever show up again. Most likely those two posts are the only ones he ever makes on 12s.

DontBogartMe
 
2011-08-31

Originally posted by: Stinky That's the thing, I don't even know where to begin to help without doing it all for him. Plus people who show up and nearly demand help or to "make this work." sort of irk me, especially since they usually don't ever show up again. Most likely those two posts are the only ones he ever makes on 12s.

:thousands_o_trees:

Frankly this "Har har! Wow, I hope you're a student and not actually working on a real project." was more help than he deserved, cos it showed you'd at least skimmed thru his code.

Technomancer
 
2011-08-31

Originally posted by: DontBogartMe Frankly this "Har har! Wow, I hope you're a student and not actually working on a real project." was more help than he deserved, cos it showed you'd at least skimmed thru his code.

:more_trees: that was kinda the point of my post - err...where do you start, there is just so much wrong with it. Probably should have added the k to my original post

Stinky
 
2011-08-31

Ok, I sarcasm failed on that one k

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneBack End

javascript problem --&gt;