?
Solved

Dynamic Content from a checkbox

Posted on 2003-03-15
7
Medium Priority
?
362 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
6 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

621 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