CONFUSIONUK Posted September 4, 2010 Share Posted September 4, 2010 I'm just wondering if someone could give me a hand with some validation on a form I have set up for a shoutbox. Below is the script I have made up to check on the click of "#shout_submit" and post the data through another script on the site, what I'm after is if someone could give me an example or some pointers as to how I can maybe use the else if statements as in php to firstly check the form has been filled out, if not display a warning using the alert feature in java prompting to input the name and message or if successful just carry on and process the code below. I have tried a few things but they didn't work and also kept refreshing the page on submit, any help would be highly appreciated! $(function() { $("#shout_submit").click(function() { $.ajax({ type: "POST", url: "get.php?shout", data: $("#shoutbox_form").serialize(), success: function(){ $('#shouts').load('get.php?shouts=5'); $('#shoutbox_form')[0].reset(); } }); return false; }); }); Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 6, 2010 Share Posted September 6, 2010 I hope this is what your looking for. its a small script that checks if the submit button with the name of submit is pressed, and if a certain value or condition is met. I dont know anything about ajax yet, but for php this works. <?php $x = 1; // assign a value to variable x if (isset($_POST['submit'])){ if ($x==$_POST['your_post_value_here']){ echo 'you pressed submit '; // or code or form to be executed }else{ //if submit wasn't pressed echo 'you didn\'t press submit'; } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.