473,765 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript in forms

*** post for FREE via your newsreader at post.newsfeed.c om ***

hello,

i am trying to create a login page to my website. there are the usual
fields for name and password, but i want 2 more: a checkbox that a new user
will check, and then another text input that will appear if the box is
checked. is it possible to have this happen dynamically? i.e. the 2nd
password box will appear if it is checked, but it will disappear if it is
unchecked. thanks

andrew
-----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----

Jul 20 '05 #1
4 3219

"Andrew Clark" <la*****@hotmai l.com> wrote in message
news:Xn******** ***********@208 .33.61.211...
*** post for FREE via your newsreader at post.newsfeed.c om ***

hello,

i am trying to create a login page to my website. there are the usual
fields for name and password, but i want 2 more: a checkbox that a new user will check, and then another text input that will appear if the box is
checked. is it possible to have this happen dynamically? i.e. the 2nd
password box will appear if it is checked, but it will disappear if it is
unchecked. thanks

andrew
-----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----


Andrew, I know you could have a layer hidden and show it upon clicking the
checkbox, but I've seen this done on other sites and think there may be a
better way. But for this way just create a layer with it's visibility
default set to hidden, and on you checkbox add an onclick event that passes
it's value (checked or not) to a function that will show or hide the layer
based on it. That'll get the job done but I'd wait for someone with more
experience with this to post something. Hopefully they do cause I'm going to
use it too.
Jul 20 '05 #2
Try this:

<html>
<head>

<style>
..showBoxOff {border: solid 0px #000000; width: 100px;
visibility:hidd en;}
..showBox {border: solid 0px #000000; width: 200px; paddig: 10px;
visibility:visi ble;}
</style>

<script language="JavaS cript">
function validate() {
if (document.login Form.newUserBox .checked)
document.all.ne wUser.className ="showBox"

else
document.all.ne wUser.className ="showBoxOff "
}
</script>
</head>

<body>

<form name="loginForm ">
username: <input type="text" name="user"><br >
password: <input type="password" name="pass"><br >
new user: <input type="checkbox" name="newUserBo x"
onClick="valida te()">
</form>

<div class="showBoxO ff" id="newUser">

<form>
new field: <input type="text">
</form>
</div>

</body>
</html>
Jul 20 '05 #3
Andrew Clark wrote:
hello,

i am trying to create a login page to my website. there are the usual
fields for name and password, but i want 2 more: a checkbox that a new user
will check, and then another text input that will appear if the box is
checked. is it possible to have this happen dynamically? i.e. the 2nd
password box will appear if it is checked, but it will disappear if it is
unchecked. thanks

andrew


<body onload="setVisi bility('additio nalInfoId', false);">
<form name="loginForm ">
<input type="text" name="userName" id="userNameId " />
<input type="password" name="userPass" id="userPassId " />
<input type="checkbox" name="newUser" id="newUserId"
onclick="toggle Visibility(this );" />
<input type="text" name="additiona lInfo" id="additionalI nfoId" />
</form>
<script type="text/javascript">
function isDefined(item) {
return (typeof item != 'undefined');
}
function setVisibility(e lementId, displayState) {
if (document.getEl ementById) {
var element = document.getEle mentById(elemen tId);
if (element && isDefined(eleme nt.style) &&
isDefined(eleme nt.style.displa y)) {
if (displayState) {
element.style.d isplay = 'inline';
} else {
element.style.d isplay = 'none';
}
}
}
}
function toggleVisibilit y(chkbox) {
var id = chkbox.form.add itionalInfo.id;
setVisibility(i d, chkbox.checked) ;
}
</script>

Works in Netscape 4.x and Opera 6.05 (by simply keeping the input element
visible all the time), IE6SP1, Mozilla and Opera 7.11 (by toggling the
visibility of the input element).

By starting the display style in the default state (in this case 'inline') and
turning it off only when the browser is capable of doing so, you've guaranteed
that the input element will only be set to display 'none' in browsers that are
capable of turning it back on again.

It's coded specific to 'inline' elements, you could make it more generic to
handle both 'block' and 'inline' elements by passing that rather then a
boolean. In fact, you could pass both a style property and it's value and make
it even more generic:

function setStyle(id, styleProperty, styleValue) {
if (document.getEl ementById) {
var element = document.getEle mentById(id);
if (element && isDefined(eleme nt.style) &&
isDefined(eleme nt[styleProperty])) {
element[styleProperty] = styleValue;
}
}
}

--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #4
*** post for FREE via your newsreader at post.newsfeed.c om ***

Grant Wagner <gw*****@agrico reunited.com> wrote in
news:3F******** *******@agricor eunited.com:
Andrew Clark wrote:
hello,

i am trying to create a login page to my website. there are the usual
fields for name and password, but i want 2 more: a checkbox that a
new user will check, and then another text input that will appear if
the box is checked. is it possible to have this happen dynamically?
i.e. the 2nd password box will appear if it is checked, but it will
disappear if it is unchecked. thanks

andrew


<body onload="setVisi bility('additio nalInfoId', false);">
<form name="loginForm ">
<input type="text" name="userName" id="userNameId " />
<input type="password" name="userPass" id="userPassId " />
<input type="checkbox" name="newUser" id="newUserId"
onclick="toggle Visibility(this );" />
<input type="text" name="additiona lInfo" id="additionalI nfoId" />
</form>
<script type="text/javascript">
function isDefined(item) {
return (typeof item != 'undefined');
}
function setVisibility(e lementId, displayState) {
if (document.getEl ementById) {
var element = document.getEle mentById(elemen tId);
if (element && isDefined(eleme nt.style) &&
isDefined(eleme nt.style.displa y)) {
if (displayState) {
element.style.d isplay = 'inline';
} else {
element.style.d isplay = 'none';
}
}
}
}
function toggleVisibilit y(chkbox) {
var id = chkbox.form.add itionalInfo.id;
setVisibility(i d, chkbox.checked) ;
}
</script>

Works in Netscape 4.x and Opera 6.05 (by simply keeping the input
element visible all the time), IE6SP1, Mozilla and Opera 7.11 (by
toggling the visibility of the input element).

By starting the display style in the default state (in this case
'inline') and turning it off only when the browser is capable of doing
so, you've guaranteed that the input element will only be set to
display 'none' in browsers that are capable of turning it back on
again.

It's coded specific to 'inline' elements, you could make it more
generic to handle both 'block' and 'inline' elements by passing that
rather then a boolean. In fact, you could pass both a style property
and it's value and make it even more generic:

function setStyle(id, styleProperty, styleValue) {
if (document.getEl ementById) {
var element = document.getEle mentById(id);
if (element && isDefined(eleme nt.style) &&
isDefined(eleme nt[styleProperty])) {
element[styleProperty] = styleValue;
}
}
}

--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...pt/1.3/referen
ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a.../dhtml_referen
ce_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html


thanks! this is exactly what i'm looking for.

andrew
-----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----

Jul 20 '05 #5

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

Similar topics

0
7070
by: Gowhera Hussain | last post by:
Use This for Learning Only .... Do Not Try To Act Smart HACKING WITH JAVASCRIPT Dr_aMado Sun, 11 Apr 2004 16:40:13 UTC This tutorial is an overview of how javascript can be used to bypass simple/advanced html forms and how it can be used to override cookie/session
3
6306
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am sending my code here.. Thanks in Advance... Regards
0
9568
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8833
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
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
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.