Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wierd Javascript Error When passing a value

Status
Not open for further replies.

Mase571

Programmer
Mar 27, 2008
6
TH
Hi I am passing a value from the selected item in a dropdown list to a hidden field (00N200000013PAx).

This is the code:
Code:
function onChange(){
	
  var Current = document.destin.procedure.selectedIndex;
  document.form.00N200000013PAx.value = document.form.procedure.options[Current].value;
 }

When I take out the first two zeros in (00N20000013PAX[hidden field]) it works but it has to be with two zeros because of a third party integration.
Any ideas?
Thanks in advance.
 
try

document.forms["form"].elements["00N200000013PAx"].value = ...
 
Thanks bro that worked like a charm
appreciate it.
 
The name attributes of any html nodes should only, risk of oversimplified, start with alphabets(a-zA-Z) or underscore (_) and should not contain whitespace in it. One should script the name attribute in compliance with this spec in the first place. If one, driven by whatever motive or by ignorance, has scripted a name not compliant to it, one can still, in case of document form elements, succeed in referencing to it via elements[name] hash table. The above is the case. (The same approach is applicable to form element use forms[name].) Hope that make the thing appeared less of a hacking or of a trick, one way or another, namely the shorter format because I know some make a big issue of it.
 
Hi again im sorry im new to javascript i have another question:

Now this worked for one hidden value what if i have 8 hidden values?

I need a function like:
if option1 selected
pass the value to checkbox1
if option2 selected
pass the value to checkbox2

i tried something like this but didnt work

Code:
function onChange() {	

  var Current = document.form.procedure.selectedIndex;

  if (document.getElementById="00N200000013PAd")
  {
	  document.forms["form"].elements["00N200000013PAd"].value = document.form.procedure.options[Current].value;
  }
  else  if (document.getElementById="00N200000013PAx")
  {
	  document.forms["form"].elements["00N200000013PAx"].value = document.forum.procedure.options[Current].value;
  }
.
.
.


Thanks for any help
 
I agree with tsuji, it is really not good idea to have non standard names or ids.

Fo your problem try use switch:
(not tested)

Code:
function onChange() {    
  var Current = document.form.procedure.selectedIndex;
  switch (Current)
  {
   case 0:
    document.forms["form"].elements["00N200000013PAd"].value=Current;
     break;

   case 1:
    document.forms["form"].elements["00N200000013PAx"].value=Current;
     break;

   default:
     alert("Action failed");
  }
}
 
thanks again but here its passing the case number not the value of the option and when u change the option selected im getting the action failed
 
This will assign to hidden fields current value of selected value in select. Numbers 0-7 are indexes of your select(I suppose you have 8 hiddens and 8 items in select). It also depends on your html

Code:
function onChange() {    
  var Current = document.forms["form"].elements["procedure"].selectedIndex;
  var CurrentValue= document.forms["form"].elements["procedure"].options[Current].value;
  switch (Current)
  {
   case 0:
    document.forms["form"].elements["00N200000013PAd"].value=CurrentValue;
     break;
   case 1:
    document.forms["form"].elements["00N200000013PAx"].value=CurrentValue;
     break;
   case 2:
    document.forms["form"].elements["00N200000013PAa"].value=CurrentValue;
     break;
   case 3:
    document.forms["form"].elements["00N200000013PAb"].value=CurrentValue;
     break;
   case 4:
    document.forms["form"].elements["00N200000013PAc"].value=CurrentValue;
     break;
   case 5:
    document.forms["form"].elements["00N200000013PAd"].value=CurrentValue;
     break;
   case 6:
    document.forms["form"].elements["00N200000013PAe"].value=CurrentValue;
     break;
   case 7:
    document.forms["form"].elements["00N200000013Pf"].value=CurrentValue;
     break;

   default:
     alert("Action failed");
  }
}
 
Hi I am sorry but i faced another problem lets say i selected option 1 and then changed my mind and selected option 2 the output is coming as if i selected both options.

i need only one output shouldnt the break do this job?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top