| | |
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.
The romantic image of an über-programmer is someone who fires up Emacs, types like a machine gun, and delivers a flawless final product from scratch. A more accurate image would be someone who stares quietly into space for a few minutes and then says “Hmm. I think I’ve seen something like this before.” - John D
![]() |
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??
Views: 843 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxhelp animate api automatically beta boarder box bug button calendar card checkbox child class column cookies createrange() css cursor disablefirebug dom download dropdown editor element engine error events explorer ext file firehose flash form forms google gwt html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump margin math matrixcaptcha microsoft mimic mp3 mysql object offline onmouseoutdivproblem onreadystatechange parent passing pdf php player post problem progressbar rated rating regex runtime scroll search select session shopping size sql star stars stretch text textarea twitter validation w3c web website window windowofwords windowsxp wysiwyg xml xspf \n






