Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript onSubmit send on variable too

Posted on 2013-05-13
5
Medium Priority
?
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 total points
ID: 39163521
I change the code on this Test page : http://jsfiddle.net/9zkjJ/
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

618 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