tags:

views:

31

answers:

5
<script type="text/javascript">
function up(d,mul)
{
alert(d);
form1.d.value=mul;
}

</script>

up is a function name with which i am trying to update the value of field(field name=d). But its not working. plz somebody help me.

A: 

Maybe you are looking for something like this?

http://www.tizag.com/javascriptT/javascript-innerHTML.php

Caimen
A: 

Hi Mohit, can you post your HTML code and the code piece that invoke this function. This way you can provides us more detailed information.

Rubens Mariuzzo
+1  A: 

Well you pass d as parameter. So you either have to do (renaming it do fieldname):

function up(fieldname,mul)
{
    document.form1[fieldname].value=mul;
}

and calling it with up('d', 'newValue'),

or let d be:

function up(mul)
{
    document.form1.d.value=mul;
} 

Not sure if you need document but I think you do.

See an example here: http://jsfiddle.net/8uyv8/

Felix Kling
A: 
function up(d,mul) { alert(d); form1[d].value=mul; }

You can't use d literally here as it assumes you are looking for an element named "d". So you have to use d in a context where it will use it's value, in this case, an array index.

methodin
+1  A: 

You can handle it like so:

The HTML:

​<form method='post' action='doesnt_matter'>
<input type='text' name='field1' />
<input type='text' name='field2' />
</form>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

The JavaScript:

form = document.forms[0];
function up(d,mul)
{
    alert(d);
    form[d].value=mul;
}



up('field1','Hello field 1');
up('field2','Hello field 2');
​

Working jsfiddle

Kristoffer S Hansen