By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,480 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,480 IT Pros & Developers. It's quick & easy.

Reference input without ID

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
<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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
Never mind, I fixed it on the server-side.
Thanks for your help!

Matthew

Sep 2 '06 #7

P: n/a
Never mind, I fixed it on the server-side.
Thanks for your help!

Matthew

Sep 2 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.