Solved

Javascript onSubmit send on variable too

Posted on 2013-05-13
5
231 Views
Last Modified: 2013-05-14
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
Comment
Question by:DanteAdmin
  • 3
  • 2
5 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39162067
<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
 

Author Comment

by:DanteAdmin
ID: 39162568
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
 
LVL 82

Expert Comment

by:leakim971
ID: 39162592
check end of line 1
and line 6 is added
0
 

Author Comment

by:DanteAdmin
ID: 39162700
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
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39163521
I change the code on this Test page : http://jsfiddle.net/9zkjJ/
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Trouble inserting a variable  in javascript 7 42
Regular Expression Calculator Tester 2 59
Why my select dropdown does not work? 8 27
CSS Logo Problem. 2 8
This article discusses how to create an extensible mechanism for linked drop downs.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now