/    Sign up×
Community /Pin to ProfileBookmark

Replace the name attribute with somthing else?

Hi everyone. I really don’t know much about javascript so I need a little help. I am trying to alter a php shoutbox script to conform to my XHTML strict site. I have been succesful at making the script pass validation except for one error.

The error is cause by the name attribute in the form.

[CODE]<form action=”sign.php” name=”tagger” method=”get” onsubmit=”javascript: tagSubmit();”>[/CODE]

the javascript that goes with it is

[CODE]function tagSubmit() {
document.tagger.message.focus();
document.tagger.comment.value = document.tagger.message.value;
document.tagger.message.value = ”;
}[/CODE]

XHTML strict will not allow a name attribute in the form just in the inputs. My question is, Is there a way to change the name attribute to somthing else that will pass as XHTML strict? Somthing like id=”tagger”.

Or possibly move the name attribute to a hidden input? Any ideas? Any help would be apperciated…

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterAug 12.2005 — There is no NAME attribute in XHTML. Use IDs instead.


In HTML, document.tagger.message.value="it works" would work in this case:
<i>
</i>&lt;form name="tagger"&gt;
&lt;input type="text" name="message" value=""&gt;
&lt;/form&gt;


In XHTML, document.getElementById("message").value="it works" would work in this case:
<i>
</i>&lt;form&gt;
&lt;input type="text" [color=royalblue]id[/color]="message" value=""&gt;
&lt;/form&gt;


Also note that when a FORM submits with input fields given IDs rather than NAMEs, the [color=royalblue]param[/color]s are the same.
Copy linkTweet thisAlerts:
@FangAug 12.2005 — I think the [I]name[/I] attribute is required to pass a value (untested)
&lt;form action="sign.php" id="tagger" method="get" onsubmit="tagSubmit();"&gt;
&lt;div&gt;
&lt;input name="message" type="text" /&gt;
&lt;input name="comment" type="text" /&gt;
&lt;button type="submit"&gt;submit&lt;/button&gt;
&lt;/div&gt;
&lt;form /&gt;

andfunction tagSubmit() {
document.forms['tagger'].message.focus();
document.forms['tagger'].comment.value = document.forms['tagger'].message.value;
document.forms['tagger'].message.value = '';
}

Why xhtml strict when html strict is good enough?
Copy linkTweet thisAlerts:
@ToeBeeauthorAug 12.2005 — Thanks Fang your awesome! It worked perfectly. You don't know how happy this makes me ? I have spent the last two days messin with this thing only to get that one error holding me back. Thanks again!
Copy linkTweet thisAlerts:
@FangAug 12.2005 — FF still throws an error, but it does not prevent the form from working.
Copy linkTweet thisAlerts:
@ToeBeeauthorAug 13.2005 — FF still throws an error, but it does not prevent the form from working.[/QUOTE]
Wow really? I use FF and didn't notice any errors ?
Copy linkTweet thisAlerts:
@FangAug 13.2005 — Open the JavaScript Console
Copy linkTweet thisAlerts:
@ToeBeeauthorAug 13.2005 — Oh wow *closes console and sweeps under a rug*
×

Success!

Help @ToeBee 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.28,
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,
)...