Trying to get a name in a function - Javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Pineriver
Forum Commoner
Posts: 50
Joined: Fri Aug 15, 2003 5:24 pm

Trying to get a name in a function - Javascript

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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)">
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)"
Pineriver
Forum Commoner
Posts: 50
Joined: Fri Aug 15, 2003 5:24 pm

Post by Pineriver »

Thanks, anjanesh code worked like a charm!
Post Reply