Put this attribute in your body tag:onload="document.formName.keytxt.focus(); document.formName.keytxt.select()"of course replacing formName with the name of the form.
but, it won't work. And the onload one works, but I have many different txt boxes, cause I'm using ColdFusion as well with multiple IF statements, so I don't know what the name of the text box will be according to the category selected.
Any other suggestions? If you can look up the <select:all> attribute, it would be greatly appreciatyed.
Thanks,
Jason
Jason Hill
10-05-2001, 09:14 PM
Thank you, I'm almost there.
onload="document.forms[0].elements[1].select();"
will work, however, depending on the selection of the user to search by KEYWORD or COMPANY, the page returns with a text box or a select box. If it comes back with a text box, the onload() event works great, HOWEVER, if the user selects to search by company, and it comes back with a select box, the select() method doesnt apply to the select list and gives me an error.
ALSO, once the user submits the search, the resulting page does'nt have a second feld . SO the statement including, elements[1] doesn't apply either.
THEREFORE, I'm thinking to try something like this:
OnLoad="javascript: if (document.forms[0].elements[1].value is TRUE AND if (document.forms[0].elements[1].name=='keytxt' || document.forms[0].elements[1].name=='prodtxt') document.forms[0].elements[1].select();"
But, I need some of your help with the code.
Thanks again,
Jason
voicebox
10-05-2001, 09:53 PM
Hi Jason,
The fastest way to do what you want (and which will be compatible if one day browsers do have a select method on select boxes for some reason) is to check for the method within the object before you call it, for example:if (document.forms[0].elements[1].select) document.forms[0].elements[1].select();
Jason Hill
10-05-2001, 11:05 PM
Thank you Mr. Voice Box,
You're code works great:
OnLoad="javascript: if (document.forms[0].elements[1].select()) document.forms[0].elements[1].select();"
HOWEVER, once the search is submited, the resulting [age only has one element, the serch selection list with keyword, company, product.
SO I keep getting the error:
"document.forms[0].elements[1]" is undefined, or null.
SO, I have to validate that it exists first of all in my javascript statement.
Thanks,
Jason
Jason Hill
10-05-2001, 11:21 PM
I'm soooooo close. This is what I'm using:
OnLoad="javascript: if ((document.forms[0].elements[1]) && (document.forms[0].elements[1].select())) {document.forms[0].elements[1].select()};"
HOWEVER, if the user wants to search by company, using a select list instead of a text box, I get the following error:
Object does'nt support this property or method
...because it is a select list.
SO what prop or meth does it support??
Thanks,
Jason
voicebox
10-06-2001, 05:14 PM
Hi Jason,
If you have another look at my post there are no () brackets after the select within the if statement (this is because I'm just checking to see if the function exists, not trying to call it). So the code you want would look like this:if ((document.forms[0].elements[1]) && (document.forms[0].elements[1].select)) {document.forms[0].elements[1].select()}