473,394 Members | 1,755 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,394 software developers and data experts.

Help with basic onClick mechanism please

I am pretty new to JavaScript and having trouble with something that
should, I think, be fairly easy.

I have one form.
I have two radio buttons.
I have a text box that is hidden.
If you click the radio button that has the value "Yes", the hidden
field should be made visible.

I would appreciate help knowing what I did wrong. Here is the
pertinent code:

<TD WIDTH=100% ALIGN=LEFT>
<INPUT TYPE="HIDDEN" NAME="Institution" VALUE="{Individuals.CS-
Appl Academic.Institution}" SIZE=32 MAXLENGTH=5>
</TD>

<TD width="100%">
<Input type="radio" name="addInstitution" value="Yes"
onClick="choiceInstitution(this.form)">
<Input type="radio" name="addInstitution" CHECKED value="No"
onClick="choiceInstitution(this.form)">
</TD>

<script LANGUAGE="JavaScript">
void choiceInstitution(theForm) {
if(theForm.addInstitution[0].checked)
{
document.theForm.getElementByID("Institution").vis ibility =
"visible"';
}
}

</script>
When I click the radio button with the value of "Yes", nothing changes
on the screen. I'm wondering if this is because the type of the
element is HIDDEN. How should I change this so that I can get it to
display when I click the yes radio button? Thanks.

Ken


Jun 27 '08 #1
12 1058
OccasionalFlyer wrote:
[snip]
>
I would appreciate help knowing what I did wrong. Here is the
pertinent code:

<TD WIDTH=100% ALIGN=LEFT>
<INPUT TYPE="HIDDEN" NAME="Institution" VALUE="{Individuals.CS-
Appl Academic.Institution}" SIZE=32 MAXLENGTH=5>
</TD>
An Input element of the HIDDEN type will never be displayed.
You need to change this to the TEXT type and set the style attribute to
"visibility:hidden;"
>
<TD width="100%">
<Input type="radio" name="addInstitution" value="Yes"
onClick="choiceInstitution(this.form)">
<Input type="radio" name="addInstitution" CHECKED value="No"
onClick="choiceInstitution(this.form)">
</TD>

<script LANGUAGE="JavaScript">
void choiceInstitution(theForm) {
if(theForm.addInstitution[0].checked)
{
document.theForm.getElementByID("Institution").vis ibility =
"visible"';
}
}

</script>
You don't have any elements with an id of "Institution"
I assume you mean your HIDDEN input element which has a /name/ of
"Institution".

Give that an id of "Institution" and you're golden
Jun 27 '08 #2
On Jun 11, 2:26 pm, Dan Rumney <danrum...@warpmail.netwrote:
OccasionalFlyer wrote:

[snip]
I would appreciate help knowing what I did wrong. Here is the
pertinent code:
<TD WIDTH=100% ALIGN=LEFT>
<INPUT TYPE="HIDDEN" NAME="Institution" VALUE="{Individuals.CS-
Appl Academic.Institution}" SIZE=32 MAXLENGTH=5>
</TD>

An Input element of the HIDDEN type will never be displayed.
You need to change this to the TEXT type and set the style attribute to
"visibility:hidden;"


<TD width="100%">
<Input type="radio" name="addInstitution" value="Yes"
onClick="choiceInstitution(this.form)">
<Input type="radio" name="addInstitution" CHECKED value="No"
onClick="choiceInstitution(this.form)">
</TD>
<script LANGUAGE="JavaScript">
void choiceInstitution(theForm) {
if(theForm.addInstitution[0].checked)
{
document.theForm.getElementByID("Institution").vis ibility =
"visible"';
}
}
</script>

You don't have any elements with an id of "Institution"
I assume you mean your HIDDEN input element which has a /name/ of
"Institution".

