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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

returning multiple checkbox values to textarea

Status
Not open for further replies.

staffa

Programmer
Jan 31, 2005
32
DK
Hi

I've made a script that generates a popup window with checkbox options that onclick gets send to a textarea on the opener page and it works, but the problem is that the checkbox values overwritte eachother when they are passed to the textarea.

Here is my script:
Code:
function check(){
infoservices = document.forms[0].elements
inp_services = self.opener.document.form_tilfoej.inp_services
txt=""
for (i=0;i < infoservices.length; i++){
if (infoservices[i].checked){
txt = infoservices[i].value
}
inp_services.value = txt
}
}
I hope someone can help.
 
staffa,

Try this.
[tt]txt [red]+[/red]= infoservices.value
[/tt]
regards - tsuji
 
With better format like line separator or else, like this.
[tt]
txt += infoservices.value + "\n";
[/tt]
- tsuji
 
Hi tsuji and thanks for your quick reply.

I'm not able to use "\n" because the script is generatet by another script:

generator.document.writeln('txt += infoservices.value');
 
Do you know a way to get around that problem?

Thanks.
 
staffa,

This would do?
[tt]
generator.document.writeln('txt += infoservices.value'+'<br />');
[/tt]
- tsuji
 
Or this - I don't see quite clearly your setup, but for textarea eventually it has gone to, this might do.
[tt]
generator.document.writeln('txt += infoservices.value'+'\n');
[/tt]
(Do not see why you raised a concern previously, but try it.)

- tsuji
 
Thanks again, but it still doesn't work.

The generator makes a popup with a form full of checkbox options and the script to handle the form and pass the values to the opener page, so when the generator reads the \n it makes a line break in my script in the popup.

Hope that make sens :)

Staffa
 
staffa,

To pass to the textarea, it would be this, I think after looking more closely your description.
[tt]
generator.document.writeln('txt += infoservices.value'+'[COLOR=red yellow]\[/color]\n');
[/tt]
wiht "\" escaped.

- tsuji
 
Clearing up the quote misplaced! (what a mess!)
[tt]
generator.document.writeln('txt += infoservices.value+"\\n"');
[/tt]
- tsuji
 
This is a quick & dirty demo.
Code:
<html>
<head>
<script language="javascript">
function winopen() {
	var owin=window.open("","popup");
	with (owin.document) {
		writeln("<html><head><script>");
		writeln("function mopup() {");
		//simplified version, unrelated to checkbox status
		writeln("self.opener.txtarea.value='a\\nb\\nc'");
		writeln("self.close();");
		writeln("}");
		writeln("<\/script><\/head><body><form name='abc'>");
		writeln("<input type=checkbox name=chkbox value='a'>a<\/input>");
		writeln("<input type=checkbox name=chkbox value='b'>b<\/input>");
		writeln("<input type=checkbox name=chkbox value='c'>c<\/input>");
		writeln("<button name=closewin onclick='mopup()'>close<\/button>");
		writeln("<\/form><\/body><\/html>");
	}
}
</script>
</head>
<body>
<button name="makewindow" onclick="winopen()">select checkboxes</button><br />
<textarea name="txtarea"></textarea>
</body>
</html>
- tsuji
 
Escaping the \n works great :-D
I've tryet to find this solution with the \n for days, because the real thing is that it's a javascript in a javascript in a php script, and thats why it was a bit difficult for me :)

Big thanks again.

Staffa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top