javascript submission of xhtml compliant form

Let’s say i have a form to perform a login to another site. With the infrastructure we have here, it reads html from a database, build a page containing a form, plugging in real values for some placeholders and then uses javascript to submit the form.

For example:

<body>
   <form method="POST" action="http://othersite/ssologin.php" name="ssoform">
    <input type="hidden" name="user" value="@username" />
    <input type="hidden" name="pass" value="@password" />
  </form>
  <script type="text/javascript">document.ssoform.submit();</script>
</body>

However, this is not XHTML compliant code. The ‘name’ attribute is deprecated and should be replaced by ‘id’. But in doing so, the javascript does not work anymore and the form doesn’t submit at all. It turns out that the javascript needs to be modified slightly:

<body>
  <form method="POST" action="http://othersite/ssologin.php" id="ssoform">
    <input type="hidden" name="user" value="@username" />
    <input type="hidden" name="pass" value="@password" />
  </form>
  <script type="text/javascript">document.forms.ssoform.submit();</script>
</body>
Advertisement

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.