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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluation Problem

Status
Not open for further replies.

Sarky78

Programmer
Oct 19, 2000
878
0
0
GB

Hi,

I am developing a e-commerce website where i ahve something like 4000 products which all have a product code. I am using this product code as the unique reference on the webpage to add the product to the cart.

these are the basic elements of the form:

<!--- the quantity field for a specific product--->
<input type=&quot;text &quot;name=&quot;quantiy10001&quot; value=&quot;1&quot;>

<!--- the submit button next to the product --->
<a href=&quot;javascript:submitMe('#getProducts.ProductCode#');&quot; class=&quot;link&quot;>Add Product</A>


<!--- this is the code that i am having problems with --->
function submitMe(PCode) {
var a,b,c,d
a = 'document.cart.quantity' + PCode + '.value';
b = eval(a);
}

This code above works fine when i have a product code as above (10010) but some of the product codes are of the format 10010/FF so when i come to the eval(a) line it tries to divide 10010 by FF and produces an error.

What i need is for the actualt quantity entered into the field to be returned can anyone suggest anything that i could do to either cancel out the / in the product code or another function that is not going to try and do a mathematical function on it ?

cheers !

tony
 
You can send the actual value of the field to the function with:

<a href=&quot;javascript:submitMe(document.myForm.myTextbox10010.value);&quot; class=&quot;link&quot;>Add Product</A>

If this isn't what you want, you could send the textbox object to the function with:

<a href=&quot;javascript:submitMe(document.myForm.myTextbox10010);&quot; class=&quot;link&quot;>Add Product</A>

Just a thought too, it's not a good idea to use characters other than letters, numbers, and the underscore character when naming values. You may want to consider running your values through some text converter function on the server.

Good luck.
 

thanks for the quick response as my hands are tied on the product code front then i think i am going to have to do some server side stuff to cancel out the / in the product code.

 
If you want to use the &quot;/&quot; character, you can &quot;escape&quot; it with &quot;\/&quot; to keep Javascript from thinking it's a division symbol. You could also use the pipe &quot;|&quot; (or some other non-math operation punctuation), since that doesn't perform any operations in Javascript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top