473,624 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thanks to Michael Winter, and another (related) question :-)

Mike,

Your code on the dynamic input checking was excellent and very well
explained. (The only thing I had to do was change the test for text input to
be "1 > len of text", instead or "0 > length of text", and add a line to
store the result for use on the server). Thank you very much!

I have a related issue that you might have some ideas on. In some cases, I
have a select box where one of the selections may require an additional
input field to appear next to it. For example,

Pseudo code:

<select id='Length'>
None
Fixed At 12
Variable Length
</select>

If the "Variable" option is selected, I want an input control to appear next
to the select box so that the actual value for length can be entered.
Otherwise, it's not needed and I want to hide it.

The placement is working fine (I added a "NewLine" variable to the control
definition on the server side to control location). What I need to resolve
is how to make a control appear and disappear, depending on the selected
index of it's "parent" control. My implementation does not let me easily
make a trip back to the server when the option is changed.

Any ideas?

TIA

Calan
Jul 23 '05 #1
7 1385
Also, the " required" attribute for the control that gets hidden and
displayed also has to be updated, so that it is not checked with "
isRequired" if it isn't visible. The current isRequired function that you
provided is looking to see if a 'required' class exists. This is currently
set at the server, and the class will have to be added/removed dynamically,
or a different method used I think.

Calan

"Calan" <no**@nospam.co m> wrote in message
news:10******** *****@corp.supe rnews.com...
Mike,

Your code on the dynamic input checking was excellent and very well
explained. (The only thing I had to do was change the test for text input to be "1 > len of text", instead or "0 > length of text", and add a line to
store the result for use on the server). Thank you very much!

I have a related issue that you might have some ideas on. In some cases, I
have a select box where one of the selections may require an additional
input field to appear next to it. For example,

Pseudo code:

<select id='Length'>
None
Fixed At 12
Variable Length
</select>

If the "Variable" option is selected, I want an input control to appear next to the select box so that the actual value for length can be entered.
Otherwise, it's not needed and I want to hide it.

The placement is working fine (I added a "NewLine" variable to the control
definition on the server side to control location). What I need to resolve
is how to make a control appear and disappear, depending on the selected
index of it's "parent" control. My implementation does not let me easily
make a trip back to the server when the option is changed.

Any ideas?

TIA

Calan

Jul 23 '05 #2
On Wed, 7 Apr 2004 14:08:43 -0500, Calan <no**@nospam.co m> wrote:

[snip]
I have a related issue that you might have some ideas on. In some cases,
I have a select box where one of the selections may require an
additional input field to appear next to it. For example,

Pseudo code:

<select id='Length'>
None
Fixed At 12
Variable Length
</select>

If the "Variable" option is selected, I want an input control to appear
next to the select box so that the actual value for length can be
entered. Otherwise, it's not needed and I want to hide it.

The placement is working fine (I added a "NewLine" variable to the
control definition on the server side to control location). What I need
to resolve is how to make a control appear and disappear, depending on
the selected index of it's "parent" control. My implementation does not
let me easily make a trip back to the server when the option is changed.
The best approach would be to keep the control visible and enabled
initially, and hide and disable it when the page loads. This way, users
without JavaScript will still be able to use the page properly, but you'll
need to add server-side checks to make sure someone doesn't try to use it
when they shouldn't.

/* Assumes that "Variable Length" input is visible by default */
function setVisibility( ref, visible ) {
if( ref && ref.style ) {
ref.style.visib ility = visible ? '' : 'hidden';
}
}

/* Assumes "Variable Length" option is at index 2 */
function enableLength( r ) {
var f = r.form, i = r.selectedIndex , vL = f.elements[ 'vLength' ];

setVisibility( vL, 2 == i );
/* In addition to trying to set the visibility, you might want
to disable the control in case the browser doesn't support
the inline style object */
vL.disabled = ( 2 != i );
}

<form ...>
<select name="length" onchange="enabl eLength(this)">
<!-- options -->
</select>
<input name="vLength" type="text">
</form>

On Wed, 7 Apr 2004 14:23:08 -0500, Calan <no**@nospam.co m> wrote:
Also, the "required" attribute for the control that gets hidden and
displayed also has to be updated, so that it is not checked with
"isRequired " if it isn't visible. The current isRequired function that
you provided is looking to see if a 'required' class exists. This is
currently set at the server, and the class will have to be added/removed
dynamically, or a different method used I think.


I think a different method would be more appropriate. In the validation
function, use (assuming the HTML above, 'form' refers to the FORM, and
"Variable Length" is at index 2)

if( 2 == form.elements[ 'length' ].selectedIndex ) {
var length = +form.elements[ 'vLength' ].value;

if( isNaN( length ) || ( 1 > length )) {
/* The value is either not a number,
or it is a number less than zero */
}
}