Give that an id of "Institution" and you're golden
Thanks for the help. I have a follow-up question. I know how to set
styles for a whole page, whether in the page or (better) in an
external style sheet. I don't want to override the style of all INPUT
elements, but I can't seem to find any examples of modifying the style
for one specific HTML element on a page, and nothing else of that same
type. How can I do that? Thanks.
Jun 27 '08 #3
OccasionalFlyer wrote:
[snip]
>
Thanks for the help. I have a follow-up question. I know how to set
styles for a whole page, whether in the page or (better) in an
external style sheet. I don't want to override the style of all INPUT
elements, but I can't seem to find any examples of modifying the style
for one specific HTML element on a page, and nothing else of that same
type. How can I do that? Thanks.
Wrong newsgroup for that. [Followup-To set to
comp.infosystems.www.authoring.stylesheets]

However, you can use id and class selectors in your stylesheets to limit
your styling to specific elements.

For instance

input#Institution
{

}

should be used for applying styling to the INPUT element with
id="Institution"
Jun 27 '08 #4
On Jun 11, 3:26 pm, OccasionalFlyer <klit...@apu.eduwrote:
On Jun 11, 2:26 pm, Dan Rumney <danrum...@warpmail.netwrote:
OccasionalFlyer wrote:
[snip]
I would appreciate help knowing what I did wrong. Here is the
pertinent code:
<TD WIDTH=100% ALIGN=LEFT>
<INPUT TYPE="HIDDEN" NAME="Institution" VALUE="{Individuals.CS-
Appl Academic.Institution}" SIZE=32 MAXLENGTH=5>
</TD>
An Input element of the HIDDEN type will never be displayed.
You need to change this to the TEXT type and set the style attribute to
"visibility:hidden;"
<TD width="100%">
<Input type="radio" name="addInstitution" value="Yes"
onClick="choiceInstitution(this.form)">
<Input type="radio" name="addInstitution" CHECKED value="No"
onClick="choiceInstitution(this.form)">
</TD>
<script LANGUAGE="JavaScript">
void choiceInstitution(theForm) {
if(theForm.addInstitution[0].checked)
{
document.theForm.getElementByID("Institution").vis ibility =
"visible"';
}
}
</script>
You don't have any elements with an id of "Institution"
I assume you mean your HIDDEN input element which has a /name/ of
"Institution".
Give that an id of "Institution" and you're golden

Thanks for the help. I have a follow-up question. I know how to set
styles for a whole page, whether in the page or (better) in an
external style sheet. I don't want to override the style of all INPUT
elements, but I can't seem to find any examples of modifying the style
for one specific HTML element on a page, and nothing else of that same
type. How can I do that? Thanks.
I modified my JavaScript like this, but this still doesn't work:
<script LANGUAGE="JavaScript">
void choiceInstitution(theForm) {
if(theForm.getElementByID.("Institution").style.vi sibility=="hidden")
{
document.theForm.getElementByID("Institution").sty le.visibility =
"visible"';
}
}

function init(){
document.forms[0].getElementByID("Institution").style.visibility
= "hidden";
}

window.onload=init;

</script>
Jun 27 '08 #5
OccasionalFlyer wrote:
[snip]
I modified my JavaScript like this, but this still doesn't work:
<script LANGUAGE="JavaScript">
void choiceInstitution(theForm) {
if(theForm.getElementByID.("Institution").style.vi sibility=="hidden")
{
document.theForm.getElementByID("Institution").sty le.visibility =
"visible"';
}
}

function init(){
document.forms[0].getElementByID("Institution").style.visibility
= "hidden";
}

window.onload=init;

</script>
What about your INPUT element... did you set it's ID correctly?
Jun 27 '08 #6
On Jun 11, 4:57 pm, Dan Rumney <danrum...@warpmail.netwrote:
OccasionalFlyer wrote:

[snip]
I modified my JavaScript like this, but this still doesn't work:
<script LANGUAGE="JavaScript">
void choiceInstitution(theForm) {
if(theForm.getElementByID.("Institution").style.vi sibility=="hidden")
{
document.theForm.getElementByID("Institution").sty le.visibility =
"visible"';
}
}
function init(){
document.forms[0].getElementByID("Institution").style.visibility
= "hidden";
}
window.onload=init;
</script>

What about your INPUT element... did you set it's ID correctly?
Yes. Please excuse the extra HTML (added by the PeopleSoft tool I'm
required to use for part of this, hence the weird value for
"Institution") but here's all the HTML that should show up on the
form:

