Page 1 of 1

Confirm window not working properly

Posted: Sun Sep 21, 2003 11:26 am
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.

Posted: Sun Sep 21, 2003 11:44 am
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

Posted: Sun Sep 21, 2003 12:59 pm
by brewmiser
Thanks Pimp Daddy, that is exactly what I was looking for !!!

Posted: Sun Sep 21, 2003 3:26 pm
by brewmiser
btw, is java a lot like php....I need to learn it, should it be easy to learn?

Posted: Mon Sep 22, 2003 3:25 am
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

Posted: Mon Sep 22, 2003 5:08 am
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

Posted: Mon Sep 22, 2003 11:34 am
by brewmiser
I meant javascript..... :)