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

JAVASCRIPT functions

Status
Not open for further replies.

pragan1945

Technical User
May 15, 2008
1
US
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.
 
reading
code
that
is
posted
like
this

isjustaboutaseasyasreadingasentencethatiswrittenlikethis


Please do everybody a favor (including yourself) and indent your code properly before you post it.

Based on your question it seems you need to read up on the confirm() function.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

Finally, <. is a good thing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top