| | |
javascript variable issue
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2005
Posts: 92
Reputation:
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>Thanks.
•
•
•
•
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 !!!
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Indian Developer
http://falaque.wordpress.com/
> 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.
![]() |
Similar Threads
- 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??
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate array automatically beta box bug calendar cart checkbox child class codes column cookies createrange() css cursor date debugger decimal design dom download dropdown editor element enter error explorer file firefox focus forms frameworks getselection google gwt html htmlform ie8 iframe images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent php player post problem programming progressbar prototype redirect regex runtime safari scale scriptlets search select session shopping size sql text textarea toggle variables w3c web website window windowofwords windowsxp wysiwyg \n






