Jump to content

Changing class on error


coupe-r

Recommended Posts

Hi All,

 

I have a form with a submit button.  When you click the button, it calls (posts) another page to check the validation and returns with a success message or an error message.  If there is an error message, I need that <input> element to change class.  I can do it with PHP, but when jquery is involved, I'm not sure where to start.

 

JQuery:

function updateButton()
{
$('#errors').hide();
$.post('app_edit_validation.php', 
{
	ref_name1: document.form1.ref_name1_txt.value,
},
	function(output) {
		$('#errors').html(output).fadeIn(2000);
	});
}

 

Input from main form:

<input name="ref_name1_txt" type="text" 
<?php if(isset($ref_name1_error)) { echo 'class="textboxError"'; } 
else { echo 'class="glow"'; } ?> id="ref_name1_txt" 
value="<?php if(isset($ref_name1)) {echo stripslashes($ref_name1);} ?>" 
size="35" maxlength="35" />

 

 

secondary php page for processing:

$ref_name1	= trim(mysqli_real_escape_string($connect, $_POST['ref_name1']));

if(empty($ref_name1))
{
$ref_name1_error = 1;
$val_error[] = 'Reference 1 Name is empty.';
}

 

As you can see, if $ref_name1_error isset, class="textboxError.  Unfortunately, I need the secondary php page to post back the $ref_name1_error variable and then the main form page updates that input.

 

Any ideas?

 

Sorry if this wasn't clear enough.  Let me know if you have any questions.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.