Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2004, 10:42 PM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default adding more objects to an already defined form.

ok, basically i want a new radio button added to an already defined form (orderForm) if the user clicks a radio button that triggers the following function (using the onClick event handler)

<script language="JavaScript" type="text/javascript">
function checkradio()
{
if (orderForm.type.value = "selfserve")
    {
        document.write("<input type='radio' name='type' value='selfserve' />");
    }
}
</script>

-the funky junkie-
 
Old March 19th, 2004, 12:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

A simple way to do this is to put the information you wish to show with the onclick event in a hidden div tag and then just change the visibility property with the onclick event.

Try messing around with the code below.

Code:
<script>
    function ClickTest(index)
    {    
        if (index == 1) 
        {
        //Show Div 1
        document.all["DIV1"].style.visibility = 'visible'
        document.all["DIV1"].style.display = ''        
        //HIde Div 2
        document.all["DIV2"].style.visibility = 'hidden'
        document.all["DIV2"].style.display = 'none'
        }
        else
        {
        //Hide Div 1
        document.all["DIV1"].style.visibility = 'hidden'
        document.all["DIV1"].style.display = 'none'
        //Show Div 2
        document.all["DIV2"].style.visibility = 'visible'
        document.all["DIV2"].style.display = ''
        }        
    }

</script>
<table>
    <tr>
        <td><input onclick="ClickTest(1);" type="radio" name="Test" id="1">Test 1</td>
        <td><div style="visibility:Hidden;display:none"  Id="DIV1">Put Anything you like in here</div></td>
    </tr>
    <tr>
        <td><input onclick="ClickTest(2);" type="radio" name="Test" id="2">Test 2</td>
        <td><div style="visibility:Hidden;display:none"  Id="DIV2">Or here</div></td>
    </tr>
</table>
The 'display' attribute makes the are not take up space if the divs are stacked vertically.(so there is no space when they are not visible)

======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old March 19th, 2004, 12:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

PS. Carn' the Dockers

======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old May 19th, 2004, 09:50 AM
dar dar is offline
Registered User
 
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks rodmcleay!

This was very useful.

There may be some bugs using the DIV tag.
In a form it may cause unnecessary spaces or line brakes.

It might help using SPAN instead of DIV tags.





Similar Threads
Thread Thread Starter Forum Replies Last Post
ADODB.Connection user-defined type not defined Wall st Guru Excel VBA 2 March 26th, 2014 03:44 PM
dynamically adding objects shawnvb VB How-To 3 February 14th, 2007 03:12 PM
Appl-defined or Object-defined error 1004 chp Excel VBA 3 April 4th, 2006 08:12 AM
User-defined type not defined (Icecream.mdb) dloren01 BOOK: Beginning Access VBA 0 June 22nd, 2005 10:36 PM
Form Objects Overlap on some Systems Ron Howerton ASP.NET 1.x and 2.0 Application Design 0 September 30th, 2004 01:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.