•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 332,567 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,151 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 329 | Replies: 4
![]() |
•
•
Join Date: Jun 2005
Posts: 82
Reputation:
Rep Power: 3
Solved Threads: 0
I have a form text field called "field_0", and javascript code:
if I run this, it pops up correct message box with the "field_0" value.
However if I change a little in javascript code:
this script will no longer work, how can I use variable "fd" in "document.form...."? any idea?
Thanks.
<script language="javascript">
function test() {
var a=document.form1.field_0.value;
alert (a);
}
</script>
<form name=form1 ....>
<input type=text name=field_0>
<input type=text name=field_1>
<....onclick='javascript: test();'>
</form>
if I run this, it pops up correct message box with the "field_0" value.
However if I change a little in javascript code:
<script language="javascript">
function test() {
var fd="field_0";
var a=document.form1.fd.value;
alert (a);
}
</script>
this script will no longer work, how can I use variable "fd" in "document.form...."? any idea?
Thanks.
•
•
Join Date: Jan 2008
Location: Bangalore, India
Posts: 327
Reputation:
Rep Power: 0
Solved Threads: 31
•
•
•
•
var fd="field_0";
•
•
•
•
var a=document.form1.field_0.value;
so you cant do what you want to do ?
any way why actually you want this to be done ?
you can try alternatives like getElementById();
hope this helps !!!
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
~Mitch Ratcliffe
> I have a form text field called "field_0", and javascript code:
First of all, your markup is broken. The HTML tag attributes need to be in the form of key-value pairs with the value being enclosed in double quotes.
> However if I change a little in javascript code this script will no longer work
This is because your JS code now looks for an element with the name 'fd' instead of 'field_0'. Try something like
But the way you are accessing forms is fundamentally broken, read this excellent article on form access.
First of all, your markup is broken. The HTML tag attributes need to be in the form of key-value pairs with the value being enclosed in double quotes.
> However if I change a little in javascript code this script will no longer work
This is because your JS code now looks for an element with the name 'fd' instead of 'field_0'. Try something like
document.form1[fd].value.But the way you are accessing forms is fundamentally broken, read this excellent article on form access.
"I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
call c# through javascript cross-browser javascript menu with few lines of code firefox html javascript javascript delete all rows from table in javascript show overflow of text by "..." javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator prevent javascript menu from getting hidden under flash movies preventing the delay when src attribute of the images set via javascript you tried to assign the null value to a variable that is not a variant data type
- Checkbox has no properties in FireFox. Works fine in IE (JavaScript / DHTML / AJAX)
- Javascript image slider issue (JavaScript / DHTML / AJAX)
- Opinions? javascript/php/etc and programming standards (JavaScript / DHTML / AJAX)
- Need FireFox refrence in javascript (JavaScript / DHTML / AJAX)
- FireFox config setting through Java Script (Community Introductions)
- input id and name issue (HTML and CSS)
- Form not sending email (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Help with Ajax toolkit drop downs
- Next Thread: Using ASCII codes??



Linear Mode