473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.attachEvent)
{

window.attachEvent('onload', setupForm);
}
else if(window.addEventListener)
{
window.addEventListener('load', setupForm,true);
}

function setupForm(someEvent)
{

document.getElementById("testField").style.display ="none";

var field = document.getElementById"buttonField");

if(window.attachEvent)
{
field.attachEvent('onclick', handleClick);
}
else if(window.addEventListener)
{
field.addEventListener('click', handleClick,true);
}

}

function handleClick(someEvent)
{

document.getElementById("testField").style.display ="";
}
Its not working and i have no idea why, Can anyone please help? Thanks

May 11 '07 #1
6 1746
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.attachEvent)
{

window.attachEvent('onload', setupForm);}

else if(window.addEventListener)
{
window.addEventListener('load', setupForm,true);

}

function setupForm(someEvent)
{

document.getElementById("testField").style.display ="none";

var field = document.getElementById"buttonField");

if(window.attachEvent)
{
field.attachEvent('onclick', handleClick);
}
else if(window.addEventListener)
{
field.addEventListener('click', handleClick,true);
}

}

function handleClick(someEvent)
{

document.getElementById("testField").style.display ="";

}

Try this code:

function addListener(ev,lis,elem){
elem=elem||window;
if(window.attachEvent)
elem.attachEvent('on'+ev, lis);
else if(window.addEventListener)
elem.addEventListener(ev, lis,false);
else
elem['on'+ev]=lis
}

addListener("load",setupForm)

function setupForm(someEvent)
{
document.getElementById("testField").style.display ="none";
var field = document.getElementById("buttonField");
addListener('click', handleClick,field);
}

function handleClick(someEvent)
{
document.getElementById("testField").style.display ="";
}

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 addEventListener and attachEvent fails, it sets the
onEventName attribute of element.

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

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

May 12 '07 #6

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

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

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

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

May 12 '07 #7

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

Similar topics

0
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
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....
10
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...
1
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...
3
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...
4
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...
5
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
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.