Hope that helps,
Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #3
On Thu, 08 Apr 2004 14:57:58 GMT, Michael Winter
<M.******@bluey onder.co.invali d> wrote:

[snip]
<form ...>
<select name="length" onchange="enabl eLength(this)">
<!-- options -->
</select>
<input name="vLength" type="text">
</form>


[snip]

Forgot to mention that after the closing form tag, you should call
enableLength():

<script type="text/javascript>
enableLength( document.forms[ 'formName' ].elements[ 'length' ]);
</script>

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #4
Thanks Mike... this is soaking in (slowly), but I'm still not seeing a way
to make it work for ANY control that is somehow designated as a "child" of
another control.

I'm thinking I can add an ASP variable called 'ControlParent" (which comes
from the database of control definitions). This variable will contain the
name of the control that it is dependent on, if there is one. But I also
need to set the parent's index that will trigger the visibility.

I'm working through your example below for a known control (Length), but
still not quite grasping how to make it work for any control, as defined in
the ASP script.

(Maybe dynamically create the JS with response.write, inserting control
names where appropriate? Would this be easier than a generic JS function
that can handle any control that has some property that identifies it as
having a dependency?)

Once again thanks for your help...

Calan

"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:op******** ******@news-text.blueyonder .co.uk...
On Thu, 08 Apr 2004 14:57:58 GMT, Michael Winter
<M.******@bluey onder.co.invali d> wrote:

[snip]
<form ...>
<select name="length" onchange="enabl eLength(this)">
<!-- options -->
</select>
<input name="vLength" type="text">
</form>


[snip]

Forgot to mention that after the closing form tag, you should call
enableLength():

<script type="text/javascript>
enableLength( document.forms[ 'formName' ].elements[ 'length' ]);
</script>

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

Jul 23 '05 #5
Mike,

I've got everything working, except sometimes the child control may not be
an input box. Here is the JS validation after it has been served:

*************** *******

<script type="text/javascript">
function checkForm(form)
{
var c = form.elements, e, t;

for( var i = 0, n = c.length; i < n; ++i )
{
t = ( e = c[ i ]).type;

if(( 'select-one' == t ) && ( e.selectedIndex == 0 ) &&
isRequired( e ))
{
alert("Please select an option for " + e.title + ".");
form.validated. value="false";
return false;
}
else if(( 'text' == t ) && ( e.value.length < 1 ) && isRequired( e ))
{
alert("Please enter a value for " + e.title + ".");
form.validated. value="false";
return false;
}
else if(( 'textarea' == t ) && ( e.value.length < 1 ) && isRequired( e ))
{
alert("Please enter a value for " + e.title + ".");
form.validated. value="false";
return false;
}

// etc.

else if((e.id=='Dome Light')&&(e.sel ectedIndex>=2)) {
var cValue = form.elements['DomeLightFB'].value;
if(isNaN(cValue )||(cValue<1)){

alert('Please enter a value for Dome Light Location.');
form.validated. value='false';
return false;}}

}
form.validated. value="true";
return true;
}

function isRequired( e )
{
return( -1 != e.className.ind exOf( 'required' ));
}

function setVisibility( ref, visible ) {
if( ref && ref.style ) {
ref.style.visib ility = visible ? '' : 'hidden';
}
}

function enableChild( r,child,trigger ) {
var f = r.form, i = r.selectedIndex , childControl = f.elements[ child ];

setVisibility( childControl, i >= trigger);
/* disable the control in case the browser doesn't support
the inline style object */
childControl.di sabled = ( i < trigger);
}

//-->
</script>

*************** *******

The lines in question are:

else if((e.id=='Dome Light')&&(e.sel ectedIndex>=2)) {
var cValue = form.elements['DomeLightFB'].value;
if(isNaN(cValue )||(cValue<1)){

alert('Please enter a value for Dome Light Location.');
form.validated. value='false';
return false;}}

'DomeLight' is a select that has a child select called 'DomeLightFB' when
the selected index is >=2.

If 'DomeLightFB' is an input control, this works fine. But as a selectbox,
it doesn't. I need to check if the value is < 1 (for children that are input
controls), and selectedIndex ==0 (for children that are selects).

I tried adding an OR to the value test line, but it doesn't want to work for
some reason:

if( isNaN(cValue)|| (cValue<1) || (form.elements['DomeLightFB'].selectedIndex
== 0)){

Any ideas?

Thanks once again for all the invaluable help!

Calan





"Calan" <no**@nospam.co m> wrote in message
news:10******** *****@corp.supe rnews.com...
Thanks Mike... this is soaking in (slowly), but I'm still not seeing a way to make it work for ANY control that is somehow designated as a "child" of
another control.

I'm thinking I can add an ASP variable called 'ControlParent" (which comes
from the database of control definitions). This variable will contain the
name of the control that it is dependent on, if there is one. But I also
need to set the parent's index that will trigger the visibility.

