473,574 Members | 3,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adaptive forms with Javascript

Hi
I'm new to javascript and i'm trying to create a simple form that:
has a text field
and a button
when the page is initially loaded the text field is not visible.
Pressing the button is supposed to make the text field visible

This is the code I have
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<link rel="stylesheet " type="text/css" href="style.css " />
</head>
<body>
<script src = "srcipt.js" type="text/javascript"></script>
<form>
<fieldset id="testField" >
<legend>Test</legend>
Test Field &nbsp<input type="text"/>
</fieldset>
<fieldset>
<legend>Test</legend>
<button type ="button" id="buttonfield " >Show field</button>
</fieldset>
</form>
</body>
</html>

The Javasrcript(in an external file)

if(window.attac hEvent)
{

window.attachEv ent('onload', setupForm);
}
else if(window.addEv entListener)
{
window.addEvent Listener('load' , setupForm,true) ;
}

function setupForm(someE vent)
{

document.getEle mentById("testF ield").style.di splay="none";

var field = document.getEle mentById"button Field");

if(window.attac hEvent)
{
field.attachEve nt('onclick', handleClick);
}
else if(window.addEv entListener)
{
field.addEventL istener('click' , handleClick,tru e);
}

}

function handleClick(som eEvent)
{

document.getEle mentById("testF ield").style.di splay="";
}
Its not working and i have no idea why, Can anyone please help? Thanks

May 11 '07 #1
6 1755
Lee
Damo said:
>
Hi
I'm new to javascript and i'm trying to create a simple form that:
has a text field
and a button
when the page is initially loaded the text field is not visible.
Pressing the button is supposed to make the text field visible

This is the code I have
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<link rel="stylesheet " type="text/css" href="style.css " />
</head>
<body>
<script src = "srcipt.js" type="text/javascript"></script>
Check the name of your script file.
--

May 11 '07 #2
On May 11, 9:01 pm, Lee <REM0VElbspamt. ..@cox.netwrote :
Damo said:


Hi
I'm new to javascript and i'm trying to create a simple form that:
has a text field
and a button
when the page is initially loaded the text field is not visible.
Pressing the button is supposed to make the text field visible
This is the code I have
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<link rel="stylesheet " type="text/css" href="style.css " />
</head>
<body>
<script src = "srcipt.js" type="text/javascript"></script>

Check the name of your script file.

--- Hide quoted text -

- Show quoted text -
oops... i changed it but still nothing

May 11 '07 #3
On May 11, 1:45 pm, Damo <cormacdeba...@ gmail.comwrote:
if(window.attac hEvent)
{

window.attachEv ent('onload', setupForm);}

else if(window.addEv entListener)
{
window.addEvent Listener('load' , setupForm,true) ;

}

function setupForm(someE vent)
{

document.getEle mentById("testF ield").style.di splay="none";

var field = document.getEle mentById"button Field");

if(window.attac hEvent)
{
field.attachEve nt('onclick', handleClick);
}
else if(window.addEv entListener)
{
field.addEventL istener('click' , handleClick,tru e);
}

}

function handleClick(som eEvent)
{

document.getEle mentById("testF ield").style.di splay="";

}

Try this code:

function addListener(ev, lis,elem){
elem=elem||wind ow;
if(window.attac hEvent)
elem.attachEven t('on'+ev, lis);
else if(window.addEv entListener)
elem.addEventLi stener(ev, lis,false);
else
elem['on'+ev]=lis
}

addListener("lo ad",setupForm )

function setupForm(someE vent)
{
document.getEle mentById("testF ield").style.di splay="none";
var field = document.getEle mentById("butto nField");
addListener('cl ick', handleClick,fie ld);
}

function handleClick(som eEvent)
{
document.getEle mentById("testF ield").style.di splay="";
}

May 11 '07 #4
excellent , cheers that did the trick.
What does the line,

elem['on'+ev]=lis ;
do?

Thanks

May 11 '07 #5

Damo wrote:
excellent , cheers that did the trick.
What does the line,

elem['on'+ev]=lis ;
If the tests for addEventListene r and attachEvent fails, it sets the
onEventName attribute of element.

For example-if you call
addListener("lo ad",someFunc)

then that line(if it runs) will set:
window.onload=s omeFunc

May 12 '07 #6

Damo wrote:
excellent , cheers that did the trick.
What does the line,

elem['on'+ev]=lis ;
If the tests for addEventListene r and attachEvent fails, it sets the
onEventName attribute of element.

For example-if you call
addListener("lo ad",someFunc)

then that line(if it runs) will set:
window.onload=s omeFunc

May 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1881
by: Hong Kong Is A Good Place | last post by:
how can i connect my sql server 2000 to Adaptive Sybase Server 11.5 and 12.0? Thx.
4
27535
by: Jan-Friedrich Mutter | last post by:
Hi, I have a problem to access a hidden field by javascript. The name of the field has a dot in it. That's the problem. But I need that dot because it is a "Stuts Property". I'm using IE 6. This is my code: <!-- function changeValue(myvalue) { //works
10
1581
by: Andy B | last post by:
Hi, I am very new to JavaScript and my first assignment is to create a simple game. Below is my code which works fine in IE, but not in any other browser (Opera, Netscape, Mozilla). It has no form defined yet it uses form buttons. Like I said, it works fine in IE but when loaded into another browser and the Start Game! button is clicked,...
1
2382
by: jsausten | last post by:
My client has a custom app using a Sybase Adaptive Server Anywhere 7 DB backend. I need to regularly extract read-only data from a couple of tables in this database and I would have thought it would be simple to setup a System DSN for this purpose, however I am finding it difficult to locate an appropriate ODBC driver, without having to pay...
3
4763
by: M D | last post by:
I've got a data source with a .cdb extension that appears to be accessed via a runtime engine of adaptive server anywhere v.6.0.3. Can anyone advise me how to connect to this data source? What's my provider? thx md *** Sent via Developersdex http://www.developersdex.com ***
4
1753
by: Nacho Nachev | last post by:
Hello, AFIAK ASP.NET (1.1) uses a technology called 'Adpative Rendering' to output HTML that is compliant with the client browser or at least stick to HTML 4 specification or IE. This seems to be quite a problem for me. I have HTML output for Mozilla that has missing style attribute in list boxes and buttons and my layout seems crappy....
5
14113
by: c676228 | last post by:
Hi everyone, my colleagues are thinking about have three insurance plans on one asp page: I simplify the plan as follow: text box:number of people plan1 plan2 plan3
23
3210
by: mosesdinakaran | last post by:
Hi All, I need a small clarification in submitting the forms, Ur suggestions please. In a page I have two form and also two submit butons. (ie)
1
1404
by: Damo | last post by:
Hi I'm new to javascript and been forced to jump in at the deep end(at least this feels like the deep end to me!). I need a form with two buttons, and when one of the buttons is pressed it displays a text box, like so. <form method = "POST" action="<?php echo $_SERVER; ?>">
0
7841
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8100
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8270
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7856
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5335
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3773
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.