Confirm window not working properly

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Confirm window not working properly

Post by brewmiser »

I know nothing about Java and I need to understand why this is not wokring.

Here is the script:

Code: Select all

<Script Language="JavaScript"> 
  function ConfirmChoice() 
  &#123; 
    answer = confirm("Do you really want to delete this company?")
		if (answer !=0) 
    &#123; 
      location = "view_results.php" 
    &#125; 
	&#125;
</script>

<body>
etc......
This is the part that I call the java function.

Code: Select all

<td>
  <form action="view_results.php" method="post">
    <input class="button" type="submit" value="Delete" onClick=" ConfirmChoice(); return false;">
    <input type="hidden" name="delete_company" value="<?php echo $db_id; ?>">
  </form>
</td
I can not get the <input type="hidden" ... > part to pass the variables to the next page. I am assuming that I need to pass this in the java script, but I have no clue how.

What I am trying to do is ask the user if they are sure that they want to delete the item. If they say ok, then it deletes, and displays a page that says "Company has been deleted!". If they press the cancel button then the popup window will just go away.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

The reason the value isn't getting passed is becoase you aren't submitting the form (in fact you don't need to use a form)

you'll need to pass the id to the Javascript, then insert the id in the location = "view_results.php" line.

So, the form would be like

Code: Select all

<td> 
  <form action="view_results.php" method="post"> 
    <input class="button" type="submit" value="Delete" onClick=" ConfirmChoice(php echo $db_id; ?>); return false;"> 
  </form> 
</td
Javascript

Code: Select all

<Script Language="JavaScript"> 
  function ConfirmChoice(id) 
  &#123; 
    answer = confirm("Do you really want to delete this company?") 
      if (answer !=0) 
    &#123; 
      location = "view_results.php?delete_company=" + id;
    &#125; 
   &#125; 
</script> 

<body> 
etc......
I think that will work, not at my normal comp at the moment so can't check the syntax.

Hopefully it will give you the idea anyway.

Mark
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

Thanks Pimp Daddy, that is exactly what I was looking for !!!
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

btw, is java a lot like php....I need to learn it, should it be easy to learn?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

they aren't like each other at all.

But, i found once i learnt my first language, others are easier to pick up because you start to undertand the concepts better.

Mark
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

brewmiser wrote:btw, is java a lot like php....I need to learn it, should it be easy to learn?
Java or Javascript - similar names, different ways of working.

Mac
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

I meant javascript..... :)
Post Reply