I'm working through your example below for a known control (Length), but
still not quite grasping how to make it work for any control, as defined in the ASP script.

(Maybe dynamically create the JS with response.write, inserting control
names where appropriate? Would this be easier than a generic JS function
that can handle any control that has some property that identifies it as
having a dependency?)

Once again thanks for your help...

Calan

"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:op******** ******@news-text.blueyonder .co.uk...
On Thu, 08 Apr 2004 14:57:58 GMT, Michael Winter
<M.******@bluey onder.co.invali d> wrote:

[snip]
<form ...>
<select name="length" onchange="enabl eLength(this)">
<!-- options -->
</select>
<input name="vLength" type="text">
</form>


[snip]

Forgot to mention that after the closing form tag, you should call
enableLength():

<script type="text/javascript>
enableLength( document.forms[ 'formName' ].elements[ 'length' ]);
</script>

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)


Jul 23 '05 #6
On Thu, 8 Apr 2004 15:57:25 -0500, Calan <no**@nospam.co m> wrote:

[fixed top-post]
"Calan" <no**@nospam.co m> wrote in message
news:10******** *****@corp.supe rnews.com...
Thanks Mike... this is soaking in (slowly), but I'm still not seeing
a way to make it work for ANY control that is somehow designated as a
"child" of another control.
You never mentioned anything about creating something generic. I thought
the relationship between the two controls was a one-off.

Without knowing the details of the page intimately, it would be
complicated to produce a truely generalised validation function able to
determine the presence of children, how those children are activated, and
how to react to different control types. You'd be sending a lot of data to
the user, and the server would be generating quite a bit of JavaScript. It
certainly would be possible, but it would require quite a shift from the
code you have at the moment.
I'm thinking I can add an ASP variable called 'ControlParent" (which
comes from the database of control definitions). This variable will
contain the name of the control that it is dependent on, if there is
one. But I also need to set the parent's index that will trigger the
visibility.

If I were to generalise the process, I'd use a JavaScript object (used as
a hash table) to associate properties with a form control. Those
properties would contain the parent, whether the control was required,
what condition enabled the child, and what makes the control valid[1].

In the long run, I'd probably be tempted to leave validation to the server.

[snipped my post and validation code]
The lines in question are:

else if((e.id=='Dome Light')&&(e.sel ectedIndex>=2)) {
var cValue = form.elements['DomeLightFB'].value;
if(isNaN(cValue )||(cValue<1)){

alert('Please enter a value for Dome Light Location.');
form.validated. value='false';
return false;}}
First of all, I would place validation of exceptional elements first,
otherwise they might be handled by the general tests based on type.
'DomeLight' is a select that has a child select called 'DomeLightFB'
when the selected index is >=2.

If 'DomeLightFB' is an input control, this works fine. But as a
selectbox, it doesn't. I need to check if the value is < 1 (for children
that are input controls), and selectedIndex ==0 (for children that are
selects).
Are you implying that DomeLightFB might be generated as a different
control type under certain circumstances?
I tried adding an OR to the value test line, but it doesn't want to work
for some reason:

if( isNaN(cValue)|| (cValue<1) ||
(form.elements['DomeLightFB'].selectedIndex
== 0)){


Assuming that the answer to the question above is "Yes", I'd split the
validation based on type, again. However, as the validation function
checked every control in the form, DomeLightFB would be checked later
anyway, and in the way to seem to want, too.

if(( 'DomeLight' == e.id ) && ( 2 <= e.selectedIndex )) {
var dLFB = form.elements[ 'DomeLightFB' ], dLFBt = dLFB.type;

if(( 'select-one' == dLFBt ) && ( 0 == dLFB.selectedIn dex )) {
// invalid
} else if( 'text' == dLFBt ) {
var dLFBv = +dLFB.value;

if( isNaN( dLFBv ) || ( 1 > dLFBv )) {
// invalid
}
}

/* Other exceptional tests */

} else if(( 'select-one' == t ) /* && etc */ ) {
} else if(( 'text' == t ) /* && etc */ ) {
} else if(( 'textarea' == t ) /* && etc */ ) {
}

Mike

Sorry for the delayed reply. I've been away for the Easter weekend.

[1] That may not be an exhaustive list.

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #7
<snip>

Thanks Mike....
'DomeLight' is a select that has a child select called 'DomeLightFB'
when the selected index is >=2.

If 'DomeLightFB' is an input control, this works fine. But as a
selectbox, it doesn't. I need to check if the value is < 1 (for children
that are input controls), and selectedIndex ==0 (for children that are
selects).


