PDA

View Full Version : help me, i can't get it to work!



Ric373
November 3rd, 2006, 09:31 AM
its probably very easy, but I can't get it to work. Here's what i have:


<script type='text/javascript' language='JavaScript'><!--
function submitForm() {
document.form1.submit();
}
//--></script>

this works

next i have a peace of php:



echo "<form name='form".$id."' method='post' action='edit.php?id=".$id."&amp;done=".$done."'>
<input name='checkbox' type='checkbox' value='checkbox' onClick='submitForm();'";


still works...

this is what i want to do:

js code:

<script type='text/javascript' language='JavaScript'><!--
function submitForm(myForm) {
document.myForm.submit();
}
//--></script>

php code:


echo "<form name='form".$id."' method='post' action='edit.php?id=".$id."&amp;done=".$done."'>
<input name='checkbox' type='checkbox' value='checkbox' onClick='submitForm('form".$id."');'";


I cant get this to work, does anyone know how to fix this?

thanks,

Ric

duncanhall
November 3rd, 2006, 12:13 PM
Your first piece of JS is referencing 'form1' and the PHP is dynamically labelling your form with "form".$id

I'm guessing $id = 1, and therefore it works.

Your second piece of JS is referencing 'myForm', yet you are still dynamically labelling the form as "form".$id.

Change the php line from

<form name=form.$id ...

to

<form name=myForm ....

Ric373
November 3rd, 2006, 08:00 PM
Your first piece of JS is referencing 'form1' and the PHP is dynamically labelling your form with "form".$id

I'm guessing $id = 1, and therefore it works.

Your second piece of JS is referencing 'myForm', yet you are still dynamically labelling the form as "form".$id.

Change the php line from

<form name=form.$id ...

to

<form name=myForm ....



no, thats not it, i call the javascript with a variable:

onClick='submitForm('form".$id."');

i retrieve the variable as myForm in my js function and i then use it
to tell it what form it should submit

function submitForm(myForm) {
document.myForm.submit();
}

the basic idea is to have a list with checkboxes, when one is clicked
it should submit the corresponding form.