User Name Password Register
DaniWeb IT Discussion Community
All
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 373,458 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 3,942 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

javascript variable issue

Join Date: Jun 2005
Posts: 85
Reputation: michael123 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

Question javascript variable issue

  #1  
Mar 6th, 2008
I have a form text field called "field_0", and javascript code:
<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.
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 5:06 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC