| | |
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 ajaxexample ajaxjspservlets array browser captcha captchaformproblem cart checkbox child class close codes date debugger decimal dependent disablefirebug dom editor element embed engine enter events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math matrixcaptcha media menu mp4 object onerror onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post programming prototype rated redirect runtime safari scale scriptlets scroll search security session shopping size software star starrating stars synchronous toggle unicode variables web webservice wysiwyg \n






