Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 06-22-2006, 11:18 PM   #1
Member (10 bit)
 
Join Date: Aug 2003
Location: East Lansing, MI
Posts: 635
Send a message via AIM to comp615
JS variable Question

Hello I am trying to integrate a bit of js into a php page...my JS looks like:
Code:
function update_checkbox(fieldName,fieldValue,fieldType) {
  if(fieldType==1) {
  	dkpType = 'ontime';
  } else {
  	dkpType = 'endtime';
  }
  dkpField = 'document.forms["DKP"].dkp_' + fieldName + '';
  dkpCheckbox = 'document.forms["DKP"].' + dkpType + '_' + fieldName + '';
  dkpValue = dkpField.value;
  alert(dkpValue);
  if(dkpCheckbox.checked) {
	  dkpValue = (dkpValue + fieldValue);
  } else {
	  dkpValue = (dkpValue - fieldValue);
  }
  dkpField.value = value;
}
However, the problem is that somewhere around dkpValue = dkpField.value; things get wierd...if I plug in literally 'document.forms["DKP"].dkp_1.value'; it works, and dkpField outputs 'document.forms["DKP"].dkp_1' however, when I try to add .value onto it to get the value it keeps coming back undefined...any ideas.

Also, as a side note, I wanted to use arrays for php but js doesn't work that way? I wanted 'document.forms["DKP"].dkp[1]', but that seems to cause troubles in making it think its a js array or something...is this right?

Thanks for the help!
comp615 is offline   Reply With Quote
Old 06-23-2006, 08:49 AM   #2
Member (9 bit)
 
DynamicTech's Avatar
 
Join Date: Jan 2006
Posts: 343
Code:
dkpField = 'document.forms["DKP"].dkp_' + fieldName + '';
  dkpCheckbox = 'document.forms["DKP"].' + dkpType + '_' + fieldName + '';
  dkpValue = dkpField.value;
dkpField is a String value, not the value of the form field. To get the value of the form field, you will have to do something like:
Code:
var myDkpField = document.getElementById('my_form_element');
var dkpValue = myDkpField.value;
or
Code:
var dkpValue = document.forms.my_form.my_form_element.value;
DynamicTech is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:10 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2