Page 1 of 1

Strange Javascript error.

Posted: Tue Jun 13, 2006 6:08 am
by SpiderMonkey
I'm trying to incorporate values entered on to a form into a string before its submitted.

Here is my code:

Code: Select all

   if (document.orderform.measure.value==2) 
      itemname=document.orderform.x_dim.value+"cm x "+document.orderform.y_dim.value+"cm ";
   else
      itemname=document.orderform.x_dim.value+"in. x "+document.orderform.y_dim.value+"in. ";
Its part of a function which gets called whenever relevant elements on the form are changed. Subsequently in the function, other strings are added to itemname, then its written to a hidden field for submission.

Something very strange has happened. Previously it behaved quite nicely by producing something like:

"24cm x 44cm"

Now it just produces:

"in. x in."

Thing is, I have not changed anything about the form, or any code executed before this. So I can't see how this can possibly have happened.

Posted: Tue Jun 13, 2006 4:23 pm
by J_Iceman05
I'm at a bit of a loss too... things like that will happen to me as well
(I don't change anything but the code stops working... then it will start working again in a few minutes/hours ... strange stuff...)

anyway... have you ever tested it with having "document.orderform.measure.value" equal something other than 2?
if the values in other fields have only led to that value equalling 2 (giving the 'cm' version), then there might be a good place to look.
check the other values in the forum as well... this may be the cause of your problem. try values that have worked in the past, if they still work, then your code still works like it did before, it just had problems you didn't discover until now.

Based on those 4 lines of code and the info you have given... this is the best advice I can give... hope it helps lead you to the answer to your problem.
Sorry I'm not much more help.

Posted: Tue Jun 13, 2006 4:59 pm
by pickle
Was the inches line ever working correctly? The code as it stands only shows cm measurements if the value is equal to 2. Should you be checking the length of the value rather than the value itself?

Posted: Wed Jun 14, 2006 3:22 am
by SpiderMonkey
pickle wrote:Was the inches line ever working correctly? The code as it stands only shows cm measurements if the value is equal to 2. Should you be checking the length of the value rather than the value itself?
'measure' is a dropdown element that gives the units. Seeing as the only choices are inches and cm, the code does it right.

This problem is now solved anyway. I didn't alter anything to do with it, but after the next upload it worked fine. Guess the computer was haunted or something.