...

View Full Version : Change this code to allow letters



brat42
07-27-2011, 08:09 PM
Hi all,

I'm trying to change our shopping cart code by making a small modification.

When editing a product, there is a dimensions box which currently only allows numbers. We want it to allow numbers and letters (don't ask why).

The code we have is the following which we think is related to why our shopping cart won't allow letters in the box.

Could someone please edit the following code to allow letters? Thank you.


if(isNaN(dimensionsFormat(prodWidth.value)) && prodWidth.value != "" && !sellingDP) {
ShowTab(0);
alert("%%LNG_EnterWidth%%");
prodWidth.focus();
prodWidth.select();
return false;
}

if(isNaN(dimensionsFormat(prodHeight.value)) && prodHeight.value != "" && !sellingDP) {
ShowTab(0);
alert("%%LNG_EnterHeight%%");
prodHeight.focus();
prodHeight.select();
return false;
}

if(isNaN(dimensionsFormat(prodDepth.value)) && prodDepth.value != "" && !sellingDP) {
ShowTab(0);
alert("%%LNG_EnterDepth%%");
prodDepth.focus();
prodDepth.select();
return false;
}

Old Pedant
07-27-2011, 08:36 PM
Yep, you got it.

isNaN( ) means "if my argument is Not A Number return true".

So you'd need to kill off the isNaN( ) calls.

But you probably also need to modify your dimensionsFormat( ) function, and you don't show us the code for that.

If you need to allow values such as "13 cm" or "27.2 in" or "3 feet" then you probably want to rewrite (or create an alternate version of) dimensionsFormat() that will accept a number followed by a unit of some kind. We could even limit what units are acceptable if you could supply a complete list.

In short, we need more info from you before we can help you.

brat42
07-27-2011, 10:28 PM
Thanks for your reply. I don't need to add the unit. All I simply want to do is to be able to add letters instead of just numbers.

Is there something I can change in the code I have given you?

Also, there is a popup (standard popup in browsers) which opens saying you need to enter a number, I just want to disable it which will let me put letters in.

Old Pedant
07-28-2011, 12:46 AM
I answered you. Without seeing what the dimensionsFormat() function does, it would be nearly impossible to be sure that any change we give you won't break something else.

As for the popup: Yes, that's almost surely what those calls to alert( ) are doing. No, let me be more definite: alert( ) *IS* the "standard popup in browsers" but the text in the alert is being supplied by some sort of macro mechanism so we can't tell for sure what it is by looking at that code you showed us.

If you are unwilling to help us help you, then there's not much more we can say.

*********

I will say one thing: It is *POSSIBLE* that if you simply remove the code you showed above things will work the way you want them to. Again, since you don't show the code for dimensionFormat( ) there's no way I can know for sure. If calling that code doesn't have any side effects, then just zapping all those lines could well work. But if that function is vital to other functioning on the page, you would be hosed. But what the heck: Try it. Worst that happens is that it doesn't work.

brat42
07-28-2011, 01:11 AM
Thanks for your reply again.

I've tried removing the code - this time it lets me 'save' it, without the popup, but when I go back into the product, the data I entered is not there. So, I restored the file and typed a number, saved it and this time, I could see the number. Do you know why it is not saving it when letters are there?

Anyhow, I can't see to find this dimensionsFormat() code. All I can find is the code I initially gave you. I've searched the whole server for dimensionsFormat() and dimensionsFormat and it is just the same file that comes back with the code I gave you.

The below bit is the html code for the dimension boxes:


<td class="FieldLabel">
&nbsp;&nbsp;&nbsp;{% lang 'ProductWidth' %}:
</td>
<td>
<input type="text" id="prodWidth" name="prodWidth" class="Field80" value="{{ ProdWidth|safe }}" style="text-align: right;" /> {{ LengthMeasurement|safe }}
<img onmouseout="HideHelp('d15');" onmouseover="ShowHelp('d15', '{% lang 'ProductWidth' %}', '{{ ProductWidthHelp|safe }}')" src="images/help.gif" width="24" height="16" border="0">
<div style="display:none" id="d15"></div>
</td>
</tr>
<tr>
<td class="FieldLabel">
&nbsp;&nbsp;&nbsp;{% lang 'ProductHeight' %}:
</td>
<td>
<input type="text" id="prodHeight" name="prodHeight" class="Field80" value="{{ ProdHeight|safe }}" style="text-align: right;" /> {{ LengthMeasurement|safe }}
<img onmouseout="HideHelp('d16');" onmouseover="ShowHelp('d16', '{% lang 'ProductHeight' %}', '{{ ProductHeightHelp|safe }}')" src="images/help.gif" width="24" height="16" border="0">
<div style="display:none" id="d16"></div>
</td>
</tr>
<tr>
<td class="FieldLabel">
&nbsp;&nbsp;&nbsp;{% lang 'ProductDepth' %}:
</td>
<td>
<input type="text" id="prodDepth" name="prodDepth" class="Field80" value="{{ ProdDepth|safe }}" style="text-align: right;" /> {{ LengthMeasurement|safe }}
<img onmouseout="HideHelp('d17');" onmouseover="ShowHelp('d17', '{% lang 'ProductDepth' %}', '{{ ProductDepthHelp|safe }}')" src="images/help.gif" width="24" height="16" border="0">
<div style="display:none" id="d17"></div>
</td>
</tr>

Just to let you know I don't use these dimensions at all, so it shouldn't have any side effects.

Thanks again for your help. Are there any ideas you have for what further code you need and what I can search for?

Old Pedant
07-28-2011, 01:41 AM
I can't even tell what underlying language or framework is being used there.

All that stuff with the % marks, for example, is apparently server-side code that then gets rewritten/substituted-for when the page is sent to the browser. But I can't tell WHAT it is rewriting/substituting because I don't know that system.

I *did* say that dimensionsFormat might have some side effects, and that's apparently what is happening: Apparently you need those side effects in order to get the values submitted into the DB.

Or maybe not! It's quite possible that the fields in the DB are *NUMERIC* fields and so can't accept non-numeric values. For example, if the data type of the corresponding field in the DB is INT or FLOAT or REAL or DOUBLE, then there's no possible way to store non-numeric values into that field. So the first step for you might well be that you need to change the DB design.

Don't take this wrong, but you are doing the software equivalent of asking a mechanic in New York to diagnose what's wrong with your car over the phone while you are sitting in the driver's seat in the middle of Colorado...and haven't even yet opened up the hood.

I'm sure what you are after *can* be done--maybe it's the equivalent of connecting a spark plug wire--but I just can't tell *how* it needs to be done (and maybe it's the equivalent of rebuilding the motor).

