Click to See Complete Forum and Search --> : Valid form field naming convention


chestertb
10-14-2003, 11:23 AM
I have a form that has to be sent to a 3rd party site. The naming convention for the field names uses a "." as in name="test.name".

Is this name valid in Javascript? If so, how do get the data from a field? Normally, I'd use
newname = window.document.formname.fieldname.value.

Now... assuming the naming convention is legal, and to demonstrate just how little I really understand...

If the form is in an iframe, and I want to access the data in that iframe form from the parent (in this case, the top), what changes in the above line of code?

Thanks
IB

Charles
10-14-2003, 11:37 AM
From the HTML 4.01 Specification:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
http://www.w3.org/TR/html4/types.html#type-idSo it's valid, but troublesome to use. To avoid having the JavaScript interpreter think that the period is the dot operator simply use the associative array object syntax. Id est:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>

<form action="" onsubmit="alert(this['king.tut'].value); return false">
<div>
<label>Field<input type="text" name="king.tut" value="Got a condo made of stone-a."></label>
<button type="submit">Submit</button>
</div>
</form>

chestertb
10-14-2003, 09:05 PM
Thanks Charles.

I'm going to try using the array as suggested to extract data from the form the the iframe and populate fields in a hidden form on the top page, then submit from there... messy, but right now i'd rather have the site working than elegant.

Cheers
IB

chestertb
10-14-2003, 10:46 PM
Thanks thanks thanks!!!

Charles... using the arrays worked a treat!

As per the last post, I created a hidden form on the parent, then used the button on the form in the iframe to call a function in the parent that populated the hidden form with the data from the iframe, and then submitted it.

Odd that a direct submit doesn't work from the iframe, but as the above solution works, care factor=0.

Once again,
Thanks
IB