Are you implying that DomeLightFB might be generated as a different
control type under certain circumstances?


The JS validation I'm considering would be a generic function, to a degree.
In the example of the Domelight, that JS was written at the server,
substituting the control names from a database. I was hoping for a generic
chunk of code that would work on either an input or select control, with
only the control names being written in.

The more I think about it, the more I'm inclined to agree that I need to do
as much validation at the server as possible, mostly just because I'm not
familiar enough with JS to make it worthwhile. (We may actually be looking
at bringing a consultant in for a few days of JS work for client-side
validation that can't be handled easily at the server).

Checking that required fields have been filled in with *something* is fairly
easy to do generically, (thanks to your help :-) ). My problem is that a
lot of select lists will need to be populated differently based on other
inputs directly before them, and some input controls shouldn't even be shown
at all. Using a JS library for dependent selects is easy enough (I've found
several nice ones on the net), but making them work generically with control
names and lists that are loaded at the server from a database is getting
really complex really fast.

Thanks again for all the help on this. I may continue to struggle through
with it a while before just biting the bullet and hiring someone for a few
days.

Want some work?

:-)

Calan

AxMaster Guitar Software
www.jcsautomation.com
www.jcsautomation.com/music.asp
Music software and web design/hosting

"Reality exists only in the minds of the extremely deranged"
Jul 23 '05 #8

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

Similar topics

7
50942
by: Tim Gaunt | last post by:
Hi, I'm hoping that someone will be able to help me with this one, I'm developing an application which basically inserts a load of data into the database ready for validation at a later date, I wrote an INSERT statement that works fine however today I decided that as part of the application upgrade it should be return the record ID so I wrote the following which I admit is a little messy at places but it works. However when I added all...
1
1360
by: David Graham | last post by:
Thanks to Michael Winter and Lasse Reichstein Nielsen, I do believe that I now understand. I have printed out this thread for future reference as I find I understand today but next week is a different story. many thanks - I guess many in this ng. benefit from your help David
28
2280
by: John Bailo | last post by:
Funny, how Bill Gate uses the Deutsches Bank and Barron's to defraud people and try to wreck his competitors ( he can't ). For example, http://www.reuters.com/financeNewsArticle.jhtml?type=hotStocksNews&storyID=4262964 Oh, but see how Barron's and MS are in bed together...
12
4031
by: Brian | last post by:
I want to use regxp to check that a form input contains at least 1 non-space charcter. I'd like to only run this if the browser supports it. For DOM stuff, I'd use if (documentGetElementById) {} Is there an object/feature detection I can use to check for regxp string manipulation support? --
4
1459
by: Richard Salin | last post by:
Hi I just wondered how I can refer to the following two textboxes in this form: <FORM action="FormWrite.php" method="post" name="submitForm"> <INPUT NAME="inputValues" SIZE=40> <INPUT NAME="inputValues" SIZE=40> <INPUT TYPE="button" onclick="javacscript:sendForm();" VALUE="Lähetä"> </FORM>
4
4683
by: Paul | last post by:
I have a basic form. On it are two sub forms. The top sub form has a list of records. When a user clicks on a new row within the top sub form. I want the RecordSource of the bottom sub form to change according to some data in the row of the top sub form. Main Form Name: Form1 Top Sub Form Name: frmT1_Datasheet Bottom Sub Form Name: frmT2_Datasheet The code in frmT1_Datasheet is:
3
1301
by: Mark Denardo | last post by:
Hi I have an app that has a number of textboxes (richtextboxes to be exact) that get created dynamically and I add a few at a time to panel controls (so I can flip a group in and out when I want). So the textbox objects get added to the panel object like so: panelObj.Controls.Add(textboxObj) And then I store the panel Objects in a linked list so I can sort through them later.
0
1088
by: kesk | last post by:
Hi, I am a learner in vb.net who is designing a database project. I dont have formal vb.net training, i learned from database books only, to the most extent its good. I have seen on dbl-clicking a datarow value, another form opens with the related record details. I would like to emulate this behaviour in my project, but i dont know the basics of doing this. Whatever examples i have doesnt explain.
0
1438
by: Carl Friedrich Bolz | last post by:
===================================================================== PyPy Leysin Winter Sports Sprint (8-14th January 2007) ===================================================================== ... image:: http://www.ermina.ch/002.JPG The next PyPy sprint will be in Leysin, Switzerland, for the fourth time. This sprint will be the final public sprint of our EU-funded period, and a kick-off for the final work...
0
8233
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
8619
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
7158
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
6108
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
5561
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
4078
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...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
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
1482
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.