homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
variables in javascript not recognised?
What am i doing wrong
immols




msg:3850625
 2:17 pm on Feb 16, 2009 (gmt 0)

How does javascript deal with variables? In this statement 'document.formname.fieldname.value' i cannot use variables?

This does not work
function ajaxFunction(_formname,_fieldname){
//simple code here to set var xmlHttp;
xmlHttp.onreadystatechange=function() {
if(xmlHttp.readyState==4) {
document._formname._fieldname.value=xmlHttp.responseText;
}
}
//open and send statements here
}

This does work
function ajaxFunction(_formname,_fieldname){
//simple code here to set var xmlHttp;
xmlHttp.onreadystatechange=function() {
if(xmlHttp.readyState==4) {
document.contact_name.name.value=xmlHttp.responseText;
}
}
//open and send statements here
}

Checking of values
When i alert(_formname+' '+_fieldname); i do get 'contact_name name' in a popup.

 

Fotiman




msg:3850692
 3:54 pm on Feb 16, 2009 (gmt 0)

Try this method:

document[_formname][_fieldname].value = xmlHttp.responseText;

immols




msg:3850746
 5:05 pm on Feb 16, 2009 (gmt 0)

HAH! Brilliant.Thanks a lot! Works like a charm.
Do you know why i works the way you wrote it and not without the brackets?

quartzy




msg:3859063
 10:27 am on Feb 27, 2009 (gmt 0)

thats how you write arrays, in square brackets

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved