satrah
05-25-2006, 09:33 AM
Hi Guys,
Once again im stuck, thanks first of all to KOR, you have been a huge help however as a n00b im going to need some help working this script out, basically i need this script converted to a more simplified version using functions, there are two pieces of code which i have so far of which i will quickly explain now...
This is my original piece of code, it works so far but there are more features to be added to it wihich i will explain with the next pice of code:
<script>
var prod = prompt("Enter The Product","")
var quan = prompt("Enter The Quantity","")
while(Number(quan)<0){
quan = prompt("No Negative Numbers, Please Enter Quantity","")
}//end of < 0 QUAN
var pric = prompt("Enter The Price","")
while(Number(pric)< 0){
pric = prompt ("No Negative Numbers, Please Enter Price","")
}// End Of < 0 PRIC
function item(prod, quan, pric){
this.product (prod);
this.quantity (quan);
this.price (pric);
}//End Of Value
} //end of item
document.write(prod+"<br>")
document.write(quan+"<br>")
document.write("$"+pric+"<br>")
</script>
Now KOR has given me this following piece of code that has the exatr components added however as a noob i dont understand it and i need it converted to a simplified form like with functions and stuff if you get me...
also the functions in this will be used with buttons eventually if that helps at all with the coding part?
<script>
var arr=['Product Added :','Quantity : ','Price : ','Total Value : ']
function addItem(){
var prod = prompt('Please Enter Product','');
var quan = prompt('Please Enter Quantity','');
while(Number(quan)<0){
quan = prompt('No negative numbers allowed. Please Enter Quantity','');
}
var pric = prompt('Please Enter Price','');
while(Number(pric)<0){
pric = prompt('No negative numbers allowed. Please Enter Price','');
}
var valueInStock=quan*pric;
var myItem={'prod':prod,'quan':quan,'pric':pric,'valueInStock':valueInStock}//this is the new object
var root=document.getElementById('mydiv');
var i=0;
for(arg in myItem){
var s=document.createElement('span');
s.style.fontWeight='bold';
s.appendChild(document.createTextNode(arr[i]))
root.appendChild(s);
root.appendChild(document.createTextNode(myItem[arg]))
root.appendChild(document.createElement('br'))
i++;i==arr.length?root.appendChild(document.createElement('br')):null;
}
confirm('Do you want to add another item?')?addItem():null;
}
onload = addItem;
</script>
<script>
document.write("<strong>Product Added :</strong> " + myItem.prod + "<br />");
document.write("<strong>Quantity :</strong> " + myItem.quan + "<br />");
document.write("<strong>Price :</strong> $" + myItem.pric + "<p>");
document.write("<strong>Total Value :</strong> $" + myItem.valueInStock + "");
</script>
Hopefully you an get teh general drift of what im trying to do here and help me out, this is so important to me and i just really need some help soon.
Cheers to anyone that can help, especially you KOR, you're probably getting very sick of me.lol
cheers,
--==::SATRAH::==--
Once again im stuck, thanks first of all to KOR, you have been a huge help however as a n00b im going to need some help working this script out, basically i need this script converted to a more simplified version using functions, there are two pieces of code which i have so far of which i will quickly explain now...
This is my original piece of code, it works so far but there are more features to be added to it wihich i will explain with the next pice of code:
<script>
var prod = prompt("Enter The Product","")
var quan = prompt("Enter The Quantity","")
while(Number(quan)<0){
quan = prompt("No Negative Numbers, Please Enter Quantity","")
}//end of < 0 QUAN
var pric = prompt("Enter The Price","")
while(Number(pric)< 0){
pric = prompt ("No Negative Numbers, Please Enter Price","")
}// End Of < 0 PRIC
function item(prod, quan, pric){
this.product (prod);
this.quantity (quan);
this.price (pric);
}//End Of Value
} //end of item
document.write(prod+"<br>")
document.write(quan+"<br>")
document.write("$"+pric+"<br>")
</script>
Now KOR has given me this following piece of code that has the exatr components added however as a noob i dont understand it and i need it converted to a simplified form like with functions and stuff if you get me...
also the functions in this will be used with buttons eventually if that helps at all with the coding part?
<script>
var arr=['Product Added :','Quantity : ','Price : ','Total Value : ']
function addItem(){
var prod = prompt('Please Enter Product','');
var quan = prompt('Please Enter Quantity','');
while(Number(quan)<0){
quan = prompt('No negative numbers allowed. Please Enter Quantity','');
}
var pric = prompt('Please Enter Price','');
while(Number(pric)<0){
pric = prompt('No negative numbers allowed. Please Enter Price','');
}
var valueInStock=quan*pric;
var myItem={'prod':prod,'quan':quan,'pric':pric,'valueInStock':valueInStock}//this is the new object
var root=document.getElementById('mydiv');
var i=0;
for(arg in myItem){
var s=document.createElement('span');
s.style.fontWeight='bold';
s.appendChild(document.createTextNode(arr[i]))
root.appendChild(s);
root.appendChild(document.createTextNode(myItem[arg]))
root.appendChild(document.createElement('br'))
i++;i==arr.length?root.appendChild(document.createElement('br')):null;
}
confirm('Do you want to add another item?')?addItem():null;
}
onload = addItem;
</script>
<script>
document.write("<strong>Product Added :</strong> " + myItem.prod + "<br />");
document.write("<strong>Quantity :</strong> " + myItem.quan + "<br />");
document.write("<strong>Price :</strong> $" + myItem.pric + "<p>");
document.write("<strong>Total Value :</strong> $" + myItem.valueInStock + "");
</script>
Hopefully you an get teh general drift of what im trying to do here and help me out, this is so important to me and i just really need some help soon.
Cheers to anyone that can help, especially you KOR, you're probably getting very sick of me.lol
cheers,
--==::SATRAH::==--