Jump to content

how to hide data in the same page


Recommended Posts

Hello im a still a newbie, :) but with the help of this great site started to learn few things... javascript ws getting tooo complex fo rme so i jumped directly to php :) .... im still doing the basic and so far it goin OK..i ws tryin out diff. things wen i got this problem.. is it possible to hide data while displaying next set of data...for eg:- A - choose any one.. radio button 1 radio button 2 submit B - now choose from these... radio button 1 radio button 2 submit C - Now choose from these... radio button 1 radio button 2 submit above is just a rough structure of the html form... . here in set A if i choose radio button 1 then set B should b displayed and tat time this Set A should not b visible. similarly If radio button 2 is selected in set A then set C should b displayed and tat time too set A should b hidden. Method=POST or GET and Action to this form will be to the same page. I have tried transferring the result to another page in action and it worked fine.. but is it possible to keep all this in SAME PAGE? is it possible to do in PHP? wat are the diff.. ways - Better optimized ways or simple ways to do it?Hopefully i was able to make u guys understand wat i meant... if no then will submit a sample code i did. Thanks in advance

Link to post
Share on other sites

A shame you don't like javascript. You'll need it for this. Fortunately, it and PHP have many similarities.Let's say Set Two of buttons lives in a div. Then all you need to do is make the div go away and come back again. You could toggle visibility or display mode (with different effects on the surrounding content) or even set the div's coordinates so that when you want it hidden it's off screen at -1000, -1000.We'll all be very impressed if you can search the school for entries pertaining to the specific issues I just raised (visibility, display, and position) and giving all this a try for yourself. If that doesn't work, come back with more questions.

Link to post
Share on other sites
We'll all be very impressed if you can search the school for entries pertaining to the specific issues I just raised (visibility, display, and position) and giving all this a try for yourself. If that doesn't work, come back with more questions.
I was hoping that there would be some solution in PHP itself. But as suggested by you will go through the possibilities using javascript also.
Link to post
Share on other sites
I was hoping that there would be some solution in PHP itself.
Not if I understood the question correctly (which I don't always do). PHP can run all kinds of computations on the server, and it can use that ability to tell a document what to look like when it finally gets sent to the browser. But once it hits the browser, PHP is out of it. View source doesn't even display any PHP code. You can get back in touch with the server through AJAX, but as I understood the problem, AJAX is not the right tool.Basically, any changes bigger than rollovers that happen on the client's screen require Javascript. But you were going to get there anyway, really. A complete web person knows the whole package, and I sense that's what you want to be.
Link to post
Share on other sites
I have tried transferring the result to another page in action and it worked fine.. but is it possible to keep all this in SAME PAGE? is it possible to do in PHP?
As you want to submit after each choice, then yes, you can do it with php using the same page. Using php, the html contents of that page are dependent on your php code, and you can include logic in that code that looks at what's been submitted and emits the next question. So rather than hiding page content, it becomes a question of deciding page content.You'll need to look at the details of exactly how you want to do this, but the rough idea is to examine the form fields submitted: and if A has been submitted with the first radio button selected, write out the html for B, but if it's the other radio button, write out the html for C instead. Should be a useful php learning exercise for you!
Link to post
Share on other sites
"..... A complete web person knows the whole package, and I sense that's what you want to be.
"........ Should be a useful php learning exercise for you!
Thank You Deirdre's Dad and Reg Edit for your support... :) & I do get the result , wen i select radio button1 in Set A and submit it displays Set B, and If i select radio button 2 in Set A and submit it shows Set C. BUT in both the cases Set A is still being displayed on the top. My plan is just to display the result (Set B or Set C) ..... While all these data's (html + php) are in same page. :)
Link to post
Share on other sites

So hide Set A. If you're doing this in javascript, the best bet might be to set it's container div's display to none . Then, you won't have a big empty space where it used to be, but rather Set B and all the other content will move up the page.

Link to post
Share on other sites
So hide Set A. If you're doing this in javascript, the best bet might be to set it's container div's display to none . Then, you won't have a big empty space where it used to be, but rather Set B and all the other content will move up the page.
On the other hand, if you're doing it in php, your php logic just needs to avoid emitting the html for Set A at those times. Either way, sounds like good progress already. You just need to finish the logic to only display part A when appropriate. If that's giving you trouble, post the code here so we can suggest a fix.
Link to post
Share on other sites

Thanks again .... well I did write the code in 2 diff. ways ... one in which html and php are seperate. and anther were all html is being printed by the PHP's print statement...just to c in which situation i can get my solution [even though partial results r coming , Both may contain stupid errors please do point them out too] I haven't used in javascript yet... BUT I WILL TRY tat method also. once I get the logic right, :) both r pretty much similar. anyways just postin a sample. please take a look ... at sample.php

<?phpprint '<form method="POST" action="sample.php">		1. what do you choose? <br /><br /><input type="radio" name="r1" value="b" /> B <br /><input type="radio" name="r1" value="c" /> C <br /><br /><input type="submit" name="submit" /><br /><br />';$x=$_POST['r1'];if($_POST['r1']){	if($x=={		print " You have choosen SET B <br/>";		print '2. what do you choose NOW? <br /><br /><input type="radio" name="r2" value="red" /> RED <br /><input type="radio" name="r2" value="blue" /> BLUE <br /><br /><input type="submit" name="submit" />';		}	else {		print "you have choosen SET C <br />";		print '3. what do you choose Now? <br /><br /><input type="radio" name="r3" value="tea" /> TEA <br /><input type="radio" name="r3" value="coffee" /> COFFEE <br /><br /><input type="submit" name="submit" />';		}		 } print '</form>'; ?>

here wen B is slected it displays the next level bt tat time question 1 is still being displayed. I guess a diff. approach is needed. :mellow:

Link to post
Share on other sites
here wen B is slected it displays the next level bt tat time question 1 is still being displayed. I guess a diff. approach is needed. :)
The approach is fine, now you just need a way to discern which state you are dealing with: either the page is being rendered for the first time (so Set A needs rendering), or a form has been submitted (so a different set needs rendering instead). I've given an example below of how you could do this. You can count the number of elements in the $_POST array to find out whether it's a postback:
if (count($_POST)==0){  // Nothing's been posted: initialise page by rendering A.   print '1. what do you choose? <br /><br />  <input type="radio" name="r1" value="b" /> B <br />  <input type="radio" name="r1" value="c" /> C <br />  <br />  <input type="submit" name="submitA" /><br /><br />';}else{  // Something's been posted. See what to render next instead of A.  if ($_POST['submitA']) {  // A submitted: render B or C. (Example renders B only for simplicity)  echo 'This is B<br>';  echo '<input type="submit" name="submitB" />';  }  else if ($_POST['submitB']) {  // B submitted: render Z.  // (Other Z details here)  echo 'This is Z<br>';  echo '<input type="submit" name="submitZ" />';  }		  else if ($_POST['submitZ']) {  // Z submitted  echo 'The end';  }}

In this example I've given the submit buttons different names (submitA etc) to tell which state we're in. As to the javascript/php question, both are well worth learning as they are both needed for different things (javascript for client-side scripting, and php for server-side scripting).

Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...