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

clear text area from radio button click 1

Status
Not open for further replies.

davidste

Programmer
Mar 7, 2004
15
GB
i have the following function

function clearTxtRadioBtn(txtBoxRbtn)
{
eval("document." + txtBoxRbtn + ".value = "";")
}
called from
onClick="clearTxtRadioBtn('form.txt_box')" in a radio button

but I keep getting the following error message when the page loads

error expected ')'

I have kept the function intact and commented out the code in the function and everything works fine but I dont see where a ')' should be.

Thank you in advance.
 
Change to:

eval("document." + txtBoxRbtn + ".value = '';")

________________________________________
Michael Flanakin
weblogs.getindigo.net/flanakin
 
Notice that I replaced the quotes with ticks when setting the value of the textarea.

________________________________________
Michael Flanakin
weblogs.getindigo.net/flanakin
 

David,

There is no reason to use eval at all for setting form element values. Consider using one of the many DOM methods to do this instead. eval is clunky, and only really has a handful of uses - this not being one of them.

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Good point. I'd recommend using document.getElementById() or document.getElementByName(). For instance...

<script>
function clearTxtRadioBtn(txtBoxRbtn) {
document.getElementByName(txtBoxRbtn).value = '';
}
</script>
...
<textarea name="txt_box">...</textarea>

________________________________________
Michael Flanakin
weblogs.getindigo.net/flanakin
 

Except getElementByName isn't a method - you probably mean either"getElementsByName" or "getElementsByTagName".

I would advise using either getElementById, or:

Code:
doucment.forms['formName'].elements['elementName'].value = newValue;

Dan



[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top