try this
e.g.
function IdentifyText(fieldname, text )
{
//your code goes here
}
<form name='form1'>
<input type='text' name='t1'>
<input type='button' name='b1' onClick='IdentifyText(this
</form>
Main Topics
Browse All TopicsMy javascript is still limited and I am getting an error message that tells me I don't understand something that's probably fairly basic.
I have 3 javascript statements that work fine inside an onclick and I want to make them into a function. The problem is that the function has to be called with the name of a field to be changed, and all the examples I have seen have the parameters as values, not as names of fields that can be changed. My current code is:
function IdentifyText(fieldname, text )
{
document.fieldname.insertA
document.fieldname.focus()
document.fieldname.insertA
return;
}
The intent is that "fieldname" is passed as a variable (e.g., UpdateLead.Comment), and the 3 statements operate upon whatever field is supplied (e.g., document.UpdateLead.Commen
I am probably missing something simple in syntax but just can't find an example anywhere to show me the right way to do it.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Grins: What a horrible idea
Just do either of these and see what is passed.
<html>
<head>
<title>Untitled</title>
<script>
function IdentifyText1(fieldObject,
fieldObject.insertAdjacent
fieldObject.focus();
fieldObject.insertAdjacent
return;
}
function IdentifyText2(fieldName, text ) {
document.forms[0].elements
document.forms[0].elements
document.forms[0].elements
return;
}
function IdentifyText3(fieldObject,
fieldObject.value+=String.
fieldObject.focus();
fieldObject.value+=text;
return;
}
</script>
</head>
<body>
<form>
<textarea name="a1"></textarea>
<input type="button" onClick="IdentifyText1(thi
<input type="button" onClick="IdentifyText2('a1
<input type="button" onClick="IdentifyText3(thi
</form>
</body>
</html>
FYI, I worked harder to try to make your suggestions work and this is what happenned:
Identify1 seems to have worked.
Identify2 generated a run time error that said
- - - - - - - - - - - document.forms.0.elements[
(and please note that I coded it as forms[0] just like your example)
Identify3 added the text at the end of the string, not at the start.
I had hoped that your solution would work because ideally I'd like one that works for Netscape too (in case there are any Netscape users left), but it must place the text first and locate the cursor in the correct place or it is of no use.
There is no way to place the cursor in Netscape
However v3 will add text in netscape too.
and here is how to add it in the beginning
function IdentifyText3(fieldObject,
fieldObject.value=text+'\n
return;
}
I was not sure what the script actually did, sorry.
The above script will work in all browsers
and the return is not needed
function IdentifyText3(fieldObject,
fieldObject.value=text+'\n
}
so if the text is in another field then all that is needed is is this:
<div align="center">
<form onSubmit="
this.a1.value=this.f1.valu
this.f1.focus();
this.f1.select();
return false">
<input type="text" name="f1" value=""><br>
<textarea name="a1"></textarea><br>
<input type="submit" value=" Add ">
</form>
</div>
which will add on enter too
Business Accounts
Answer for Membership
by: GrinsPosted on 2003-07-26 at 08:51:50ID: 9011073
i recently learned this myself. ); return false;" and remove the document. from each line in your function so that each line starts with fieldname.
xt('afterB egin',Stri ng.fromCha rCode(13)) ; xt('afterB egin',text );
when you call the function, try onClick="IdentifyText(this
fieldname.insertAdjacentTe
fieldname.focus();
fieldname.insertAdjacentTe
hope this helps.
my first answer to a question, im so excited