/    Sign up×
Community /Pin to ProfileBookmark

document.form1.name.value

I have this script:

[code=php]function SelText()
{
if (document.form1.1c.value == “Portland”)
{
document.form1.1c.value = “”;
}
}
[/code]

The problem is the “1c”. I have a form with an <input name=”1c”….
If i have a non-numerical name such as … <input name=”steve”…
the function works perfect, but it doesnt like the “1c” there.
I cannot change the name of “1c” as it is part of FORM that posts somewhere I don’t have access to.
Is there anyway to get around this?? I tried ” and ‘ around “1c” but that didnt work.

Thanks

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@PittimannFeb 18.2005 — Hi!

document.form1["1c"].value

Cheers - Pit
Copy linkTweet thisAlerts:
@minulescuauthorFeb 18.2005 — Thanks a bunch!!! That worked...kind of. Now i Have a different problem.

So I have the following two functions:
[code=php]function SelText1()
{
if (document.form1["1c"].value == "Portland")
{
document.form1["1c"].value = "";
}
}

function SelText2()
{
if (document.form1["1s"].value == "OR")
{
document.form1["1s"].value = "";
}
}[/code]


then I have the following in a form (form1):
[code=php]<input type="text" name="1c" value="Portland" size="24" maxlength="50" onClick="SelText1();" />
<input type="text" name="1s" value="OR" size="2" maxlength="2" onClick="SelText2();" />[/code]


Now the second one will work..the one with 1s and OR. But the first one wont work. Can anyone help? I have looked at this for 30 min now..and they are exactly identical!!! .?????

note:these functions are supposed to clear the text boxes.

the 2nd gets cleared but the 1st wont.
Copy linkTweet thisAlerts:
@PittimannFeb 18.2005 — Hi!

You must have some mistake in code which you didn't post. The stuff you posted now has to work, if the inputs are elements of a form named 'form1'.

Cheers - Pit
Copy linkTweet thisAlerts:
@FangFeb 18.2005 — document.form1["1c"].value[/QUOTE]
This is [URL=http://www.w3.org/TR/html4/types.html#h-6.2]not valid[/URL]

[I]name[/I] must begin with an alphabetic character
Copy linkTweet thisAlerts:
@PittimannFeb 18.2005 — Hi Fang![i]Originally posted Fang[/i]

[B]This is not valid

name must begin with an alphabetic character[/B]
[/QUOTE]
I would of course have mentioned that if this:[i]Originally posted by minulescu [/i]

[B]I cannot change the name of "1c" as it is part of FORM that posts somewhere I don't have access to.[/B][/QUOTE]
would not have been a part of what minulescu wrote in his first post.

Cheers - Pit
Copy linkTweet thisAlerts:
@FangFeb 18.2005 — This 'error' appears quite regularly and causes problems. It must be mentioned.

If [B]minulescu[/B] can not change it then those that can should be informed.
Copy linkTweet thisAlerts:
@Warren86Feb 18.2005 — Clearing EVERY textbox on click:

<HTML>

<Head>

<Script Language=JavaScript>

function init(){

nText = document.getElementsByTagName('INPUT');
for (i=0; i<nText.length; i++)
{
if (nText[i].type == "text"){nText[i].onclick=function(){this.value=""}}
}
}

window.onload=init;


</Script>

</Head>

<Body>

<Form name='form1'>

<input type="text" name="1c" value="Portland" size="24" maxlength="50">

<input type="text" name="1s" value="OR" size="2" maxlength="2">

<input type="Reset">

</Form>

</Body>

</HTML>
Copy linkTweet thisAlerts:
@PittimannFeb 18.2005 — [i]Originally posted by Fang [/i]

[B]This 'error' appears quite regularly and causes problems. It must be mentioned.

If [B]minulescu[/B] can not change it then those that can should be informed. [/B]
[/QUOTE]
You are absolutely right, Fang. Should have taken that into consideration. Hope, I will keep it in mind for the next time, because it really happens often.

To Warren: do you think, it is a good idea to make the fields blank on every click? What if a user wants to correct something and the form has many fields? Start from the top and tabbing through all the stuff with the keyboard??

Cheers - Pit
Copy linkTweet thisAlerts:
@minulescuauthorFeb 18.2005 — Thanks to all who posted.

-Thanks for script to clear all textboxes...but it wouldnt work well for me.

-What I'm doing is making a form that links to MapQuest.com to give visitors to my website direct directions to a location. I wanted to have the "city"(1c) and "state"(1s) pre-filled as they will commonly be those pre-filled values. I wanted to be slick and have the textboxes be cleared when clicked..so i went to hotmail.com and stole their script..and tried to make 2 of them for city, state. Appearantly its not workin out too well so its fine.

I just think its funny that such a famous/major website as MapQuest.com uses invalid "names" for their forms. Thats too bad. I will not be informing them.

Thanks to all again.
Copy linkTweet thisAlerts:
@PittimannFeb 18.2005 — Hi![i]Originally posted by minulescu [/i]

[B]I just think its funny that such a famous/major website as MapQuest.com uses invalid "names" for their forms. Thats too bad. I will not be informing them.[/B][/QUOTE]
Maybe because of being a German: I never heard of MapQuest.com before. Whoever they are: Fang is absolutely right with what he posted and I should have told you about the invalidity of such field names from the beginning.

Shall I tell them about that? ?

Good luck! Pit
Copy linkTweet thisAlerts:
@minulescuauthorFeb 18.2005 — Just for those who are looking in this forum on how to clear textboxes........I found something way better than using the above functions which barely worked.

In the <input... > simply add
[code=php]onfocus="if (this.value == 'Text') this.value = '';"[/code]

So much easier...and efficient...works like charm.

-MapQuest gives driving directions/shows maps/is a travel agency, etc for you German folks out there.
Copy linkTweet thisAlerts:
@PittimannFeb 18.2005 — Hi!

Thanks for telling me and other German folks, what MapQuest is/does. If you need a little function to clear any text field as far as its' value is the one assigned by default without hardcoding the values in the event handlers, just let me know. Should not take more than a few minutes.

Regards - Pit
×

Success!

Help @minulescu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...