Obi1-Cannabis Posted January 10, 2007 Share Posted January 10, 2007 i'm working with javascript and php to make a form that for each product of a DB has a diferent valuehow can i do this without having to use a submit button? because the onclick="document.form.submit();", where 'form' is a php variable doesn't work however the name of the form can be a php variable.please help Link to comment Share on other sites More sharing options...
aspnetguy Posted January 10, 2007 Share Posted January 10, 2007 If there is only one form on the page use the following code it won't matter what the form name is onclick="document.forms[0].submit(); or onclick="document.getElementsByTagName('form')[0].submit(); Link to comment Share on other sites More sharing options...
Obi1-Cannabis Posted January 10, 2007 Author Share Posted January 10, 2007 If there is only one form on the page use the following code it won't matter what the form name isonclick="document.forms[0].submit(); or onclick="document.getElementsByTagName('form')[0].submit(); what if i have more then one form? Link to comment Share on other sites More sharing options...
aspnetguy Posted January 10, 2007 Share Posted January 10, 2007 to refer to a specific form on a page...[0] refers to the first form on the page, [1] the second, [2] the third, etc etcJust change the index number to reference the correct form Link to comment Share on other sites More sharing options...
MrAdam Posted January 10, 2007 Share Posted January 10, 2007 onclick="document.forms[0].submit(); ... onclick="document.forms[1].submit(); goes up for each form on the page in the order they appear. Link to comment Share on other sites More sharing options...
Obi1-Cannabis Posted January 11, 2007 Author Share Posted January 11, 2007 That would work fine if my DB had only one element, but that's not the case... foreach($tipop as $k2=>$v2 ){if ($tipop[$k2]['IDFamilia'] == $familia[$k]['ID']){ $this->idt=$tipop[$k2]['ID']; print" <tr> <form method='Post' action='index.php' name='".$k2."' id='".$k2."'> <input type='hidden' name='comando' value='escolhi'> <input type='hidden' name='idt' value='".$tipop[$k2]['ID']."'> </form> <td width='200' align='left' onclick=\"document.".$k2.".submit();\"style=\" cursor:pointer; cursor:hand;\" onmouseover=\"bgColor='lightyellow';\" onmouseout=\"bgColor='white';\"> ".$tipop[$k2]['Descricao']." </td> </tr>"; }} This is what's not working... Link to comment Share on other sites More sharing options...
jnutty1 Posted January 12, 2007 Share Posted January 12, 2007 That would work fine if my DB had only one element, but that's not the case...foreach($tipop as $k2=>$v2 ){if ($tipop[$k2]['IDFamilia'] == $familia[$k]['ID']){ $this->idt=$tipop[$k2]['ID']; print" <tr> <form method='Post' action='index.php' name='".$k2."' id='".$k2."'> <input type='hidden' name='comando' value='escolhi'> <input type='hidden' name='idt' value='".$tipop[$k2]['ID']."'> </form> <td width='200' align='left' onclick=\"document.".$k2.".submit();\"style=\" cursor:pointer; cursor:hand;\" onmouseover=\"bgColor='lightyellow';\" onmouseout=\"bgColor='white';\"> ".$tipop[$k2]['Descricao']." </td> </tr>"; }} This is what's not working... Obi1,The code you have will work as long as the value in $k2 will create a valid form name. If $k2 contains spaces, special characters, etc., it will fail. Link to comment Share on other sites More sharing options...
Obi1-Cannabis Posted January 12, 2007 Author Share Posted January 12, 2007 Obi1,The code you have will work as long as the value in $k2 will create a valid form name. If $k2 contains spaces, special characters, etc., it will fail.Yes i found the problem already, the thing is that i was trying to use integer for the name. but thanks anyway. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now