newbie question: inserting text into a textarea

L

lawrence

I'm getting errors on my page, even with a lot of this function
commented out. Can anyone tell me what I'm doing wrong? I'm new to
Javascript (though I know a fair about of Java and PHP) and I'm
wondering what mistake I'm making.

is this:

document.forms.pdsForm.imagesToInsert.value

the correct way to get a value using items ids? The id names are
correct (pdsForm.imagesToInsert), one for the form and the second for
the textarea that I want to get.



function insertAtCursor(myField) {
var imageName = '';
var path = '';
var myValue = '';
var status = '';

imageName = document.forms.pdsForm.imagesToInsert.value;
alert(imageName);
window.status= imageName;

path = '$path';
myValue = path+imageName;

status = myValue + ' - ' + myField;
window.status= status;

// document.forms.pdsForm.inputId3.value += myValue;
//document.forms['form'].elements['field']
// //IE support
// if (document.selection) {
// myField.focus();
// sel = document.selection.createRange();
// sel.text = myValue;
// } else if (myField.selectionStart || myField.selectionStart ==
'0') {
// //MOZILLA/NETSCAPE support
// var startPos = myField.selectionStart;
// var endPos = myField.selectionEnd;
// myField.value = myField.value.substring(0, startPos) + myValue +
myField.value.substring(endPos, myField.value.length);
// } else {
// myField.value += myValue;
// }
}
 
K

kaeli

I'm getting errors on my page,


What's the error?
document.forms.pdsForm.imagesToInsert.value

Well, more cross-browser would be
document.forms["pdsForm"].elements["imagesToInsert"].value

Check case. Javascript is case-sensitive.

You should have (name is optional but required for some CGIs and old
browsers like NN4)

<form name="pdsForm" id="pdsForm">
<textarea name="imagesToInsert" id="imagesToInsert"></textarea>

Note that some browsers allow you to turn off the ability for script to
modify the status bar text. I know mine's off. ;)

--
 
L

lawrence

kaeli said:
I'm getting errors on my page,


What's the error?
document.forms.pdsForm.imagesToInsert.value

Well, more cross-browser would be
document.forms["pdsForm"].elements["imagesToInsert"].value

Check case. Javascript is case-sensitive.

You should have (name is optional but required for some CGIs and old
browsers like NN4)

<form name="pdsForm" id="pdsForm">
<textarea name="imagesToInsert" id="imagesToInsert"></textarea>

Note that some browsers allow you to turn off the ability for script to
modify the status bar text. I know mine's off. ;)


That's good to know about needing both "name" and "id". I thought it
was bad to have both. I'll add back in the name.

The status bar is scriptable on my browser. At one point it correctly
showed the path to the image. At that time my only problem was getting
it to write to the textarea. Now it won't even show the path to the
image.
 
K

kaeli

That's good to know about needing both "name" and "id". I thought it
was bad to have both. I'll add back in the name.

You don't NEED to have both unless you're using things that need them.
To use document.getElementById type functions, you need ID. To have form
elements be accessible to many CGI apps, such as Perl, you need NAME.
So, if you're using both, you need both. ;)
I'm just used to putting them both there, JIC.

IIRC, neither is *required* in HTML specs.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top