...

View Full Version : Resolved Add class to an element if user has submitted form



RonnyNishimoto
07-25-2012, 02:44 AM
I was wondering how I would add a class to an element if a user has submitted a form. I set the form to:



<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">

</form>


and:



if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// script or php?
}


I have jquery imported, but still don't know how to do this.

Thanks!

Arcticwarrio
07-25-2012, 09:31 AM
it can be done without jquery





<form
<?PHP if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo ' class="class1" ';
}?>

action="<?PHP $_SERVER['PHP_SELF'];?>" method="POST">

</form>

RonnyNishimoto
07-25-2012, 08:53 PM
Sorry, I meant a class far away from the form. Anyone know how to do this?

Keleth
07-25-2012, 09:11 PM
Well, you can use that same code anywhere on the submission page... or do you mean on an entirely unrelated page? If so, you probably want a session or cookie, depending on how/why you're setting it.

DrDOS
07-25-2012, 09:14 PM
You could do it with javascript. Dis iz nawt rokket siense. Just have some php in the javascript near the bottom of the page that echoes an instruction to setAttribute for the element.

RonnyNishimoto
07-25-2012, 10:12 PM
Oh, I don't really know JavaScript, I just finished the PHP tutorial and will be moving onto JavaScript maybe in two weeks. Right now I'm trying to build a test website and needed one class change.

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// script or php?
}
<div id="test" class="<!-- add class -->">

</div>
<div><!--100 lines --></div>
<div><!--100 lines --></div>
<div><!--100 lines --></div>
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">

</form>

RonnyNishimoto
07-25-2012, 10:14 PM
OHHHHHHHHHH I think I got it thanks Arctic!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum