简体   繁体   中英

Form not being submitted with javascript

I cant get the form to submit using javascript. any advise ?

Here is the code at the beginning of the form:

<form method="post" name="(Unnamed Form 1)-e449aad6-596f-4806-bbcd-c5186e8b6" action="https://s908318137.t.eloqua.com/e/f2" id="form31" >
<input value="(Unnamed Form 1)-e449aad6-596f-4806-bbcd-c5186e8b6" type="hidden" name="elqFormName"  />
<input value="908318137" type="hidden" name="elqSiteId"  />
<input name="elqCampaignId" type="hidden"  />

Here is the code before <form/>

   <div class="clear"></div>
      <div class="complete-form">Please complete the form before submitting.</div>
      <a href="http://s908318137.t.en25.com/e/er?s=908318137&lid=5&elq=<span class=eloquaemail>recipientid</span>" onClick="document.forms["form31"].submit();">» Submit</a>
</form>

Your submit "button" is a link. The JavaScript starts to submit the form, then the link is followed and the request never goes through.

Use a submit button to submit forms.

Replace

<a href="http://s908318137.t.en25.com/e/er?s=908318137&lid=5&elq=<span class=eloquaemail>recipientid</span>" onClick="document.forms["form31"].submit();">» Submit</a>

With

<input type="submit" value="Submit">

I guess the problem of the quotes:

onClick="document.forms["form31"].submit();"

should be

onClick="document.forms['form31'].submit();"

There are a lot of quotes errors on your code. If you have a string delimited by a double quote ", you must selimit the nested strings with single quotes, or escaped quotes.

Furthermore, you should access the document.forms collection by the name property, not the id property.

document.forms['form31'] will look for a form with name="form31" , while you are using id="form31" .

As a solution you could use document.getElementById('form31').submit(); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM