Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-02-2012, 05:46 AM   PM User | #1
Dannymh
New to the CF scene

 
Join Date: Jan 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Dannymh is an unknown quantity at this point
Multiple forms, on one page as a single function

I have been going round in circles trying raw ajax and a number of other methods and think the best thing to do is use jquery or similar but I am a little stuck.

I have a page that generates a table, each row of the table becomes a separate form. This is for a work roster style thing, that shows user statuses, such as at lunch, busy etc for a distributed team that I work in.

I am trying to make the page a little cleaner and use AJAX for the form processing as well as bringing in the content and refreshing it at regular intervals without the need to refresh the whole page.

Anyway the content would look like this
Code:
<table>
<tr>
<td><form id="user1form" name="user1form><select name="theaction"><option value="1">Available</option>
<option value="2">At Lunch</option>
</select>
<input type="hidden" name="userid" id="userid" value="1"></td><td><input type="submit" name="submit" value="go"></td>
</form>
</tr>
<tr>
<td><form id="user2form" name="user2form><select name="theaction"><option value="1">Available</option>
<option value="2">At Lunch</option>
</select></td>
<input type="hidden" name="userid" id="userid" value="2">
</form>
<td><input type="submit" name="submit" value="go"></td>
</tr>
</table>
Thats a basic version of what is there, but gives you an idea. It is all generated from a database using PHP

Now I want to use a single ajax function to process which ever form has been updated, update the database and then reload the data on the page.

Looking at a basic JQuery example I would use something like

Code:
<script type="text/javascript">
	$(document).ready(function(){
		$("#myform").validate({
			debug: false,
			rules: {
				name: "required",
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				name: "Please let us know who you are.",
				email: "A valid email will help us get in touch with you.",
			},
			submitHandler: function(form) {
				// do other stuff for a valid form
				$.post('process.php', $("#myform").serialize(), function(data) {
					$('#results').html(data);
				});
			}
		});
	});
	</script>
However I would need to wrap that in a function and create put a variable for myForm of the form name to represent user1form etc.
Also likely I wouldn't need the validation stuff

Is this even possible?

Cheers
Dan

Last edited by Dannymh; 02-02-2012 at 05:52 AM..
Dannymh is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:44 PM.


Advertisement
Log in to turn off these ads.