473,594 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make a method universal

I have the following code which I made work for one item on my page,
now I've got more items and while it still works it takes affect on the
top item not the one that it should. What the code is doing is making a
text box visible and changing the value of something else.

I know what the problem is, and I know that it has to be made universal
to fix it, I just don't know how to do that. When I call the method I
have:
onchange="colou rCheck(this.sel ectedIndex)"
as I need the value of the drop down box.

The method is:

function colourCheck(myF orm){
if (myForm == 5){
document.getEle mentById('os1') .style.display = "block";
document.getEle mentById('on1') .value = "Other";
}
else {
document.getEle mentById('os1') .style.display = "none";
}
}

Any help very much appreciated!

Thank you!

Apr 10 '06 #1
6 1004
Flic said on 11/04/2006 9:38 AM AEST:
I have the following code which I made work for one item on my page,
now I've got more items and while it still works it takes affect on the
top item not the one that it should. What the code is doing is making a
text box visible and changing the value of something else.
By 'text box' do you mean an input element of type text? Or is it a div
or span with some text?

I know what the problem is, and I know that it has to be made universal
to fix it, I just don't know how to do that. When I call the method I
have:
onchange="colou rCheck(this.sel ectedIndex)"
as I need the value of the drop down box.

The method is:

function colourCheck(myF orm){
if (myForm == 5){
document.getEle mentById('os1') .style.display = "block";


Unless you specifically want 'block', it is better to return the display
attribute to '' (empty string) to allow it to return to the default or
whatever it has been set to by CSS or inheritance.

document.getEle mentById('os1') .style.display = "";
Search the archives for 'display block none'.

Setting an input to display: block is likely not appropriate - the
default CSS 2 display property for an input element is inline-block:

<URL:http://www.w3.org/TR/CSS21/sample.html>
Not all browsers might implement that, so use ''.
[...]

--
Rob
Group FAQ: <URL:http://www.jibbering.c om/FAQ>
Apr 11 '06 #2

RobG wrote:
Flic said on 11/04/2006 9:38 AM AEST:
I have the following code which I made work for one item on my page,
now I've got more items and while it still works it takes affect on the
top item not the one that it should. What the code is doing is making a
text box visible and changing the value of something else.


By 'text box' do you mean an input element of type text? Or is it a div
or span with some text?


Sorry I wasn't very clear, I mean an input element of type text.
I know what the problem is, and I know that it has to be made universal
to fix it, I just don't know how to do that. When I call the method I
have:
onchange="colou rCheck(this.sel ectedIndex)"
as I need the value of the drop down box.

The method is:

function colourCheck(myF orm){
if (myForm == 5){
document.getEle mentById('os1') .style.display = "block";


Unless you specifically want 'block', it is better to return the display
attribute to '' (empty string) to allow it to return to the default or
whatever it has been set to by CSS or inheritance.

document.getEle mentById('os1') .style.display = "";
Search the archives for 'display block none'.

Setting an input to display: block is likely not appropriate - the
default CSS 2 display property for an input element is inline-block:

<URL:http://www.w3.org/TR/CSS21/sample.html>
Not all browsers might implement that, so use ''.


To be honest, I hadn't even thought of using that, changed now :-)

I realised that to get what I want I would probably need the id similar
to my this.SelectedIn dex, but I wouldn't know how to do this as they
are only related to the drop down box with the onChange by being on the
same form.

Apr 11 '06 #3
Flic said on 11/04/2006 10:21 AM AEST:
RobG wrote:

[...]
Unless you specifically want 'block', it is better to return the display
attribute to '' (empty string) to allow it to return to the default or
whatever it has been set to by CSS or inheritance.

document.getEle mentById('os1') .style.display = "";
Search the archives for 'display block none'.

Setting an input to display: block is likely not appropriate - the
default CSS 2 display property for an input element is inline-block:

<URL:http://www.w3.org/TR/CSS21/sample.html>
Not all browsers might implement that, so use ''.

To be honest, I hadn't even thought of using that, changed now :-)

I realised that to get what I want I would probably need the id similar
to my this.SelectedIn dex, but I wouldn't know how to do this as they
are only related to the drop down box with the onChange by being on the
same form.


An option has a value and text, you can use both if you like, e.g. use
the value to determine which input to hide and the text to display
something to the user.

You can also use the form's elements collection rather than
getElementById. I have no idea what your form looks like or what you
are doing, but the following example may give you some ideas:
<script type="text/javascript">

function colourCheck(sel )
{
var form = sel.form;
if ( '5' == sel[sel.selectedInd ex].value ){
form.os1.style. display = "";
form.on1.value = "Other";
} else {
form.os1.style. display = "none";
}
}
</script>

<form action="">
<select onchange="colou rCheck(this);">
<option value="0">Selec t a value</option>
<option value="2">two</option>
<option value="5">five</option>
</select>
<input type="text" name="os1" value="os1">
<input type="text" name="on1" value="on1">
</form>

--
Rob
Group FAQ: <URL:http://www.jibbering.c om/FAQ>
Apr 11 '06 #4

RobG wrote:
Flic said on 11/04/2006 10:21 AM AEST:
RobG wrote:

[...]
Unless you specifically want 'block', it is better to return the display
attribute to '' (empty string) to allow it to return to the default or
whatever it has been set to by CSS or inheritance.

document.getEle mentById('os1') .style.display = "";
Search the archives for 'display block none'.

Setting an input to display: block is likely not appropriate - the
default CSS 2 display property for an input element is inline-block:

<URL:http://www.w3.org/TR/CSS21/sample.html>
Not all browsers might implement that, so use ''.

To be honest, I hadn't even thought of using that, changed now :-)

I realised that to get what I want I would probably need the id similar
to my this.SelectedIn dex, but I wouldn't know how to do this as they
are only related to the drop down box with the onChange by being on the
same form.


An option has a value and text, you can use both if you like, e.g. use
the value to determine which input to hide and the text to display
something to the user.

You can also use the form's elements collection rather than
getElementById. I have no idea what your form looks like or what you
are doing, but the following example may give you some ideas:
<script type="text/javascript">

function colourCheck(sel )
{
var form = sel.form;
if ( '5' == sel[sel.selectedInd ex].value ){
form.os1.style. display = "";
form.on1.value = "Other";
} else {
form.os1.style. display = "none";
}
}
</script>

<form action="">
<select onchange="colou rCheck(this);">
<option value="0">Selec t a value</option>
<option value="2">two</option>
<option value="5">five</option>
</select>
<input type="text" name="os1" value="os1">
<input type="text" name="on1" value="on1">
</form>

--
Rob
Group FAQ: <URL:http://www.jibbering.c om/FAQ>


The code did indeed give me ideas and I modified it to fit my code.
While it works for the first item it doesn't work for the ones after,
coming up as 'value' is null or not an object.

I've uploaded my code so you can see what I am trying to do, it can be
found at:
http://airraid.mancubus.net/flic/exp...necklaces.html
i didn't upload the pictures for the page hence them not displaying.

Apr 11 '06 #5
Flic wrote:
[snip ... old quotes]

The code did indeed give me ideas and I modified it to fit my code.
While it works for the first item it doesn't work for the ones after,
coming up as 'value' is null or not an object.

I've uploaded my code so you can see what I am trying to do, it can be
found at:
http://airraid.mancubus.net/flic/exp...necklaces.html
i didn't upload the pictures for the page hence them not displaying.

In your HTML you have 5 Forms.
Though they look the same, they aren't

The first one has (correct):
<select name="os0" onchange="colou rCheck(this)">

The other 4 has (incorrect):
<select name="os0" onchange="colou rCheck(this.sel ectedIndex)">

Make them the same and the script should basically work.

Apr 11 '06 #6

[on] wrote:
Flic wrote:
[snip ... old quotes]

The code did indeed give me ideas and I modified it to fit my code.
While it works for the first item it doesn't work for the ones after,
coming up as 'value' is null or not an object.

I've uploaded my code so you can see what I am trying to do, it can be
found at:
http://airraid.mancubus.net/flic/exp...necklaces.html
i didn't upload the pictures for the page hence them not displaying.

In your HTML you have 5 Forms.
Though they look the same, they aren't

The first one has (correct):
<select name="os0" onchange="colou rCheck(this)">

The other 4 has (incorrect):
<select name="os0" onchange="colou rCheck(this.sel ectedIndex)">

Make them the same and the script should basically work.


Thank you for pointing this out. I realised this earlier today along
with something else in the other four that I had to change, but as
quite often happens I couldn't get to the computer to fix it at the
time. It was a silly mistake I know!

Everything working now :-D

Apr 11 '06 #7

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

Similar topics

28
2337
by: The Eternal Squire | last post by:
PEP: 336 Title: Make None Callable Version: $Revision: 1.1 $ Last-Modified: $Date: 2004/11/03 16:58:30 $ Author: Andrew McClelland Status: Draft Type: Standards Track Content-Type: text/plain Created: 28-Oct-2004 Post-History:
0
1870
by: Nick Kew | last post by:
Rationale ========= Many applications today benefit from an SGML and/or XML Entity Catalogue to dereference entities referenced by a Public Identifier. For a validating SGML parser this is an absolute requirement. For any SGML or XML parser it serves to enable entities such as DTDs and modules to be resolved locally. Hitherto, different packages and applications have distributed entity
8
5050
by: Brett | last post by:
Sorry for all the post on conversion from VB.NET to C#. Just can't figure some of these out. getElementsByTagName method is fine in VB but get this error in C#: Object does not contain a signature for getElementsByTagName Intellisense in both langauges is the same. Private WithEvents IE_Inst As New SHDocVw.InternetExplorer
44
2743
by: gregory.petrosyan | last post by:
Hello everybody! I have little problem: class A: def __init__(self, n): self.data = n def f(self, x = ????) print x All I want is to make self.data the default argument for self.f(). (I
5
2648
by: EP | last post by:
This inquiry may either turn out to be about the suitability of the SHA-1 (160 bit digest) for file identification, the sha function in Python ... or about some error in my script. Any insight appreciated in advance. I am trying to reduce duplicate files in storage at home - I have a large number files (e.g. MP3s) which have been stored on disk multiple times under different names or on different paths. The using applications will...
0
1172
by: frostbb | last post by:
1st I know about the new DataGridView control. For various reasons we need the IsSelected( ) method of the old DataGrid to work in the upgraded apps. I have a small test app that illustrates the problem. The following code works great in C# Net 1.0 & Net 1.1 apps ... doesn't work for Net 2.0 apps. Cannot get pDg.IsSelected(i) to toggle to 'true' for 'highlighted' rows in a DataGrid control.
2
4816
by: Jeffrey Walton | last post by:
Hi All, BMP Strings are a subset of Universal Strings.The BMP string uses approximately 65,000 code points from Universal String encoding. BMP Strings: ISO/IEC 10646, 2-octet canonical form, Universal String: ISO/ IEC 10646, 4-octet canonical form. An excellent discussion occured with respect to BMP Strings and .Net (see http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/f18fcb62156a1a0c/)....
3
6113
by: raylopez99 | last post by:
I suspect the answer to this question is that it's impossible, but how do I make the below code work, at the point where it breaks (marked below). See error CS0411 This is the complete code. Copy and paste it into VS2008 for a Windows Forms application. With some effort I can do the job with a user defined function, but my question is whether I can do it using the built in library function "Array.Find" and a predicate that takes...
0
7877
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8374
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
6661
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
5739
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
5411
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3867
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2389
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
1
1482
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1216
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.