Page 1 of 1

Trying to get a name in a function - Javascript

Posted: Mon Aug 23, 2004 11:56 am
by Pineriver
Hello, I am trying to get the element image_url name to the new_text() function
I dont know how I would do this I am a beginner at javascript.

<script language="JavaScript">
function new_text(field_value){
document.form.+field_value+.value="New Text";
}
</script>

<input name="image_url5" type="text" onclick="new_text(this.value)">


The problem is that I have 30 textfields like this with all different names, so that is
why I am trying to use a function. Thanks

Posted: Mon Aug 23, 2004 12:05 pm
by anjanesh

Code: Select all

<script language="JavaScript">
function new_text(srcObj)&#123;
srcObj.value="New Text";
&#125;
</script>

<input name="image_url5" type="text" onclick="new_text(this)">

Posted: Mon Aug 23, 2004 12:05 pm
by feyd
try...

Code: Select all

eval('document.' + field_name + '.value = ''' + new_value + '''');
or
eval('document.forms&#1111;''form_name''].elements&#1111;''' + field_name + '''].value = ''' + new_value + '''');

-------------

onclick="new_text(this.name)"

Posted: Mon Aug 23, 2004 12:36 pm
by Pineriver
Thanks, anjanesh code worked like a charm!