<TABLE width=100% border=0 cellpadding=0 cellspacing=2>

<!** Name=AddInt, Type=Html **>
<TR>
<TD width="100%">
<P>
Add Institution?
</P>
</TD>
</TR>
<!**>
</TABLE>

<TABLE width=100% border=0 cellpadding=0 cellspacing=2>

<!** Name=Institution, Type=Text Entry **>
<TR>
<TD NOWRAP ALIGN=LEFT>
Institution
</TD>
<TD WIDTH=100% ALIGN=LEFT>
<INPUT TYPE="TEXT" NAME="Institution" VALUE="{Individuals.CS-
Appl Academic.Institution}" SIZE=32 MAXLENGTH=5>
</TD>

</TR>
<!**>
</TABLE>

<TABLE width=100% border=0 cellpadding=0 cellspacing=2>

<!** Name=Radio button to test JavaScript, Type=Html **>
<TR>
<TD width="100%">
<Input type="radio" name="addInstitution" value="Yes"
onClick="choiceInstitution(this.form)">
<Input type="radio" name="addInstitution" CHECKED value="No"
onClick="choiceInstitution(this.form)">

</TD>
</TR>
<!**>
</TABLE>
Jun 27 '08 #7
OccasionalFlyer wrote:
[snip]
<TD WIDTH=100% ALIGN=LEFT>
<INPUT TYPE="TEXT" NAME="Institution" VALUE="{Individuals.CS-
Appl Academic.Institution}" SIZE=32 MAXLENGTH=5>
</TD>
You still don't have an id attribute

