473,500 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reference input without ID

I have a form that appears several times on a page, and would rather
not assign IDs.
Is there a way to have my validation function focus() a text input
without IDs?
www.osbornewood.com
Search form in the upper right corner.

Thanks,

Matthew

Aug 31 '06 #1
7 1632
document.forms["yourform"].elements["element"].focus();
PR********@gmail.com wrote:
I have a form that appears several times on a page, and would rather
not assign IDs.
Is there a way to have my validation function focus() a text input
without IDs?
www.osbornewood.com
Search form in the upper right corner.

Thanks,

Matthew
Aug 31 '06 #2
<PR********@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
I have a form that appears several times on a page, and would rather
not assign IDs.
Is there a way to have my validation function focus() a text input
without IDs?
www.osbornewood.com
Search form in the upper right corner.
Don't you mean upper left side?

"http://www.osbornewood.com" has this Search Form:

<form action="http://www.osbornewood.com/search.cfm"
method="get" name="bar" id="bar" onSubmit="return searchSubmit();">
<input type="text" name="criteria" id=criteria size="7" value="Search"
style="color:grey;" onfocus="criteriaFocus(this);"
onblur="criteriaBlur(this);" />&nbsp;
<input type="submit" value="Go" />
</form>
which calls this function in "http://www.osbornewood.com/main.js":

function searchSubmit() {
if (document.getElementById) {
criteria = document.getElementById('criteria').value;
if (criteria == '' || criteria == 'Search') {
document.getElementById('criteria').focus();
return false;
} else {
return true;
}
}
}

Try changing it to:

function searchSubmit() {
var criteria = document.bar.criteria.value;
if (criteria == '' || criteria == 'Search') {
document.bar.criteria.focus();
return false;
} else {
return true;
}
}

Also, you can remove all "id=" from within the "form".
Aug 31 '06 #3
Yes, that's the one.
I have it on a server-side include, and would like to include it three
times per page.
I took the other two off because it didn't work properly.
So, I would have three forms called "bar"... That won't work very well
with the current or suggested code.
Thanks,
Matthew

Aug 31 '06 #4
Don't provide any ID or name for the forms and provide the same ID for
all input boxes. Then reference them by:

document.forms[0].element['criteria']
document.forms[1].element['criteria']
document.forms[2].element['criteria']

HTH

Aug 31 '06 #5
JRS: In article <nI******************************@comcast.com>, dated
Wed, 30 Aug 2006 21:49:31 remote, seen in news:comp.lang.javascript,
McKirahan <Ne**@McKirahan.composted :
><PR********@gmail.comwrote in message
news:11**********************@h48g2000cwc.googleg roups.com...
>I have a form that appears several times on a page, and would rather
not assign IDs.
Is there a way to have my validation function focus() a text input
without IDs?
Use something like onClick="Try(this.form)"
with
function Try(F) { with (F) {
... } }

// or with F. before the names of the controls rather than using with.

OTOH, if the appearing forms are the same, why?
AND, code to be executed should not be repeated in the source; you can
write your form with a javascript function (and then it's easy to give
each one a sequenced or other ID).

return false;
} else {
return true;
}

There's no need to put an else after a return.

OP : read the newsgroup FAQ.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 31 '06 #6
Never mind, I fixed it on the server-side.
Thanks for your help!

Matthew

Sep 2 '06 #7
Never mind, I fixed it on the server-side.
Thanks for your help!

Matthew

Sep 2 '06 #8

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

Similar topics

17
4177
by: Karl Irvin | last post by:
To use the Textstream object, I had to set a Reference to the Microsoft Scripting Runtime. This works good with A2000 Is the Scripting Runtime included with A2002 and A2003 so the Reference...
3
2420
by: Adriano | last post by:
Hello, when I try to print something, either DataGrid or from Crystal Report viever the folowing error message appears and cancels printing: Object reference not set to an instance of an...
8
1844
by: wASP | last post by:
Hi, I'm having a problem referencing the elements within an object after a method of that object (a member function) has been activated with an onsubmit handler: - - - - - - - - ...
11
1442
by: Richard Lewis Haggard | last post by:
Is it possible to put a reference to an object inside of a class? If so, what is the syntax? The reason I want to do this is so that I can make a copy of the original object, make modifications to...
2
3032
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
24
2479
by: Chameleon | last post by:
This code does not working in Mozilla. Works fine in IE. -------------- <input type=text value=100 name=textbox> <script> alert(textbox); </script> -------------- This perhaps, because of...
27
4184
by: David W | last post by:
I'm almost tearing my hair out. A colleague claimed that a null reference can exist, like this: void f( int& p ) { printf( "%d\n", p ); } int main (int argc, char *argv) {
10
3409
by: JurgenvonOerthel | last post by:
Consider the classes Base, Derived1 and Derived2. Both Derived1 and Derived2 derive publicly from Base. Given a 'const Base &input' I want to initialize a 'const Derived1 &output'. If the...
5
1464
by: James.Yu.Tin | last post by:
Anybody can kindly explain the confusion below? generally, would there be any problem for C++? void magic(int& a) { /* expect side-effect */ // change the value of the input
0
7136
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
7182
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,...
0
7232
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
5490
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,...
1
4923
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...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
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 ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
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...

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.