Current location: Hot Scripts Forums » General Web Coding » JavaScript » Problem with an onclick and Window Location


Problem with an onclick and Window Location

Reply
  #1 (permalink)  
Old 08-26-10, 01:07 PM
tankeriv tankeriv is offline
New Member
 
Join Date: Aug 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Post Problem with an onclick and Window Location

Hi there,

I am very new here so I hope I am abiding the rules by asking this.

I have been banned for asking this on a Dutch forum. Because it was too basic.
But I am very sorry.
I simply do not see what I am doing wrong here.


onclick="!if(confirm('Do you really want to delete the selected customers?')){ window.location='action=customers'; };"


So I am hoping on my knees that someone out here can tell me what my error is.

What this script is supposed to. Is when you click the corresponding button give an alert and ask you. "Do you really want to delete the selected customers".
And if you press "No" It should refer to the page ?action=customers

Why do I do this?
Because if I just keep it simple:

and add:

onclick='confirm('Do you really want to delete the selected customers?')' It still refreshes the page and goes to the corresponding.

It is a Submit type button.
But I want to stop it from functioning when No is pressed.

I really hope that any of you could help me.

Many thanks in advance
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-27-10, 05:36 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Hi,

The location of your ! is wrong and you probably want to add return false to the end of the statement because it will always postback now, losing you location directive. So also you will probably need to define what to do when OK was clicked in an else statement.

Code:
<button type="submit" name="submit" value="sumbit" onclick="if(!confirm('Do you really want to delete the selected customers?')){ window.location='Default.aspx?action=customers' }; return false;"></button>
BTW. Weird you got banned for asking this.

/Yeroon
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to Yeroon For This Useful Post:
tankeriv (08-27-10)
  #3 (permalink)  
Old 08-27-10, 07:09 AM
tankeriv tankeriv is offline
New Member
 
Join Date: Aug 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Hey Jeroen!
Dank je!

Thanks Yeroon!

With your help I knew to find the solution to my problem.
Now I saw your syntax I knew what I was doing wrong.

HTML Code:
<button type="submit" name="Submit" class="button3" value="sumbit" onclick="if(!confirm('Do you really want to delete the selected customers?')){ window.location='?action=klanten'; return false; }  else{ return true; }"><span>Delete selected customers</span></button>

Yeah, I got banned because I was asking a question that was too easy. I was called lazy because I should have gotten deeper into the subject. I am simply not that good at this. And I now see my error. (I mean in the coding) But I simply did not see it before.

But it was too simple and they closed my first thread I should look better into coding. But after many looking I still didn't see an answer. Also many Googling. I simply didn't see it. (Got dyslexia that helps a lot ) I asked again. And got instantly banned.

But thanks a lot! I am really helped with this!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-27-10, 09:19 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Hi,

Glad you got it sorted! Well you are more than welcome here! If you make an effort yourself and have some code for us to work with we will always help you if we can.

/Yeroon
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks

Tags
javascript


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
onclick question levd JavaScript 4 03-01-10 08:21 AM
Closing a window onclick ! n3wb!e JavaScript 2 07-10-06 07:54 AM
close window on submit lynchm0bx JavaScript 3 02-21-06 04:09 PM
Newbie problem with OnClick newwindow and ASP ianric JavaScript 1 11-30-05 06:32 AM
image and onclick harland JavaScript 1 08-31-05 12:23 PM


All times are GMT -5. The time now is 12:29 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.