Connecting Tech Pros Worldwide Forums | Help | Site Map

Need Help with my script logic

pbd22
Guest
 
Posts: n/a
#1: Sep 24 '07
Hi.

In my script the below code creates a new element
on the page with an associated delete button:

var row_element = new Element(
'div',
{
'class':'container',
'events':{
'click':function( uid ){
this.activeRow( uid );
}.pass( current_element.uid, this )
}
}
).adopt( delete_button ).adopt( item );

Now, when a user clicks on that element, I want the
input fields on the page to be particular to that element.
So, whatever is written in them, gets stored in an array
that is specific to this particular element "uid". If something
was written, the fields get repopulated when the element
is clicked on again.

Here is the function that gets activated when the element is clicked
on:

activeRow:function( uid ){

active_row = this.elements[ this.uid_lookup[ uid ] ];
[?]

}

I am not quite sure how to approach this, help appreciated.

Thanks.


pbd22
Guest
 
Posts: n/a
#2: Sep 25 '07

re: Need Help with my script logic


On Sep 24, 2:36 pm, pbd22 <dush...@gmail.comwrote:
Quote:
Hi.
>
In my script the below code creates a new element
on the page with an associated delete button:
>
var row_element = new Element(
'div',
{
'class':'container',
'events':{
'click':function( uid ){
this.activeRow( uid );
}.pass( current_element.uid, this )
}
}
).adopt( delete_button ).adopt( item );
>
Now, when a user clicks on that element, I want the
input fields on the page to be particular to that element.
So, whatever is written in them, gets stored in an array
that is specific to this particular element "uid". If something
was written, the fields get repopulated when the element
is clicked on again.
>
Here is the function that gets activated when the element is clicked
on:
>
activeRow:function( uid ){
>
active_row = this.elements[ this.uid_lookup[ uid ] ];
[?]
>
}
>
I am not quite sure how to approach this, help appreciated.
>
Thanks.
OK, I think I have figured out a more productive way to ask this
question (i hope). Could somebody show me how I could identify a
change on my form (select box, input field, textarea, etc) and assign
the new values to an associated array for each element. So, there will
be a selectbox[0], input[0], etc and selectbox[1], input[1], etc. My
attempts at this have been pretty ugly - lots of code.

Thanks for any help.

Sabine Dinis Blochberger
Guest
 
Posts: n/a
#3: Sep 25 '07

re: Need Help with my script logic


pbd22 wrote:
Quote:
>
OK, I think I have figured out a more productive way to ask this
question (i hope). Could somebody show me how I could identify a
change on my form (select box, input field, textarea, etc) and assign
the new values to an associated array for each element. So, there will
be a selectbox[0], input[0], etc and selectbox[1], input[1], etc. My
attempts at this have been pretty ugly - lots of code.
>
Thanks for any help.
>
Well, if it works, does it matter if it's one or three lines of code? It
really shouldn't, especially if it makes for readable/maintainable code.

Maybe you should post the code that does work, so someone can help you
beautify/optimize it.
--
Sabine Dinis Blochberger

Op3racional
www.op3racional.eu
Henry
Guest
 
Posts: n/a
#4: Sep 25 '07

re: Need Help with my script logic


On Sep 24, 10:36 pm, pbd22 <dush...@gmail.comwrote:
Quote:
In my script the below code creates a new element
The code below uses what must be a function named "Element" to create
a javascript object, though the fate of that object is unclear form
the code. If here you are referring to a DOM node implementing the
Element interface being created as a side effect (or anything else)
there is no evidence of that happening in this code.
Quote:
on the page with an associated delete button:
>
var row_element = new Element(
'div',
{
'class':'container',
'events':{
'click':function( uid ){
this.activeRow( uid );
}.pass( current_element.uid, this )
}
}
).adopt( delete_button ).adopt( item );
>
Now, when a user clicks on that element,
Which element? You can "click on" (at least most) DOM Elements, but
"clicking" is a little detached from being something that you can do
with a javascript object.
Quote:
I want the input fields on the page
What input fields, what page?
Quote:
to be particular to that element.
So, whatever is written in them, gets stored in an array
that is specific to this particular element "uid". If something
was written, the fields get repopulated when the element
is clicked on again.
That sounds more like you want the contents of an INPUT (presumably
type="text") Element to change when some notion of 'current selection'
is applied to one of some group of other Elements by the action of
clicking.
Quote:
Here is the function that gets activated when the element is clicked
on:
>
activeRow:function( uid ){
>
active_row = this.elements[ this.uid_lookup[ uid ] ];
[?]
>
}
How does it "get activated"? As javascript determines the - this -
value by how a function is called that is very important in
determining how this might behave, or be written so that it does
something related to what you are interested in.
Quote:
I am not quite sure how to approach this, help appreciated.
The best approach to getting a question answered is to provide the
information necessary to answer it (and not hide it in anything
superfluous). Here you have provided none of the mark-up with which
this code is going to interact, you have not shown the context in
which the first code snippet is executed, your have not shown the
context in which the second is defined, you have not provided the
definition of the - Element - constructor used here, the - adopt -
method or the constructed/returned object (or the - adopt - method of
the object returned from the first call to - adopt -(if they differ)),
the - pass - method that appears to have been added to the -
Function.prototype -, or any of the code that these may depend upon.
There is no indication of the type or nature of the - uid - value or
the - current_element - value.

pbd22
Guest
 
Posts: n/a
#5: Sep 25 '07

re: Need Help with my script logic


On Sep 25, 9:47 am, Henry <rcornf...@raindrop.co.ukwrote:
Quote:
On Sep 25, 2:01 pm, pbd22 wrote:On Sep 25, 4:03 am, pbd22 wrote:
<snip>
Quote:
Henry, in response to your comments about not having enough
info. Below is the complete script (minus the delete function).
>
<snip>
>
Quote:
You have omitted any code for the constructors - Class - and - Element
below is the script for construction:

<script type="text/javascript">
window.addEvent('domready', function() {
new MultiUpload( $
( 'uploadForm' ).my_file_input_element, 0, '{id}', true, true );
});
</script>
Quote:
-, their method definitions, some functions (the unwisely named - $ -
and - $defined - functions), at least two - Function.prototype -
extensions, and the code that any of this absent code depends upon,
I am using a javascript library for this. I have no actual prototype
declarations of my own. For the library function definitions, you will
need to look at: http://docs.mootools.net
Quote:
context of how the code you have posted is executed/used.
Please see the steps marked by an "x" earlier in the thread. The
larger picture is that this is a file upload form and that I am trying
to upload multiple files at the same time using the code I have
posted. The files will all then be sent to the server in succession
for processing. Where I am getting stuck is that, for each file, the
data associated with its form elements need to be saved prior to
submit. I am working on the solution in the activeRow:function() block
that I have posted.
Quote:
the mark-up that this code is intend to interact with and any
the hidden inputs get populated after the following on the form:

<input id="my_file_input_element" type="file" name="file_1" />

the other relevant fields are pretty much everything that takes data
on the form - selects, inputs, textarea, radiobuttons, etc.

Rather than dump a ton of HTML here - I have named every relevant form
element name="ff1", name="ff2", name="ff3"... name=ffn", where "n" is
the count of the final element. This way I can loop through them if
need be.

Closed Thread