Advertisement

05.16.2008 at 08:34AM PDT, ID: 23408654
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Javascript Help : Confirm and Alert box for the same button

Tags: Javascript
Hello ,

I am trying to get the following process working through Javascript

I have a button(type= image)and when I click this it adds an item(using addItem function) to the list which is on the page..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(same) again then it should alert them saying "Already added" if its added or do the first step(Ask them if they "want to add" YES/NO).

Please let me know how to achieve this functionality in javascript.Also I wanted to have a customized confirm box/alert box or suggest if there is any other way to achieve this and I shall try it out.

Existing addItem function is
<Check code snippet>

HTML Button
<a href="javascript: addItem('$prod');">
<img src='/additem.png' border='0'></a>

Waiting for the ideas and let me know if I need to provide more info...Thanks.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
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[i].indexOf('=');
if (pos == -1) continue;
var argname = pairs[i].substring(0,pos);
if(argname.toLowerCase() != "siteid" && argname.toLowerCase() != "urlpull" && argname.toLowerCase() != "exstyle" && argname.toLowerCase() != "aitems" && argname.toLowerCase() != "mitem" && argname.toLowerCase() != "ditems"){
newstring += pairs[i] + "&";
}
}
return newstring;
}
 
if (getArgs()) { urlString = getArgs(); }
else { urlString = ''; }
 
window.location = location.pathname + '?' + urlString + 'aitems=' + item + '#itemList';
}
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: Igiwwa
Solution Provided By: Zvonko
Participating Experts: 1
Solution Grade: B
Views: 16
Translate:
Loading Advertisement...
05.16.2008 at 11:37AM PDT, ID: 21585294

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.17.2008 at 12:36AM PDT, ID: 21588292

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.19.2008 at 08:39AM PDT, ID: 21598739

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.19.2008 at 08:46AM PDT, ID: 21598788

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.19.2008 at 09:07AM PDT, ID: 21598989

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.19.2008 at 02:18PM PDT, ID: 21601703

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.19.2008 at 02:21PM PDT, ID: 21601731

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.19.2008 at 04:20PM PDT, ID: 21602391

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.19.2008 at 10:28PM PDT, ID: 21603671

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.20.2008 at 06:09AM PDT, ID: 21605733

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.20.2008 at 06:20AM PDT, ID: 21605837

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.20.2008 at 06:27AM PDT, ID: 21605894

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.20.2008 at 06:59AM PDT, ID: 21606181

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.16.2008 at 11:37AM PDT, ID: 21585294
Let me know if the question is not clear.
 
05.17.2008 at 12:36AM PDT, ID: 21588292

Rank: Genius

The question is three questions: How to change the confirm() dialog? How to call the confirm() method? How to store the added items?
And if you look closer then it is not a question at all but a solution development.
For example, how would you know from JavaScript side that an item is added after the window is loaded with new location?  Storing the added item name in an Array or Object is not a problem at all, but that var is gone after window reload.

 
05.19.2008 at 08:39AM PDT, ID: 21598739
Thanks for the reply. I understand what you are saying but can you suggest / guide me if there is any alternative solution to achieve this or closer to this.

Thanks.
 
05.19.2008 at 08:46AM PDT, ID: 21598788

Rank: Genius

Starting point is to change the <a> tag to this:
<a href="#" onClick=addItem('$prod');return false">
<img src='/additem.png' border='0'></a>

And add the confirm() call like this:
function addItem(item) {
  if(!confirm("want to add")){
     return false;
  }
  function getArgs() {
 
05.19.2008 at 09:07AM PDT, ID: 21598989
Thanks a lot again.This works if they want to add/cancel the choice..just wondering if there is any other way to give some message when they click it second time(I understood what you had mentioned earlier that we cannot store it anyways.)but just wanted to know if someway we can mention/alert/display that or avoid the confirm box for the second time when they click after adding it? and I shall take them to the list so that they can see it there.. Also is customizing a confirm box possible??Advise me.

if nothing is possble or if there is no alternative for what I need then I shall accept this as solution.
 
05.19.2008 at 02:18PM PDT, ID: 21601703

Rank: Genius

Like this:

var arrProd = {};
function addItem(item) {
  if(arrProd[item]){
    alert("Already added");
    return false;
  }
  if(!confirm("want to add")){
     return false;
  }
  arrProd[item] = true;
  function getArgs() {
Accepted Solution
 
05.19.2008 at 02:21PM PDT, ID: 21601731

Rank: Genius

And if your items are numeric then you need a prefix.
Like this:

var arrProd = {};
function addItem(item) {
  if(arrProd['_'+item]){
    alert("Already added");
    return false;
  }
  if(!confirm("want to add")){
     return false;
  }
  arrProd['_'+item] = true;
  function getArgs() {
 
05.19.2008 at 04:20PM PDT, ID: 21602391
Hi,

Thanks this idea works better but there is small problem as below
It confirms one more time after adding it and then shows the alert message..
Its as below
Want to add - Ok
it adds it
If you click again it again asks "Want to add" but it doesnt to anything even if you say OK.
If you click it for  third time ..it shows the Alert message...and its fine for further clicks.
I tried by checking the condition if its  true but stil it dint solve the problem?Any idea..
thanks a lot for the help provided.
 
05.19.2008 at 10:28PM PDT, ID: 21603671

Rank: Genius

After you click add - OK does this statement execute:
window.location = location.pathname + '?' + urlString + 'aitems=' + item + '#itemList';

After that statement is no script execution predictable.
Especialy when it realy added the item the for sure is the arrProd var not more available as before. The scripts and vars live ONLY for duration of one page load. After reload by window.location change as above are the new page script and their vars valid.

 
05.20.2008 at 06:09AM PDT, ID: 21605733
Yeah window.location happens and item is added when I click OK in the confirm box for the first time..then after page load if you click the button it asks the question "want to add" but if you click OK it doesnt do anything it  just stays in the same page and from there on if you click the button it says "Already Added" which is fine...so only thing is to avoid the confirm box again after window.location..any suggestions?
Please let me know if I need to be more clear.
 
05.20.2008 at 06:20AM PDT, ID: 21605837

Rank: Genius

Please understand: that CANNOT work.
So you need not to explain me what happens because that scenario will never go to work korrect. So it it is independant how it now behaviors.

 
05.20.2008 at 06:27AM PDT, ID: 21605894
Thanks..I understood that..I thought you asked me to explain it again..
Thanks for all the help.Really useful tips.I shall accept this solution.
 
05.20.2008 at 06:59AM PDT, ID: 21606181

Rank: Genius

OK. So for handling added items you need some sort of web server side scripting processing.
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628