Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Change this code to allow letters

    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.

    Code:
    		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;
    		}

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,193
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    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.

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    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.
    Last edited by brat42; 07-27-2011 at 10:47 PM.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,193
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    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.

  • #5
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    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:

    Code:
    						<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?

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,193
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    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.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by Old Pedant View Post
    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.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #8
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    sounds like you'll have to modify the dimensionFormat() function to handle product widths values that contain numbers or numbers and letters.

    Code:
     
    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().

  • Users who have thanked bullant for this post:

    webdev1958 (08-13-2011)

  • #9
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Thanks for your replies. I think I am nearly there. Additional code I have been able to find is:

    Code:
    	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?

  • #10
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by brat42 View Post
    Is this the code you were after?
    need to see the code in dimensionFormat()

  • Users who have thanked bullant for this post:

    webdev1958 (08-13-2011)

  • #11
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    How come though I've done a search of the whole server for dimensionFormat but also dimensionFormat() and found nothing?

  • #12
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    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.

  • Users who have thanked bullant for this post:

    webdev1958 (08-13-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •