Show div if PHP form is successfull

Javascript coding ..

Moderators: macek, egami, gesf

soder
New php-forum User
New php-forum User
Posts: 15
Joined: Fri Mar 16, 2012 7:38 pm

Show div if PHP form is successfull

Postby soder » Sat Mar 24, 2012 7:51 pm

Heya, I got this code

Code: Select all

function initShowHideDivs()
{
   var divs = document.getElementsByTagName('DIV');
   var divCounter = 1;
   for(var no=0;no<divs.length;no++){
      if(divs[no].className=='dhtmlgoodies_question'){
         divs[no].onclick = showHideContent;
         divs[no].id = 'dhtmlgoodies_q'+divCounter;
         var answer = divs[no].nextSibling;
         while(answer && answer.tagName!='DIV'){
            answer = answer.nextSibling;
         }
         answer.id = 'dhtmlgoodies_a'+divCounter;
         contentDiv = answer.getElementsByTagName('DIV')[0];
         contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
         contentDiv.className='dhtmlgoodies_answer_content';
         contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
         answer.style.display='none';
         answer.style.height='1px';
         divCounter++;
      }
   }
}
window.onload = initShowHideDivs;

This is to hide the div when the page loads.

and I got this PHP form:

Code: Select all

if(strlen($_POST['cat']) > 2)
{
  $sql="INSERT INTO categories (username, name) VALUES ('$name','$_POST[cat]')";
  mysql_query("$sql");
  echo "Category ".$_POST[cat]." has been created.<br>";
?>
<script type="text/javascript">
  initShowHideDivs();
</script>
<?php
}


How do I make the div show when the form loads successfully?

Regards,
Soder.

viper94x
New php-forum User
New php-forum User
Posts: 15
Joined: Mon Apr 16, 2012 2:15 am
Location: Netherlands

Re: Show div if PHP form is successfull

Postby viper94x » Tue Apr 17, 2012 9:47 am

to hide it on start : css-> visibility: hidden;
To show it, use scriptaculous or jQuery.
Thats by far the easiest and best way.

Sam

User avatar
JordanMRichards
New php-forum User
New php-forum User
Posts: 84
Joined: Mon Apr 23, 2012 7:43 am
Contact:

Re: Show div if PHP form is successfull

Postby JordanMRichards » Wed Apr 25, 2012 7:09 am

Personally I'd use PHP to handle this.

check to see if the form has been submitted then echo the div out.. like this.

Code: Select all

//cat is the form data past through, change cat to the name of the element that you want to check if it's been submitted..

if(isset($_POST['cat'])) {
    echo "
//Your div here
<div>
<p>
SUCCESS! ;)
</p>
</div>

";
}



Hope this helped :)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 Year Old Programmer & Graphic Artist, Confident and Courageous
Image


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest

cron