Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #18028
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | "Leonardo Azpurua" <leonardo@exmvps.org> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Matching arbitrary pairs of elements |
| Date | Tue, 8 Jan 2013 23:11:02 -0430 |
| Organization | A noiseless patient Spider |
| Lines | 67 |
| Message-ID | <kcioj3$cip$1@dont-email.me> (permalink) |
| References | <1kwe933.qjka3b5vluq5N%real-not-anti-spam-address@apple-juice.co.uk> |
| Injection-Date | Wed, 9 Jan 2013 03:36:04 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="de2878c18c27ea00a51224844a34e6d4"; logging-data="12889"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9nPgYvbUVg76223yj+YL8BMmJzCgmceQ=" |
| X-MimeOLE | Produced By Microsoft MimeOLE V6.00.2900.5512 |
| X-RFC2646 | Format=Flowed; Original |
| X-Newsreader | Microsoft Outlook Express 6.00.2900.5512 |
| Cancel-Lock | sha1:iyl7uocF43HhLnjAJoCBaMgBiSs= |
| X-Priority | 3 |
| X-MSMail-Priority | Normal |
| Xref | csiph.com comp.lang.javascript:18028 |
Show key headers only | View raw
"D.M. Procida" <real-not-anti-spam-address@apple-juice.co.uk> escribió en el
mensaje
news:1kwe933.qjka3b5vluq5N%real-not-anti-spam-address@apple-juice.co.uk...
>I am trying to create a widget that when a certain option in a <select>
> is chosen, a previously-hidden input field is shown.
>
> So far I have managed to come up with http://jsfiddle.net/j2xYs/ - which
> works, for one pair of select/input elements.
>
> Now in my interface there will be an arbitrary number of these pairs,
> with matching numbered ids.
>
> What I'd like to do is amend my JS so that if <select id="[number]"> is
> changed to "show", then <input id="[number]"> will be shown, whatever
> [number] is.
>
> I'm sure this must be possible, but this is the first time I've tried to
> do something in JS so I am not really sure where to start.
>
> Thanks for any suggestions or advice,
>
> Daniele
Hi,
You seem to be using jQuery and I don't have the faintest idea of how that
works.
If I had to solve your problem, I would probably write a class (function) to
handle it.
Not sure that it would work, since I am also a newcomer to Web development,
but it's likely that this is the way:
function widgetPair(selWidget, textWidget)
{
this.sel = selWidget;
this.txt = textWidget;
this.sel.style.display = "block";
this.txt.style.display = "none";
this.sel.addEventListener("change", this.showHideText, false);
}
widgetPair.prototype.showHideText = function () {
if (this.sel.value = "SHOW")
{
this.txt.style.display = "block";
}
else {
this.txt.style.display = "none";
}
};
Then, if you have several pairs like this, you can write:
p1 = new widgetPair(forms[0].getElementByName("select1"),
forms[0].getElementByName("text12"));
p2 = new widgetPair(forms[0].getElementByName("select5"),
forms[1].getElementByName("textNoNumber"));
and that would be all... perhaps.
--
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Matching arbitrary pairs of elements real-not-anti-spam-address@apple-juice.co.uk (D.M. Procida) - 2013-01-08 19:41 +0000
Re: Matching arbitrary pairs of elements Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-09 00:36 +0100
Re: Matching arbitrary pairs of elements real-not-anti-spam-address@apple-juice.co.uk (D.M. Procida) - 2013-01-09 11:46 +0000
Re: Matching arbitrary pairs of elements Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-09 18:24 +0100
Re: Matching arbitrary pairs of elements John G Harris <niam@jghnorth.org.invalid> - 2013-01-09 16:34 +0000
Re: Matching arbitrary pairs of elements "Leonardo Azpurua" <leonardo@exmvps.org> - 2013-01-08 23:11 -0430
Re: Matching arbitrary pairs of elements Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-16 12:49 +0100
Re: Matching arbitrary pairs of elements Tim Streater <timstreater@greenbee.net> - 2013-01-16 12:47 +0000
Re: Matching arbitrary pairs of elements Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-16 14:27 +0100
Re: Matching arbitrary pairs of elements Tim Streater <timstreater@greenbee.net> - 2013-01-16 13:52 +0000
Re: Matching arbitrary pairs of elements Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-16 18:48 +0100
Re: Matching arbitrary pairs of elements Tim Streater <timstreater@greenbee.net> - 2013-01-16 17:58 +0000
Re: Matching arbitrary pairs of elements John G Harris <niam@jghnorth.org.invalid> - 2013-01-17 14:30 +0000
Re: Matching arbitrary pairs of elements Jeff North <jnorthau@yahoo.com.au> - 2013-01-10 13:11 +1100
Re: Matching arbitrary pairs of elements real-not-anti-spam-address@apple-juice.co.uk (D.M. Procida) - 2013-01-11 10:32 +0000
Re: Matching arbitrary pairs of elements RobG <rgqld@iinet.net.au> - 2013-01-13 22:36 -0800
csiph-web