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.
not really answering your question, but can't you do the BR to line break conversion in PHP before encoding to JSON?
also, perhaps enable the m and g flags for the regular expression?
Thanks for the tip poliguin, that took care of it..
details = val['details'].replace(//g, '\n');
<%-- 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
<%@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/
Har har! Wow, I hope you're a student and not actually working on a real project.
Awww - come on Stinky - we all had to start somewhere...throw a dog a bone huh? Show him what he's doing wrong...
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.
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.
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
to my original post
Ok, I sarcasm failed on that one 