0

I can't get my css button to submit. the form directs to the correct page, but nothing gets submitted. any ideas?

echo "<form action=\"submit_something.php\" id=\"submit_x\" method=\"post\">
<input type=\"hidden\" name=\"submit_value\" value\"10\"/><div id=\"button\">
<a href=\"javascript:;\"onclick=\"javascript:document.getElementById('submit_something').submit()\">buttonvalue</a>
</div></div></form>"

update2:

echo "<form action=\"submit_something.php\" id=\"submit_x\" method=\"post\">
<input type=\"hidden\" name=\"submit_value\" value\"10\"/><div id=\"button\">
<a href=\"javascript:;\"onclick=\"javascript:document.getElementById('submit_x').submit()\">buttonvalue</a>
</div></div></form>"

update3: I tried this instead: css:

#btn {font-weight:bold}

html:

<form action="submit_something.php" id="submit_x" method="post">
  <input type="submit" value="button" id="#btn">
</form>

The button doesn't get styled. I tried differentcss parameters, but the submit button doesn't get styled. Any ideas?

2
  • 4
    Look! An element that is designed to submit forms: <input type="submit"> Commented Mar 4, 2012 at 9:21
  • i'm using a css button with $_POST Commented Mar 4, 2012 at 9:28

3 Answers 3

1

You're attempting to submit an element with the ID submit_something, but your form actually has the ID submit_x, so the form won't submit. Also, you shouldn't include javascript: into event handler code like onclick; this is only needed when you want to execute Javascript code in something like a href.

I don't recommend submitting your form using Javascript by the way, avoid it if you can. Using basic HTML functions like submit buttons where possible can prevent a lot of trouble, for example with usability.

Sign up to request clarification or add additional context in comments.

3 Comments

Updated. Still doesn't work. I'm using javascript and onclick because i'm using a css button instead of a regular submit button. I want to use $_POST on a css button. hmmm
I don't see how this is bad usability? Do you mean if user disables javascript?
@user1163859: did you also remove the javascript: scheme identifier from your event handler? Event handlers like onclick are already treated as code, adding an URI scheme will just be a syntax error.
0

Use the input type of image instead, or style your submit button, instead of this unmaintainable nastiness you have now.

<input type="image" src="myimage.png" />

The image input behaves the same way as a regular submit button.

Or, you can style an actual submit button appropriately, with most of the same styles as your anchor currently. For more info, see http://www.456bereastreet.com/lab/styling-form-controls-revisited/submit-button/

2 Comments

Indeed. You really should use the correct controls here, and avoid unnecessary javascript. There's no need to reinvent the wheel for something like a submit button. You will confuse users, and you will destroy usability.
You gave it an id of "#btn". It should be an id of "btn". The # is for CSS only, and is a way of saying "select by ID".
0

use

<input type="submit" value="button" id="btn">

instead of

<input type="submit" value="button" id="#btn">

to apply the style with id btn.

CSS

#btn {font-weight:bold}

and your php to print the form

echo "<form action=\"submit_something.php\" id=\"submit_x\" method=\"post\">
<input type=\"hidden\" name=\"submit_value\" value=\"10\"/><div id=\"button\">
<a href='' onclick=\"document.getElementById('submit_x').submit();return false;\">buttonvalue</a>
</div></div></form>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.