Hi!

Thanxs.. it's working now..

~Gurcharan

On 10/11/06, Colin Mollenhour <[EMAIL PROTECTED] > wrote:
Gurcharan,
    Your problem is that all of your inputs have the same id.  It is invalid for any two elements of any type to share ids. If specified, it must be unique. I only ever specify them if it is necessary to access a particular DOM element, otherwise, use other methods not involving ids.
If you want to group inputs, use brackets after the name to declare an array in the result. Similarly you can declare a hash of results by supplying brackets with the key for the hash inside the brackets.

Form with checkboxes all using the same "name" attribute (will give an array):
<form id="myform">
    <input type="checkbox" name="AC[]" value="ANTIQUES & COLLECTIBLES Art" />
    <input type="checkbox" name="AC[]" value="ART General" />
    <input type="checkbox" name="AC[]" value="ART African" />
    <input type="checkbox" name="AC[]" value="ART American General" />
</form>

Use Form.serialize to gather all results in one fell swoop. Only checkboxes that were checked will be present in the result.
E.g. if "ART General" and "ART African" were checked:

var query = Form.serialize('myform'); //you can use this to send values back to the server (post or get parameters string)
var values = query.toQueryParams(); //now values will have a nice hash like so:
{
    AC: [
        "ART General",
        "ART African"
    ]
}

If you use "query" as the parameters for a request, you'll also have a nice array of values on the server side accessible via (PHP example) $_POST['AC'].

Lastly, to loop through all of the checked boxes, simply:

values.AC.each(function(value){ //will alert the values of each checked box
    alert(value);
});

Very clean, no?

Colin

Gurcharan Singh wrote:
Hi!

Thanxs for your response. I tried as suggested but still it's not working. My HTML sample code is -


<script src=""
<script>

function update()
{
      
 
       formElements = Form.getInputs('searchForm','checkbox');
     
       var len = formElements.length;
     
   
    for( i=0 ; i< len ; i++)
    {      
       if(document.searchForm.elements[i].checked)
       {       
                
                 window.opener.document.signup.subject_1.value = $F(formElements[i]);
               
                window.close();
       }
    }
   
}
</script>
</head>
<body>

<!-- Form for the display of search text bar !-->
<form name="search" method="post" action="" ?formField=subject_1">
    <center><b>Search Criteria:&nbsp;</b><input type="text" name="searchValue">
    &nbsp;<input type="submit" value="Search" name="searchBisac"><br />
    </center>
    <fieldset><legend>Note</legend>

    Search on category name e.g. art, fiction, science etc.<br />
    Search leads to listing of BISAC codes, when clicked shall be stored in the category of your choice.
    </fieldset>
   
   
</form>

<!-- Form created from the search result !-->

<form id="searchForm">
<br /><input type="checkbox" name="AC" id="AC" value="ANTIQUES & COLLECTIBLES Art    " >">
ANT002000 ANTIQUES & COLLECTIBLES Art

<br /><input type="checkbox" name="AC" id="AC" value="ART General    " >">
ART000000 ART General

<br /><input type="checkbox" name="AC" id="AC" value="ART African    " >">
ART015010 ART
African

<br /><input type="checkbox" name="AC" id="AC" value="ART American General   " >">
ART015020 ART
American
General

..................
...

</form>

Pls, suggest what I'm missing.

Thanxs
~Gurcharan


On 10/10/06, Christophe Porteneuve aka TDD <[EMAIL PROTECTED] > wrote:

Hey there,

Gurcharan Singh a écrit :
> Form.getInputs ('FormName',['checkbox']). But on the submission of the
> form I'm getting the error message - HTML has no properties.

Try Form.getInputs('FormId', 'checkbox').

a) You need the *id* of the form, not its *name* (btw, XHTML 1.0
deprecated 'name' attributes for just about anything except form *fields*).

b) You pass a string, not an array of strings, as a second argument.

'HTH

--
Christophe Porteneuve aka TDD
[EMAIL PROTECTED]





--
www.digitalmediainitiatives.com






--
www.digitalmediainitiatives.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---

Reply via email to