Click to See Complete Forum and Search --> : help!! how to replace object w/ variable in a js expression?
wscottpadgett
01-29-2004, 05:11 PM
help!
i pass an argument to a function that i need to have replace "form_name" in an expression like this:
function such_and_such(form_name)
{
document.form_name.submit();
}
but writing the code like this doesn't work. anyone know what would? thanks!!!!!
could we get the full source?
wscottpadgett
01-29-2004, 05:36 PM
the URL of the results of my PHP is at:
http://wscottpadgett.com/CWMC/fee_content_query_test.php
and it shows all that is really pertinent to my question...
thanks!!!!
dhgeyer
01-29-2004, 05:42 PM
I'm not sure that javascript is decoding the variable into the form name as you intend. Given your application, could you pass the form number on the document to the function instead of the name? The form objects on a document are stored in an array, such that the first one can be referred to as document.forms[0], for example. So you could have:
function submitform(i) {
// i is the number of the form on the document, - 1.
document.forms[i].submit();
}
Just a thought, and I didn't test it!
Dave Geyer
wscottpadgett
01-29-2004, 05:53 PM
i don't think i can use the form number, because the page arrangement will change according to how many items are in the database at the time of submission, but is it possible that javascript sets an associative array with keys of form names also??
this would work beautifully, but if i try this:
document.forms['form_name'].submit();
it doesn't seem to work....
is that because the above expression is evaluating the form_name var as it runs, or because the array just isn't associative as i thought i might be???
wscottpadgett
01-29-2004, 05:58 PM
no associative array.
but i think i can write a script to yield an appropriate form number to pass for the appropriate from submitted from and fix it up that way.
thanks for the tip, i'm going to give it a shot.
just fyi, if i do run the explicit form # in the script it does work! so i think you got me half-way there.
i'll keep you posted.
thanks!
wscottpadgett
01-29-2004, 07:12 PM
your tip about the existence of the forms array has me all set. i appreciate it.
i just placed a counter into the PHP that creates the forms so that i have a counter variable passed to the javascript function. then it correctly submits the right form!
thanks A LOT. you pulled me out of deep frustration!
:cool:
dhgeyer
01-29-2004, 07:33 PM
Hey, you know what? That makes my day too! Sounds like you're doing some substantial server side processing. Maybe some time I'll need to know how to do that as well.
Dave Geyer