Aux Boss du JS

Aux Boss du JS - HTML/CSS - Programmation

Marsh Posté le 24-12-2002 à 09:10:56    

Voila j'ai un script pour un caddie en javascript, mais je ne comprend pas comment il fonctionne pour la création et la lecture du cookie créé. Une ame charitable :cry: pourrait-elle me faire un petit descriptif de ce code.
 
Merci pour votre aide.
 
Voici ce qui est envoyé par la page produit:

Code :
  1. <FORM NAME=PROD1 onSubmit="addto(document.PROD1,'caddie.html')">
  2. <INPUT TYPE="TEXT" NAME="quantity" SIZE=3 MAXLENGHT=3 VALUE="1">
  3. <INPUT TYPE="hidden" NAME="100.5" VALUE="ici la description">
  4. <INPUT TYPE="hidden" NAME="PROD1" VALUE="ici_la_page_actuelle.html">
  5. <input type="image" src="../media/bouton_ajout_caddie.gif">
  6. </form>


 
ici le javascript de traitement:
 

Code :
  1. function Inscrit(){
  2. alert('Article ajout\u00e9 à votre panier.')
  3. }
  4. function addto (form) { //add to cart but stay on the same page
  5.   var entry=form;
  6.   var a=0;
  7.   boundry = new Array(entry.elements.length);
  8.   boundry[0]=0;
  9.    for(x=1;x<entry.elements.length;x++){
  10. if(entry.elements[0].name==entry.elements[x].name)
  11.          {
  12.            a++;
  13.            boundry[a]=x;
  14.          }
  15.    } 
  16. j=0;
  17. for(i=0;i<=a;i++) {
  18.   j=boundry[i];
  19. // check to see if you are using <select>
  20. if(isNaN(entry.elements[j+1].length)){
  21.      var description=entry.elements[j+1].value;
  22.   } else {
  23.      var opindex=entry.elements[j+1].selectedIndex;
  24.      var description=entry.elements[j+1].options[opindex].text;
  25.   }
  26.   var ind=j+2;
  27.   while(entry.elements[ind].name==entry.elements[ind-1].name)
  28.   {
  29.      opindex=entry.elements[ind].selectedIndex;
  30.      description = description+" "+entry.elements[ind].options[opindex].text;
  31.      ind++;
  32.   }
  33.   store_name=entry.elements[ind].value;
  34.   product_name=entry.elements[ind].name;
  35.   quantity=entry.elements[j].value;
  36.   price=entry.elements[j+1].name;
  37.   var num=parseInt(entry.elements[j].value)
  38.   if(!isNaN(num) && num>=0 )
  39.   {
  40.   document.cookie ="crea"+store_name+"+"+description
  41. + "+" + product_name + "=" + quantity +
  42. "+" + document.referrer  +"+"+ price +
  43. "; path=/"+"";
  44.    }     
  45. }
  46. Inscrit()
  47. }
  48. function  addtocart(form,page){ //add to cart and go to a new page
  49. addto(form)
  50. location.href=page;
  51. }
  52. function setform(form,page){
  53. var formname=form;
  54. formname.method='GET';
  55. formname.action=page;
  56. }


Message édité par DJERO le 24-12-2002 à 09:25:41
Reply

Marsh Posté le 24-12-2002 à 09:10:56   

Reply

Marsh Posté le 14-01-2003 à 16:47:03    

up please

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed