Solved

Javascript onSubmit send on variable too

Posted on 2013-05-13
5
229 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
Comment Utility
<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
Comment Utility
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
Comment Utility
check end of line 1
and line 6 is added
0
 

Author Comment

by:DanteAdmin
Comment Utility
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
Comment Utility
I change the code on this Test page : http://jsfiddle.net/9zkjJ/
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

10 Experts available now in Live!

Get 1:1 Help Now