473,800 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.formna me wildcard?

JV
I thought I once saw somewhere that a global variable, "xyz" for
example, could be declared and used so that instead of using
"document.formn ame.elementname .value" one could use
"xyz.elementnam e.value" or use "xyz" in place of "document.formn ame"
anytime a reference to a form element was made.

Is this actually true or not? I'm going crazy trying to recall
something that might not even exist!

Thanks.

JV

Dec 8 '06 #1
4 2701
ASM
JV a écrit :
I thought I once saw somewhere that a global variable, "xyz" for
example, could be declared and used so that instead of using
"document.formn ame.elementname .value" one could use
"xyz.elementnam e.value" or use "xyz" in place of "document.formn ame"
anytime a reference to a form element was made.

Is this actually true or not? I'm going crazy trying to recall
something that might not even exist!
function verif() {
var f = document.forms['myForm']; // shortcut for form named 'myForm'
for(var i=0; i<f.length; i++)
if(f[i].type == 'text' && f[i].value=='') {
alert('field "'+f[i].name+'" not filled');
f[i].focus();
f[i].select();
return false;
}
return true;
}
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 8 '06 #2
ASM wrote on 09 dec 2006 in comp.lang.javas cript:
JV a écrit :
>I thought I once saw somewhere that a global variable, "xyz" for
example, could be declared and used so that instead of using
"document.form name.elementnam e.value" one could use
"xyz.elementna me.value" or use "xyz" in place of "document.formn ame"
anytime a reference to a form element was made.
that shortcut is browser specific, I heard.
>Is this actually true or not? I'm going crazy trying to recall
something that might not even exist!

function verif() {
var f = document.forms['myForm']; // shortcut for form named 'myForm'
shouldn't that be for completeness:

var f = document.forms['myForm'].elements
[..]
=============== ==========

Stipulating that you use the return false/true from an onsubmit='..',
"this" is a good alternative, making the function universal:

<form onsubmit='verif (this)' ...
....
function verif(fm) {
var f = fm.elements
for(var i=0; i<f.length; i++)
if(f[i].type == 'text' && f[i].value=='') {
alert('field "'+f[i].name+'" not filled');
f[i].focus();
f[i].select();
return false;
}
return true;
}

=============== ==========

What about this:

function verif(fm) {
var f = fm.elements;
i=0;
while (i<f.length && (f[i].type!='text' || f[i].value!=''))
i++;
if (i==f.length) return true;
alert('field "'+f[i].name+'" not filled');
f[i].focus();
f[i].select();
return false;
}


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 8 '06 #3
ASM
Evertjan. a écrit :
ASM wrote on 09 dec 2006 in comp.lang.javas cript:
>var f = document.forms['myForm']; // shortcut for form named 'myForm'

shouldn't that be for completeness:

var f = document.forms['myForm'].elements
yeap, probably, but ...
>[..]
Stipulating that you use the return false/true from an onsubmit='..',
clever you are that finding :-)
"this" is a good alternative, making the function universal:
each thing at its time

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 9 '06 #4
ASM wrote on 09 dec 2006 in comp.lang.javas cript:
>Stipulating that you use the return false/true from an onsubmit='..',

clever you are that finding :-)
me try harder! [avis]
>"this" is a good alternative, making the function universal:

each thing at its time
I liked the triviality of the sentence at the time. ;-}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 9 '06 #5

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

Similar topics

0
3020
by: DaveS | last post by:
Hello, I'm using Oracle 9.2 and would like to automatically save a copy of each deleted record in XML format to another database table. There would be one XML record for each deleted record. I'd like to store the XML record in a CLOB. I've created a table and added a trigger to capture the delete event but I'm not sure how to create the XML document. Each deleted record is comprised of a single row from a parent table and multiple...
2
6156
by: Miles Davenport | last post by:
My Javascript is rather rusty :( ... and I need to do change some form values, in the folowing way: (1). I have the following a href (wrapped in PHP), which calls processForm. ==== <input type="hidden" name="myHiddenValue"> href="javascript:void(0)" onClick="processForm(\'' . $form_name
6
1880
by: Mark Anderson | last post by:
I have code to develop result page links (like a search engine) for some results being passed from a database where I've no server-sdide acces - thus JS. The code is below and works fine except the function in the onClick event of the link being written on screen fails indicating 'theForm' as being passed through is 'not defined'. The form is being passed as "document.resultAdd" and can be checked as arriving in my function. So what...
3
4678
by: Don | last post by:
I can successfully force submission of a <form> using "document.formname.submit()". But, the submission doesn't appear to occur when used with Netscape. Anybody know why this is happening, and what I can do to get around this? Thanks, Don -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World!
6
3694
by: skubik | last post by:
Hi everyone. I'm attempting to write a Javascript that will create a form within a brand-new document in a specific frame of a frameset. The problem is that I can create the form and input element using createElement(), but when I go to append the form element into the new document, the script halts and I get the following error in my Javascript Console (Firefox 1.0): __tmp_newDoc.body has no properties.
7
2954
by: michael | last post by:
apologies in advance, as not only am i new to learning how to code javascript properly, i'm new to the groups posting thing... i am developing in firefox 1.0+, but will be working in an msie 6.0+ produciton environment ( not my choice, but when is it ever? ). the desired output is that when the end-user selects two radio buttons, one from each 'group', the form / page will open an alert window displaying the values of the radio buttons...
1
1480
by: mike | last post by:
I have some code on a page that will enable/disable a text box if a checkbox has been checked/unchecked and it seems to be working fine unless there is only one checkbox and one text box. Here is the javascript: function EnableCustLoyaltyNotes(x,y) { if (document.frmCustLoyalty.VoidLineID.checked || document.frmCustLoyalty.UnVoidLineID.checked)
7
2737
by: vinsim24 | last post by:
Hi all, the code where i am finding a problem is as follows: <html> <head> <script> function fun1(){ window.document.formName.action="/someServlet"; window.document.formName.submit();
23
5923
by: Stanimir Stamenkov | last post by:
<form name="myForm" action="..."> <p><input type="text" name="myElem"></p> </form> As far as I was able to get the following is the standard way of accessing HTML form elements: document.forms.elements But I have also seen the following:
0
10505
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
10276
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...
1
10253
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
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
7580
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
5471
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...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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.