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
https://forums.phpfreaks.com/topic/244973-changing-class-on-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.