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

passing form elements to function as parameter 2

Status
Not open for further replies.

brownfox

Programmer
Jan 5, 2003
173
GB
Why does this work in firefox but not IE?
Code:
<form name="form1" id="form1">
<textarea name="biog" id="biog"></textarea>
<input type="button" name="Button" value="Paragraph" onClick="code('form1','biog','[p][/p]')">
</form>
<script language="JavaScript" type="text/JavaScript">
function code(the_form,form_element,thecode){
document.eval(the_form).eval(form_element).value += thecode;
}
</script>
How do I get this to work in IE?
T.I.A
 
Code:
<form name="form1" id="form1">
<textarea name="biog" id="biog"></textarea>
<input type="button" name="Button" value="Paragraph" onClick="code(this.form,'biog','[p][/p]')">
</form>
<script language="JavaScript" type="text/JavaScript">
function code(the_form,form_element,thecode){
    the_form.elements[form_element].value += thecode;
}
</script>

*cLFlaVA
----------------------------
[tt]a frickin' twelve-gauge, what do you think?[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Avoid using eval whenever possible. It's very processor intensive and almost always unnecessary. The best way to reference your form elements if you have the names would be:

Code:
function code(the_form,form_element,thecode){
   document.forms[the_form].elements[form_element].value += thecode;
}

-kaht

Do the chickens have large talons?
 
I've seen that setting thats evaluated to another value does not work in IE.

just wondering does this work?

var x = eval(the_form);
var y = eval(form_element);
document.x.y.value += thecode;

 
vtatta - no that doesn't work. kaht thanks...prefect
 
How often is it that the person that is late to the submit button gets the star? Oh well, have one on me cory [lol]

-kaht

Do the chickens have large talons?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top