Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting value of text area problem

Status
Not open for further replies.

danmul

Programmer
Jan 16, 2003
89
IE
Hi,
This is the code that is generated when I re-call. The value in the text area has been pasted from an excel sheet in the first form. I get an unterminated string constant error from the browser. Is there a way around this?
Thanks,
Daniel.
<SCRIPT>document.insert.i_part_desc.value = "Part1 UOM1 100 21/01/2004 DESC1
Part2 UOM2 333.33 1/10/2004 DESC2
Part3 UOM3 99999 5/06/2004 DESC3
Part4 UOM4 123456 4/06/2004 DESC4
";</SCRIPT>
 
Ummm, well it looks like you're splitting the quoted string across lines which would cause that error.

Once you've fixed that you're going to get a 'document.insert has no properties' error unless that's something you've defined already. Have you?
 
Hi,
The problem is with the lines because if I send one line then it it works OK. How do I get around this or I am after hitting a wall?
Thanks,
daniel.
 
Like this:

document.insert.i_part_desc.value = "Part1 UOM1 100 21/01/2004 DESC1\nPart2 UOM2 333.33 1/10/2004 DESC2\nPart3 UOM3 99999 5/06/2004 DESC3\nPart4 UOM4 123456 4/06/2004 DESC4";
 
In explanation, you have to put the whole thing on one line, as you discovered. If you want to display several lines in a textarea, use the \n, which is the newline character. If you were to display the same string in the HTML area, you'd use <br> instead.

Lee
 
OK, two questions, How do I check in javascript that I am at the end/start of line to insert the \n. Also, this data is being sent to a procedure to be loaded into DB. My worry is that the format which I am checking for new lines, carriage returns, field de-limiters(I use ASCII values to check these) will be lost. Would this be true?
 
I'd split the textarea text into an array with one line each. How you do that depends on what language you're using on the page submitted to. A JScript possibility would be:

var dataarray=new String(Request('mytextarea')).split('\n');

Then you can split each element of the array into the appropriate fields for the database the way you normally would.

You asked how you'd check to see if you were at the end of a line to insert the newline character in Javascript. How do you check now to do that? You initially wrote that it was pasted in from an Excel spreadsheet. At the end of each line you paste in between the quotation marks, use \n instead of hitting the return key on your keyboard. If you're going though an array to create the string to be pasted in, then have the programming insert a \n after each array element.
 
Hi, will try the array. About the end of line. When I paste this into the text area first and hit submit button, the form calls the db procedure and loads into db perfect. I do not need to show data on next page. But I have a drop down list that when changed just re-loads the page to change some default values. This is where I hit the problem because the data is not loaded into tables yet it has to be shown.
Thanks,
Daniel.
 
Unless you're going to pass the data in the URL, you'll have to load it into the database to display on the page. Or you can use a cookie to store the info, too.

 
i tried passing it in the URL first. Everything does get passed but it is all on one line. i think i will just create a temp table in the DB. Insert into that and read back from that. Thanks for all teh help,
daniel
 
When you pass the data, you can put a special character between the rows and then replace that character with a newline character (\n when you write it into the textarea.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top