?
Solved

Dynamic Content from a checkbox

Posted on 2003-03-15
7
Medium Priority
?
360 Views
Last Modified: 2013-12-12
How can I have a user view more content on page by checking a checkbox?

So they hit the order page and it shows the billing address and the shipping address.  Below the shipping address they have the option to ship part of the order to someone else.  But instead of showing the extra shipping form I would like to have a checkbox and when the use checks it the new info is displayed?   Any thoughts?

Thanks in advance!!

Owen
0
Comment
Question by:owenj24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 1

Expert Comment

by:montonen
ID: 8149736
Hi Owen

This is more of an DHTML and Javascript problem.
This could help.
Browser dependent code... but I guess you get the idea.


<html>
<head>
<title>Dummy Test</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function showForm(spanId) {
 document.all[spanId].style.visibility = 'visible';
}
//-->
</script>
</head>

<body>
<form name="form1" method="post" action="">
  <p>
    <input name="checkbox" type="checkbox" onClick="javascrip:showForm('moreForm');" value="checkbox"> More form
  </p>
  <p>
    <SPAN style="visibility:hidden" id="moreForm"><textarea name="textarea"></textarea></SPAN>
  </p>
</form>
</body>
</html>

Regards
Jonas Montonen
0
 
LVL 1

Accepted Solution

by:
montonen earned 140 total points
ID: 8149749
Improvements to implement:

- Check the actual status of the checkbox onClick, if changed to "checked" then show FORM or else hide it again

- Make the setting of visibility browser independent (browser check and normally duplicate code for different
versions)

- Much more I guess ;)
0
 

Author Comment

by:owenj24
ID: 8151364
I will test this out tonight...thanks a lot...will close question out then!

Thanks again!

Owen
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:owenj24
ID: 8154433
Hmmmm...it looks like it works in IE but not Mozilla. So it looks like you were correct in "- Make the setting of visibility browser independent (browser check and normally duplicate code for different versions)"

So I will play around a bit more with it tonight (Got bored at work just now ;-) ) But I think you have pretty much answered this.  But feel free to add more if ya like ;-)

Thanks!

Owen

0
 

Expert Comment

by:tirdun
ID: 8167512
You could have the checkbox submit the page to itself.

(onCheck="document.form.submit()")

During each page load PHP can check to see if the checkbox is set using issset($_POST[]). If not, it won't show the extra data. You could expand further by setting multiple checkboxes (or links or buttons or whatever) and having PHP check each one before showing the extended data. It means reloading the page each time, but it's more platform-friendly than DHTML.

If you want to alter the form to submit to other pages you can create simple javascripts to change the form action:

function formsubmit(newpage)
{
   document.form.action=newpage;
   document.form.submit();
}


so any form element can use:
 OnWhatever="javascript:formsubmit(nextpage)"

Since Radio and Checkboxes are a pain to check sometimes in JS and PHP you could also have a function to set a hidden value by checking the box, then reloading the page:

function switchvalue(element,newval)
{
  changelement = eval("document.form."+element);
  changeelement.value = newval;
  document.form.submit();
}

and in the HTML body have:

<input type="checkbox" name="more" onCheck="javascript:switchvalue(&quot;showmore&quot,&quot;yes&quot;)">;
<input type="hidden" name="showmore" value="no">

Then have

if ((!isset($_POST["showmore"]))&&($_POST["showmore"]=="yes")):
   # // Extra HTML stuff
else:
   # // No Extra HTML stuff
endif;
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 9682763
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation in the Cleanup topic area:

Answered by montonen

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

snoyes_jw
EE Cleanup Volunteer
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question