• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Javascript onSubmit send on variable too

Currently we have users being listed and each row holds one entry, and with that there's three options Delete, Seat and Notify

Now clicking either of these first triggers a javascript pop-up that require a yes/no to continue, and then the action gets processed

I would like to send a PHP variable in this call, and as each row is looped out they will have different variables

This is the the current code:

<form method="post" action="http://<?echo $_SESSION["instance"];?>:8080" onSubmit="return confirmActionDelete()">
	<input type="hidden" name="method" value="removeUserFromQueue">
	<input type="hidden" name="clientId" value="<?echo $_SESSION['clientID'];?>">
	<input type="hidden" name="userPhoneNo" value="<?echo $Customer->phone?>">
	<input type="hidden" name="userId" value="<?echo $Customer->userId ?>" />
	<input class="btn red submit" value="DELETE" type="submit" />
</form>

Open in new window


So this is the form, and it triggers this Javscript
function confirmActionDelete() {
        return confirm("Are you sure you want to Delete this party?")
      }

Open in new window


This is looped out several times depending on how many users there are, each have individual name, ID etc

So I'm thinking I should be able to add the same PHP variable that is being looped out in this snippet somewhere, and then be able to get that in the top javascript ?

onSubmit="return confirmActionDelete([b]<?echo $Customer->name?>[/b])"

Open in new window


Or how can I get the pop-up to include the name of some other data ?

Thanks
0
DanteAdmin
Asked:
DanteAdmin
  • 3
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
<form method="post" action="http://<?echo $_SESSION["instance"];?>:8080" onSubmit="return confirmActionDelete(this)">
	<input type="hidden" name="method" value="removeUserFromQueue">
	<input type="hidden" name="clientId" value="<?echo $_SESSION['clientID'];?>">
	<input type="hidden" name="userPhoneNo" value="<?echo $Customer->phone?>">
	<input type="hidden" name="userId" value="<?echo $Customer->userId ?>" />
	<input type="hidden" id="name" value="<?echo $Customer->name ?>" />
	<input class="btn red submit" value="DELETE" type="submit" />
</form>

Open in new window

with :
function confirmActionDelete(form) {
   var name = form.getElementById("name").value;
   alert(name); // testing purpose
}

Open in new window

0
 
DanteAdminAuthor Commented:
When I have this snippet it doesn't bring up any notification, just goes straight to the next step and posts it

var name = form.getElementById("name").value;

Open in new window


Should I have any other values in the form for "this" and in the script for "form" ?
0
 
leakim971PluritechnicianCommented:
check end of line 1
and line 6 is added
0
 
DanteAdminAuthor Commented:
This is what I have no but it just skips the Javascript on that specific button

And as I mentioned there's more then one form, there's three peruser ... the javascript I'm using is below with the updated code for the delete

<SCRIPT LANGUAGE="JavaScript">
      function confirmActionNotify() {
        return confirm("Are you sure you want to Notify this party?")
      }
      
      function confirmActionDelete(form) {
   		var name = form.getElementById("name").value;
   		alert(name); // testing purpose
	}
      
      function confirmActionSeat() {
        return confirm("Are you sure you want to Seat this party?")
      }
</SCRIPT>

Open in new window


<form method="post" action="http://<?echo $_SESSION["instance"];?>:8080" onSubmit="return confirmActionDelete(this)">
	<input type="hidden" name="method" value="removeUserFromQueue">
	<input type="hidden" name="clientId" value="<?echo $_SESSION['clientID'];?>">
	<input type="hidden" name="userPhoneNo" value="<?echo $Customer->phone?>">
	<input type="hidden" name="userId" value="<?echo $Customer->userId ?>" />
	<input type="hidden" id="name" value="<?echo $Customer->name ?>" />
	<input class="btn red submit" value="DELETE" type="submit" />
</form>

Open in new window

0
 
leakim971PluritechnicianCommented:
I change the code on this Test page : http://jsfiddle.net/9zkjJ/
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now