Strange Javascript error.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
SpiderMonkey
Forum Commoner
Posts: 85
Joined: Fri May 05, 2006 4:48 am

Strange Javascript error.

Post 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.
User avatar
J_Iceman05
Forum Commoner
Posts: 72
Joined: Wed Aug 03, 2005 10:52 am
Location: Las Vegas, NV

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
SpiderMonkey
Forum Commoner
Posts: 85
Joined: Fri May 05, 2006 4:48 am

Post 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.
Post Reply