Getting somebody to come in and look at the problem in situ may be the most practical solution.

Philip M
07-28-2011, 07:33 AM
Getting somebody to come in and look at the problem in situ may be the most practical solution.

Presumably you would not attempt to service or repair a machine or appliance without any experience or understanding of how it worked.
As this is a commercial application the only sensible advice is - pay a professional to sort it out for you.

bullant
07-28-2011, 11:14 AM
sounds like you'll have to modify the dimensionFormat() function to handle product widths values that contain numbers or numbers and letters.



if(isNaN(dimensionsFormat(prodWidth.value)) && prodWidth.value != "" && !sellingDP) {
ShowTab(0);
alert("%%LNG_EnterWidth%%");
prodWidth.focus();
prodWidth.select();
return false;
}


With the above code, if dimensionsFormat(prodWidth.value) returns anything but a number , the IF test will evaluate to false.

So it looks like dimensionsFormat() will have to be modified to handle prodWidth.value that contains numbers as well as letters.

You haven't posted the code for dimensionsFormat().

brat42
07-28-2011, 12:56 PM
Thanks for your replies. I think I am nearly there. Additional code I have been able to find is:


if(!productCheckedDimensions){
if(!sellingDP &&
((prodWidth.value == "" || isNaN(priceFormat(prodWidth.value))) ||
(prodHeight.value == "" || isNaN(priceFormat(prodHeight.value))) ||
(prodDepth.value == "" || isNaN(priceFormat(prodDepth.value))))) {
$.iModal({
type: 'inline',
inline: '#AddProductWithEmptyDimensions',
width: 450
});
return false;
}
}

Is this the code you were after?

bullant
07-28-2011, 02:33 PM
Is this the code you were after?

need to see the code in dimensionFormat()

brat42
07-28-2011, 02:46 PM
How come though I've done a search of the whole server for dimensionFormat but also dimensionFormat() and found nothing?

bullant
07-28-2011, 02:52 PM
The function will most likely be in the web page's html or in a javascript file that the web page links to.

If you're not getting any error messages in your browser's error console saying the function is undefined then either it is never being called and so may or may not exist or it is being called and so exists somewhere.

Your text editor should have a Find function and so search for the function name in the html and any linked javascript files to find the function.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum