0

My website has been created with a CSS/HTML frame work that has been integrated into an ASP.NET website.

Inside of a ContentPlaceHolder, I have a simple login form. The catch is that I am using the onclick event of an image to submit the form. It normally works pretty straight forward, but this time I am having an issue.

<div id="login">
    <form action="index.aspx" method="post" id="nothingForm" name="nothingForm">
    </form>
    <form action="https://google.com.au" method="post" id="loginform" name="loginform">
        <input type="text" name="uname" value="username" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;"/>
        <input type="password" name="pword" value="password" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;"/>
    </form>
    <br /><img src="images/login.gif" alt="" onclick="document['loginform'].submit()" />    </div>

I have to stick another form before the real form to make onclick="document['loginform'].submit()" actually work. This should not be the case, of course, but I was unable to find any solutions to it on the web.

Has anyone else come across this before?

8
  • Check and see if your content place holder is inside a form. That can cause form submit issues... Commented Sep 27, 2010 at 4:11
  • Why not use Server side controls anyway? You're using ASP.NET, there's a built in login widget... Commented Sep 27, 2010 at 4:16
  • 1
    You're code seems to work, even without the "nothingForm". Can you reproduce the problem on a public site or on JSBin.com? Are you having this problem with a particular browser? Commented Sep 27, 2010 at 4:27
  • I agree, this should work w/o the blank form. Post your full code, the problem (if one exists) is probably elsewhere. Commented Sep 27, 2010 at 4:31
  • @EJC The ContentPlaceHolder is inside of the required ASP.NET form. Commented Sep 27, 2010 at 4:51

2 Answers 2

2

Did you try out document.getElementById("loginform").submit()? I would think this is better, since I have never seen anyone access elements on the document itself like that before. May be some kind of strange side effect.

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

2 Comments

Thanks for your response. I did try that with no luck.
...or document.forms["form-id"].submit()
1

Your problem is that the page already has a form around all the code. Forms can not be nested, so your first form tag will be ignored, and it's end tag will end the outer form.

You have to place your form outside the already existing form.

1 Comment

That did the trick, thanks Guffa! Never would have thought to check for nested forms...

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.