Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > document.forms[0] and Struts (tags)

Reply
Thread Tools

document.forms[0] and Struts (tags)

 
 
Jan-Friedrich Mutter
Guest
Posts: n/a
 
      06-27-2003
Hi,

I have a problem to access a hidden field by javascript. The name of
the field has a dot in it. That's the problem. But I need that dot
because it is a "Stuts Property".
I'm using IE 6. This is my code:

<!--
function changeValue(myvalue) {
//works
document.forms[0].testProperty.value = myvalue;
alert('document.forms[0].testProperty.value='+document.forms[0].testProperty.value);
//doesn't work
//(javascript error:
//document.forms[0].dotted.prop is null or not an object)
document.forms[0].dotted.prop.value = myvalue;
alert('document.forms[0].dotted.prop.value='+document.forms[0].testProperty.value);
}
//-->

<form>
<input type="hidden" name="testProperty" value="">
<input type="hidden" name="dotted.prop" value="">
</form>

Any comments are appreciated.

Cheers,
Jan.
 
Reply With Quote
 
 
 
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      06-27-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Jan-Friedrich Mutter) writes:

> I have a problem to access a hidden field by javascript. The name of
> the field has a dot in it. That's the problem. But I need that dot
> because it is a "Stuts Property".


It is illegal HTML, so you should check again whether it is *really*
necessary.

> document.forms[0].dotted.prop.value = myvalue;


How to access properties with illegal names:
<URL:http://jibbering.com/faq/#FAQ4_25>
I.e.,
document.forms[0].elements["dotted.prop"].value

/L
--
Lasse Reichstein Nielsen - (E-Mail Removed)
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
 
 
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      06-27-2003
(E-Mail Removed) (Jan-Friedrich Mutter) writes:

> document.forms[0].dotted.prop.value = myvalue;
> alert('document.forms[0].dotted.prop.value='+document.forms[0].testProperty.value);


Use getElementById('dotted.prop')
 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      06-27-2003
"Tor Iver Wilhelmsen" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
<snip>
> Use getElementById('dotted.prop')


Do not use getElementById to access form elements with JavaScript. Use
the W3C HTML DOM level 2 specified document.forms collection to access
the form and access the element as either a named or indexed property of
either the form or the form's elements collection:-

document.forms[nameOrIndex].elements[nameOrIndex];

- complies with the latest W3C specification and is back-compatible with
_every_ JavaScript capable browser currently in use.

Richard.


 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      06-28-2003
Jan-Friedrich Mutter wrote:
> I have a problem to access a hidden field by javascript. The name of
> the field has a dot in it. That's the problem. But I need that dot
> because it is a "Stuts Property".


In general, it's best not to post JavaScript questions to
comp.lang.java.* groups. Java and JavaScript are not the same.
Followups are set.

> I'm using IE 6. This is my code:
>
> <!--
> function changeValue(myvalue) {
> //works
> document.forms[0].testProperty.value = myvalue;
> alert('document.forms[0].testProperty.value='+document.forms[0].testProperty.value);
> //doesn't work
> //(javascript error:
> //document.forms[0].dotted.prop is null or not an object)
> document.forms[0].dotted.prop.value = myvalue;
> alert('document.forms[0].dotted.prop.value='+document.forms[0].testProperty.value);
> }
> //-->


Try:

(document.forms[0])["dotted.prop"].value = myvalue;

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Eclipse and Ant with Struts: how to combine to generate javadoc api, how to map struts source to binary code for debugging Merlijn Java 0 03-24-2006 01:47 PM
Is it safe to point to Internet for locating struts DTD files in struts TLDs and XML files? Katie Wright Java 8 01-07-2005 03:37 PM
[Struts]output javascript in struts perform() sin Java 3 02-22-2004 08:27 AM
Integrate a Struts app with a non-struts app jc1771 Java 0 12-28-2003 06:36 PM
Struts Installation - missing struts.tld??? Jason Us Java 0 10-03-2003 11:36 PM



Advertisments