Reputation: 43
I have following form where i want to assign value of "R.EmailAddress" field to a Hidden field "email_From".
I tried to use the function doCalculate in Javascript but its not assigning R.EmailAddress to email_From, is it because of input type="image" ??
<form name="eMail" method="post" action="/emailform.asp" >
<input type="text" name="R.EmailAddress" class="textfield_contact" value="">
<input type="hidden" name="email_From" value="[email protected]">
<input type="image" src="submit.gif" border="0" name="submit" value="Submit" `onClick="doCalculate(this.form)">`
My Javascript function looks like below
<script language="javascript" type="text/javascript">
function doCalculate(theForm){
var aVal = theForm.R.EmailAddress.value;
theForm.email_From.value=aVal;
alert(aVal);
}
</script>
Upvotes: 1
Views: 3405
Reputation: 237847
theForm.R.EmailAddress.value
This looks at the object theForm
, finds a property R
from that object, then finds a property EmailAddress
from that object, then gets the value
from that object. This clearly isn't what you mean: you're looking for the R.EmailAddress
property of the theForm
object.
Since .
can't be used in property names with the dot member notation, you'll have to use square bracket notation instead:
theForm['R.EmailAddress'].value;
See the MDN page on member operators for more information on these syntaxesx.
Upvotes: 0
Reputation: 24534
Since "R" is not a property of the object, you have to use ["R.EmailAddress"]
function doCalculate(theForm){
var aVal = theForm["R.EmailAddress"].value;
theForm.email_From.value=aVal;
alert(aVal);
}
Upvotes: 3