-
Moving Information from list box to textarea
Hi guys,
I have a problem with my javascript. I need to move values in the list box to a textarea in the same page but in different forms. When i select the value in the list box and click on the button it should print something like this:
start telnet 192.168.111.80
start /w LAN789.vbs
cls
start telnet 192.168.111.81
start /w LAN789.vbs
cls
The IP address is a value from the list box. I am also wondering if it is possible to select multiple and print it all out in the textarea like the above. The list box get its values from the database.
Thanks
Irwin
-
Re: Moving Information from list box to textarea
What have you got so far ?
To get help with your code, you have to show us your code.
-
Re: Moving Information from list box to textarea
This is my javascript:
<SCRIPT LANGUAGE="JavaScript"><!--
function additive() {
document.form1.BATfile.value += document.form1.select1.options[document.form1.select1.selectedIndex].text + "\n";
}
//--></SCRIPT>
This is my list box:
<form name="form1" method="post" action="">
<select name="select1" size="10">
<%
While (NOT objRS.EOF)
%>
<option value="<%=(objRS.Fields.Item("GRP").Value)%>" <%If (Not isNull((objRS.Fields.Item("GRP").Value))) Then If (CStr(objRS.Fields.Item("GRP").Value) = CStr((objRS.Fields.Item("GRP").Value))) Then Response.Write("SELECTED") : Response.Write("")%> ><%=(objRS.Fields.Item("GRP").Value)%></option>
<%
objRS.MoveNext()
Wend
If (objRS.CursorType > 0) Then
objRS.MoveFirst
Else
objRS.Requery
End If
%>
</select>
<br>
<input type="submit" name="Submit" value="Add" onClick="additive()">
<br>
</form>
This is the textarea:
<form action="<%=request.ServerVariables("SCRIPT_NAME")%>" method="post" name="formBATfile" id="formBATfile">
<font color="#4799B6" face="Arial, Helvetica, sans-serif">Enter BAT Commands:</font><br>
<textarea name="BATfile" cols="55" rows="18" wrap="VIRTUAL"><%=textFile1%></textarea>
<br>
<input name="saveBat" type="submit" id="saveBat" value="Save">
<input type="hidden" name="VB" value="<%=request("VB")%>">
<input type="hidden" name="BAT" value="<%=request("BAT")%>">
<input type="hidden" name="callback1" value="true">
</form>
Thanks
Irwin
-
Re: Moving Information from list box to textarea
This line
Code:
document.form1.BATfile.value += document.form1.select1.options[document.form1.select1.selectedIndex].text + "\n";
Should be
Code:
document.formBATfile.BATfile.value += document.form1.select1.options[document.form1.select1.selectedIndex].text + "\n";
And you might want to change the type attribute on the form1 add button from 'submit' to 'button' this avoids having the page reload to it's original state every time you press add.
-
Re: Moving Information from list box to textarea
Thanks for the help. I can now add the value in.
But there is still the other values like
start telnet 192.168.111.81
start /w LAN789.vbs
cls
The other values are fixed, is it possible to add them in.
If I want it to be able to add multiple values(shown above) how it is done.
Thanks
Irwin
-
Re: Moving Information from list box to textarea
This page shows an example of working with a multiselect in javascript.
http://www.mredkj.com/tutorials/tutorial004.html
-
Re: Moving Information from list box to textarea
Thanks alot. But I have values in the textarea and the values i send to the textarea is at the bottom of the textarea. How do I move it to the top.
Irwin
-
Re: Moving Information from list box to textarea
Quote:
Originally Posted by lchi
Thanks alot. But I have values in the textarea and the values i send to the textarea is at the bottom of the textarea. How do I move it to the top.
I would think something like
Code:
document.formBATfile.BATfile.value = document.form1.select1.options[document.form1.select1.selectedIndex].text + "\n" + document.formBATfile.BATfile.value;
Should do.
-
Re: Moving Information from list box to textarea
Thanks. But how you add the other values like
start telnet xxx.xxx.xxx.xxx
start /w LAN789.vbs
cls
Please help me on this.
-
Re: Moving Information from list box to textarea
Quote:
Originally Posted by lchi
Thanks. But how you add the other values like...
Ehh, add more options to the select.
Perhaps I'am not quite understanding you.
-
Re: Moving Information from list box to textarea
What I mean is when I add the IP address in, the other values will be added in the textarea as shown like this:
start telnet xxx.xxx.xxx.xxx
start /w LAN789.vbs
cls
The xxx.xxx.xxx.xxx being the value from the list box and the other values are fixed.
Sorry if I was not clear.
Thanks
Irwin
-
Re: Moving Information from list box to textarea
Don't you have any understanding of what a line like
Code:
document.formBATfile.BATfile.value = document.form1.select1.options[document.form1.select1.selectedIndex].text + "\n" + document.formBATfile.BATfile.value;
Does ?
It concatenates strings and assings the result to the text area.
To add more fixed values to the text area just add more string literals to the above line. Something like
Code:
document.formBATfile.BATfile.value = "start telnet " + document.form1.select1.options[document.form1.select1.selectedIndex].text + "\nstart /w LAN789.vbs\ncls\n" + document.formBATfile.BATfile.value;
-
Re: Moving Information from list box to textarea
I do not understand that line. I am very new at this and I only know very simple things. I am trying to understand the codes but it prove very difficult.
Irwin
-
Re: Moving Information from list box to textarea
Well I'll this is what this line does:
Code:
document.formBATfile.BATfile.value = document.form1.select1.options[document.form1.select1.selectedIndex].text + "\n" + document.formBATfile.BATfile.value;
Replace the content of the element named BATfile in the form named formBATfile with the content of the currently selected item in the list box named options appended to what is already in the element BATFile.
Hence, if the element BATfile contains the text:
"is my name"
and the value of the text of the currently selected list item is "Adam" then the above line of code will change the text of the element BATfile to:
"Adam
is my name"
I am afraid I cannot make it any clearer.
-
Re: Moving Information from list box to textarea
Quote:
Originally Posted by lchi
I do not understand that line. I am very new at this and I only know very simple things. I am trying to understand the codes but it prove very difficult.
Irwin
You need to go read some more tutorials, and don't just copy their code, try to understand what they are doing.
http://www.w3schools.com/js/default.asp
You cannot develop a javascript by asking for help everytime you need to change the tiniest bit.
-
Re: Moving Information from list box to textarea
Thanks both of you. I am starting to understand a little. I will do the tutorials to learn more. I will post more if i have any question. Thanks alot guys.
Irwin
-
Re: Moving Information from list box to textarea
I am now doing the multiselect. I can now multiselect and get the values but I do not know how to spilt the values. This is the code I am using, I understand what it does but I do not know how to seperate the values.
Irwin
-
Re: Moving Information from list box to textarea
Quote:
Originally Posted by lchi
...This is the code I am using...
Either I'am going blind or you didn't post your code.
As for seperating the values in a multiselect that is explained in the page I posted a link to back in comment #6.
You might also want to take a look at some string functions
http://www.w3schools.com/js/js_obj_string.asp
-
Re: Moving Information from list box to textarea
Opps looks like I forgot haha. I was in a hurry yesterday.
Here are the codes.
function loopSelected()
{
var BATfileObj = document.getElementById('BATfile');
var selectedArray = new Array();
var selObj = document.getElementById('select1');
var i;
var count = 0;
for (i=0; i<selObj.options.length; i++) {
if (selObj.options[i].selected) {
selectedArray[count] = selObj.options[i].value;
count++;
}
}
BATfileObj.value = selectedArray;
}
I got it from the codes from the tutorial you give me. The values it gives out are in this form value1,value2,value3,value4. I want to seperate the values. How do you do it.
Irwin
-
Re: Moving Information from list box to textarea
Quote:
Originally Posted by lchi
I want to seperate the values. How do you do it.
Ehh, you already got the values seperated inside the 'for' loop on this line
Code:
selectedArray[count] = selObj.options[i].value;
I assume what you meant to say, was that you want each of values the values on a line by itself, in the text area.
Again You obviouly haven't been paying any attention to what I have been telling you about concatenating strings.
To get the select values, each on a line by itself, you could just replace the above line with
Code:
selectedArray += selObj.options[i].value + "\n";
Although this is bit of a misnomer on my part, since selectArray is now a string rather than a Array of strings.
And once again please read some more tutorials and try to put a lot more work into your problems before asking for help. As far as I'am concerned you are rapidly becoming the boy how cried wolf.
-
Re: Moving Information from list box to textarea
Thanks. What I don't understand is the array part I thought that
for (i=0; i<selObj.options.length; i++) {
if (selObj.options[i].selected) {
selectedArray[count] = selObj.options[i].value;
count++;
this part just all the values and put it together I was not sure so I ask.
Sorry for the problem I cause. But I thank you for teaching me alot.
But one more question what is the count and count++ for?
Thanks
Irwin
-
Re: Moving Information from list box to textarea
Quote:
Originally Posted by lchi
But one more question what is the count and count++ for?
Again I must strongly suggest that you go read some tutorials, the ++ operator is explained at http://www.w3schools.com/js/js_operators.asp
You are building an array of the selected options from all the options, Every time you find a selected option you insert the value into result array at position count. And increment the count variable so that the next selected option will be inserted at the next position in the result array.
-
Re: Moving Information from list box to textarea
Thank you I understand what you mean. I know what a ++ means I was just wondering what the count is for as there is var i for the values. So the count is for selected values. Thanks alot.
Irwin