pragan1945
Technical User
Hi Friends,
I am trying to get the following javascript function working.
I have a button(type= image)and when I click this it adds an item(addItem function) to the list which is on the page.(kind of adding an item to the cart).I am trying to show a confirmation box to ask the user "want to add" yes/no...and if YES then add it using the existing addItem funciton otherwise dont do anything.
Also if once the item is added and if they click the button again then it should alert them saying "Already added".
Please let me know how to achieve this functionality in javascript.
My addItem function is
function addItem(item) {
function getArgs() {
var args = new Object();
var query = location.search.substring(1);
var pairs = query.split("&");
var newstring = "";
for(var i = 0; i < pairs.length; i++){
var pos = pairs.indexOf('=');
if (pos == -1) continue;
var argname = pairs.substring(0,pos);
if(argname.toLowerCase() != "siteid" && argname.toLowerCase() != "urlpull" && argname.toLowerCase() != "exstyle" && argname.toLowerCase() != "aitems" && argname.toLowerCase() != "mitem" && argname.toLowerCase() != "ditems"){
newstring += pairs + "&";
}
}
return newstring;
}
if (getArgs()) { urlString = getArgs(); }
else { urlString = ''; }
window.location = location.pathname + '?' + urlString + 'aitems=' + item + '#itemList';
}
//Code ends here
HTML Button
<a href="javascript: addItem('$prod');">
<img src='/additem.png' border='0'></a>
Please help me out and let me know if I need to provide more info...Also I wanted to have a customized confirm box if its possible as the requirement is not to have the default js confirm/alert box.
I am trying to get the following javascript function working.
I have a button(type= image)and when I click this it adds an item(addItem function) to the list which is on the page.(kind of adding an item to the cart).I am trying to show a confirmation box to ask the user "want to add" yes/no...and if YES then add it using the existing addItem funciton otherwise dont do anything.
Also if once the item is added and if they click the button again then it should alert them saying "Already added".
Please let me know how to achieve this functionality in javascript.
My addItem function is
function addItem(item) {
function getArgs() {
var args = new Object();
var query = location.search.substring(1);
var pairs = query.split("&");
var newstring = "";
for(var i = 0; i < pairs.length; i++){
var pos = pairs.indexOf('=');
if (pos == -1) continue;
var argname = pairs.substring(0,pos);
if(argname.toLowerCase() != "siteid" && argname.toLowerCase() != "urlpull" && argname.toLowerCase() != "exstyle" && argname.toLowerCase() != "aitems" && argname.toLowerCase() != "mitem" && argname.toLowerCase() != "ditems"){
newstring += pairs + "&";
}
}
return newstring;
}
if (getArgs()) { urlString = getArgs(); }
else { urlString = ''; }
window.location = location.pathname + '?' + urlString + 'aitems=' + item + '#itemList';
}
//Code ends here
HTML Button
<a href="javascript: addItem('$prod');">
<img src='/additem.png' border='0'></a>
Please help me out and let me know if I need to provide more info...Also I wanted to have a customized confirm box if its possible as the requirement is not to have the default js confirm/alert box.