<INPUT TYPE="TEXT" id="Institution"
NAME="Institution" VALUE="{Individuals.CS-Appl Academic.Institution}"
SIZE=32 MAXLENGTH=5>
Jun 27 '08 #8
On Jun 11, 4:40 pm, OccasionalFlyer <klit...@apu.eduwrote:
I modified my JavaScript like this, but this still doesn't work:
<script LANGUAGE="JavaScript">
void choiceInstitution(theForm) {
if(theForm.getElementByID.("Institution").style.vi sibility=="hidden")
{
document.theForm.getElementByID("Institution").sty le.visibility =
"visible"';
}
Even if this can work (and I don't know if it can), I think it's a bad
idea to check conditions based on the existing style of a component.
You're better off using the "checked" state of the checkbox, as you
were before, or anything else but the style of a component. I've
always felt that "style" should be write-only.
Jun 27 '08 #9
OccasionalFlyer wrote:
I modified my JavaScript like this, but this still doesn't work:
<script LANGUAGE="JavaScript">
I would consider learning how to write Valid HTML to be a
prerequisite for learning proper client-side scripting.

http://validator.w3.org/
void choiceInstitution(theForm) {
This causes a SyntaxError. choiceInstitution(theForm) would be
considered a CallExpression but it is not followed by a `;'
before the `{'.

You were looking for a decent HTML reference (say, the HTML 4.01
Specification), then a decent scripting reference (say, the Core
JavaScript 1.5+ Reference), and then

function choiceInstitution(theForm)
{
//
}

Any function that does not return a value explicitly, returns `undefined'.

See also http://jibbering.com/faq/
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jun 27 '08 #10
I'm still trying to make this work. I don't know if the code to
make the element visible works or not because I cannot make the
element invisible. Here's my approach to trying to make it invisible
to start, based on an example I found for having something happen
automatically at onLoad:
function init(){
document.getElementByID("Institution").style.displ ay = 'none';
}

window.onload=init;
Here's te element:
<TR>
<TD NOWRAP ALIGN=LEFT>
Institution
</TD>
<TD WIDTH=100% ALIGN=LEFT>
<INPUT TYPE="TEXT" ID="Institution" NAME="Institution"
VALUE="{Individuals.CS-Appl Academic.Institution}" SIZE=32
MAXLENGTH=60>
</TD>

</TR>
This approach is not working. How can I make this one element
invisible by default when the page is displayed? Thanks.

Jun 27 '08 #11
OccasionalFlyer wrote:
I'm still trying to make this work. I don't know if the code to
make the element visible works or not because I cannot make the
element invisible. Here's my approach to trying to make it invisible
to start, based on an example I found for having something happen
automatically at onLoad:
function init(){
document.getElementByID("Institution").style.displ ay = 'none';
}

window.onload=init;
Use

<body onload="init()">

instead of this line.
Here's te element:
<TR>
<TD NOWRAP ALIGN=LEFT>
Institution
</TD>
<TD WIDTH=100% ALIGN=LEFT>
<INPUT TYPE="TEXT" ID="Institution" NAME="Institution"
VALUE="{Individuals.CS-Appl Academic.Institution}" SIZE=32
MAXLENGTH=60>
</TD>

</TR>
http://validator.w3.org/
This approach is not working.
http://jibbering.com/faq/#FAQ4_43
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jun 27 '08 #12
I've been working on this and found a basic error. I copied a
fragment from a web page tutorial that had getElementByID. I found in
the error console that it should be getElementById. With that fix, I
was able to get an INPUT element with an in-line style (<INPUT
TYPE="TEXT" style="display:none"..., to begin hidden and then be shown
when I clicked a radio button. What I need, thoough, is to have the
entire line, including its "label" hidden. So I tried this:

<style type="text/css">
#divSchoolRow1 {
display:none;
}
</style>
Then, down in the HTML, I have
<div id="divSchoolRow1">
<TABLE width=100% border=0 cellpadding=0 cellspacing=2>
<TR>
<TD WIDTH=100% ALIGN=LEFT>
<INPUT TYPE="TEXT" ID="Institution" NAME="Institution"
VALUE="{Individuals.CS-Appl Academic.Institution}" SIZE=32
MAXLENGTH=60>
Institution
</TD>
</TR>
</TABLE>
</div>

Great. The little table begins hidden. (It really should be a table
row, but that's a little matter I hope.)

Unfortunately, the code that relied upon a radio button to display the
INPUT element and worked great doesn't work for a div.

<script LANGUAGE="JavaScript">
function showInstitution(choice) {
if(choice == "no")
{
document.getElementById("divSchoolRow1").style.dis play="none";
}
else
{
document.getElementById("divSchoolRow1").style.dis play = "";
}
}

</script>

<TABLE width=100% border=0 cellpadding=0 cellspacing=2>
<TR>
<TD width="100%">
<Input type="radio" name="addInstitution" value="Yes"
onClick="showInstitution('yes')">
<Input type="radio" name="addInstitution" CHECKED value="No"
onClick="showInstitution('no')">

</TD>
</TR
</TABLE>
By the way, I appreciate pointers to validators. Unfortunately, the
validator basically found every single line of my .html file invalid,
beginning with the absence of a DTD, so that didn't really help me.

Anyway, can someone tell me what I'm doing wrong? I installed
Firebug but haven't been able to get it to tell me anything. Thanks.

Ken
Jun 27 '08 #13

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

Similar topics

0
by: Mike | last post by:
Hi All, I have been struggling with this for weeks now and I just can't get my head around it. I am trying to convert this procedure to VB.NET. In particular I am having problems with the...
8
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link,...
1
by: Laurentiu | last post by:
Hi all, I've just started to decipher the world of COM programming and I would appreciate if someone can clarify this: Why do I need to access a method in a class that implements an interface...
3
by: Julia | last post by:
I need help with architecture design,please: I have a server which constantly downloading messages from the internet and store them inside a data base. the server have two administrators...
21
by: Al Christoph | last post by:
I posted this last week end in the MSDN forums. No luck there. Let's see what the experts here have to say:-)))) I have a rather convoluted project. The distributable will come in eight...
4
by: hkhellhkhell | last post by:
This is a basic overall question. Please note I am new to ASP! I am currently running IIS 5/Access 2000/Windows 2000 and have developed a web application. master/detail form, the best way...
1
by: adamchiaz | last post by:
I am trying to access progressive.com and it says that javascript is disabled and i went thru everything and all the settings are correct..it is enabled and is still not recognizing...can anybody...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.