Jump to content

Dam this form


Obi1-Cannabis

Recommended Posts

i'm working on 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

I don't understand, why can't you use submit? I've never run into a situation where I could not use submit.
it's not that i can't use a submit button, but it isn't very pleasant to see so i just wanted to use text from a table cell...<form method='Post' action='index.php' name='".$myForm."'><input type='hidden' name='comando' value='escolhi'><input type='hidden' name='idt' value='".$tipop[$k2]['ID']."'></form> <td width='200' align='left' onclick=\"document.".$myForm.".submit();\"style=\"cursor:pointer; cursor:hand\" onmouseover=\"bgColor='lightyellow';\" onmouseout=\"bgColor='white';\">".$type[$key]['Value']." </td>this one isn't working, tough the onmouseover and onmouseout are working.
Link to comment
Share on other sites

I got you, you just want to use javascript to submit it. I think you use the ID, not the name though. So try this:<form method='Post' action='index.php' name='".$myForm."' id='".$myForm."'>
nope it dosn't work either i've tried it already. i also tried something like:<td width='200' align='left' onclick=\"document.forms[0].submit();>but since i have another form in the same page it doesn't work either...
Link to comment
Share on other sites

Well, I guess the obvious answer would be to just type some javascript that does it, and then convert it to have PHP output the same javascript. I noticed that there is not a space between the onclick and the style, I'm not sure if that matters. Try this:

<td width='200' align='left' onclick=\"document.{$myForm}.submit();\" style=\"cursor:pointer; cursor:hand;\" onmouseover=\"bgColor='lightyellow';\" onmouseout=\"bgColor='white';\">

Also, the style attribute has conflicting properties. Not that it affects the javascript, but you should remove one of them.

Link to comment
Share on other sites

I don't know what you're doing wrong, but this works just fine for me. Just make sure you remove the space between java and script in the href, it should be one word.

<?php$form_name = "myform";?><html><head><title>Form test</title></head><body><form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post" name="<?php echo $form_name; ?>" id="<?php echo $form_name; ?>"><input type="hidden" name="test" value="test value"><a href="java script: void(0);" onclick="document.<?php echo $form_name; ?>.submit();">click to test</a></form><?phpif ($_POST['test'] == "test value")  echo "form was submitted";?></body></html>

Link to comment
Share on other sites

I don't know what you're doing wrong, but this works just fine for me. Just make sure you remove the space between java and script in the href, it should be one word.[
Finnaly solved it using the way i was before, the problem was that i was trying to use an integer variable for form's id if i use a string it works.To think i took 3 days to see the problem lol.
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...