Need help passing form variables through javascript

Hi, I downloaded this comment wall script here Facebook Wall Script 3.0 with PHP and Jquery

And I’m attempting to customise and expand it and I’ve not done so bad so far. Guy knows what he is doing but I’ve managed to condense a lot of functions and better organise some stuff for better results.

But I cannot figure out the javascript side. I want to require a poster to put in their name and email before submitting a comment. I struggled to figure out why the variables weren’t passing and then realised that they were processed through a javascript file for AJAX. But I cannot understand it well enough to figure out how to pass the additional variables.

This is the code.

$(document).ready(function() 
{
// Update Status
$(".update_button").click(function() 
{
var updateval = $("#update").val();
var dataString = 'update='+ updateval;
if(updateval=='')
{
alert("Please Enter Some Text");
}
else
{
$("#flash").show();
$("#flash").fadeIn(400).html('Loading Update...');
$.ajax({
type: "POST",
url: "message_ajax.php",
data: dataString,
cache: false,
success: function(html)
{
$("#flash").fadeOut('slow');
$("#content").prepend(html);
$("#update").val('');	
$("#update").focus();

    	

$("#stexpand").oembed(updateval);
  }
 });
}
return false;
	});

There’s further code in the file but this is the part pertinent to what I need. updateval, as far as I can tell is taking the information from “update” here.

<form method="post" action="">

     <input type='text' name='nickname' id='nickname' maxlength='25' />
		<label for='fullname'>Your Name: <em>(required)</em> </label>
     	<br />													
     		<input type='email' name='email' id='email' maxlength='30'/>			
	 			<label for='email'>Email (will not be published) <em>(required)</em> </label>
     			<br />													
     				<input type='text' name='website' id='website' maxlength='50'/>			
	 					<label for='website'>Website </label>
           			 	<br />	
							<textarea cols="30" rows="4" name="update" id="update" maxlength="400" ></textarea>
                			<br />
                
<input type="submit" value=" Submit Comment "  id="update_button"  class="update_button"/>
</form>

Does anyone know how to do this? I’m sure it will be something simple but I just don’t know any javascript or AJAX, all I ended up doing was combining username and message into one field.

If it helps, this is what I’ve done. http://cms.mediaxombie.com/wall/

If you want to post their name and email address as a part of the ajax request, you will need to update this piece of the code:


var updateval = $("#update").val();
var dataString = 'update='+ updateval;

Here is where the sanity check is performed:


if (updateval=='') {
alert('Please Enter Some Text');
} else {
    ...
}

So you can add other conditions as an “else if” part of the structure.


if (updateval=='') {
    alert("Please Enter Some Text");
} else if (...) {
    ...
} else if (...) {
    ...
} else {
    ...
}

where the else if conditions check for their name and email address.

Yeah that’s what I want, to pass it to message_ajax.php

I have the variables passing INTO the javascript but I want to pass them on. But when I tried to alter this line:


var dataString = 'update='+ updateval;

It just came out as a single string. Is there some trick to keeping them as separate items or a special icon to divide them?

I tried


var dataString = 'update='+ updateval;'nickname='+updateval2

and so on but that only showed the first value, so I’m obviously not knowledgeable on this.

Do you know about the structure of a querystring?

Do you mean something like this?


var dataString = 'update='+ updateval & 'nickname='+updateval2;

Something like that. The ampersand should be in the string as an ordinary piece of text

YESSSSSSSSSSSSSSSSSSSSSSS

Thank you so much paul, I was quite chuffed with how I’d developed his code but couldn’t get this at all. Never would have thought to put the “&” in the string.

Thanks a lot for the help.