I am writing the BBCodes part to my forums so I have three submit buttons: one for the color picker, one for inserting a typed url and one to actually post the forum.
I am using button with onclick: the url and color picker use a submit button in insert the text into the textarea and the final submit posts the form. When pressing the final submit the following error occurs:
Uncaught TypeError: document.getElementById(...).submit is not a function
ps I have removed the majority of the 's for the simple BBCodes to lessen the amount of code under html.
note: I have another posting class similar to this that hasn't had the bbcodes added yet and the javascript for posting the form works perfectly fine - hence my guess that the 3 submit buttons are causing this.
html:
<form action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>" method="get" name="postingTopicSub" id="postingTopicSub" enctype="multipart/form-data">
<input type="hidden" name="topicID" id="topicID" value="<?php echo $topicID ?>"/>
<div class="post-subject">
Subject:
<input type="text" name="subject" id="subject" />
</div>
<div class="post-addons">
<input type="button" class="bbc_button" name="color" value="Choose a Font Color" onclick="bbstylecolor()" title="Font color: [color=red]text[/color] or [color=#FF0000]text[/color]">
<div id="colour_palette" style="display:none;">
<br>
<input type="color" id="color" value="#ff0000">
<input type="button" name="submit" value="Pick" onclick="bbcolor();">
<br>
</div>
<br>
<input type="button" class="bbc-button" name="bbcode1" value=" " style="background-image:url('../images/BBC/bold.gif');" onclick="bbstyle(1);" title="Bold Text: [b]text[/b]">
<input type="button" class="bbc_button" name="bburl" value=" " style="background-image:url('../images/BBC/url.gif');" onclick="bburl();" title="List item: [url]http://url[/url] or [url=http://url]text[/url]">
<div class="urlforms" id="url_div" style="display:none;">
<br>
<table style="margin: 0 auto;">
<tr>
<td>Enter a site URL:</td>
<td width="200px";><input type="text" id="url_input" placeholder="http://themooliecommunity.com/"></td>
</tr>
<tr>
<td>Optional description:</td>
<td width="200px";><input type="text" id="url_input_title" placeholder="The Moolie Community"></td>
</tr>
</table>
<input type="button" name="submit" value="Insert into message" onclick="bburlpick();">
<input type="button" name="cancel" value="Exit" onclick="bburl();">
<br>
</div>
<br>
<input type="button" class="bbc_button" name="bbcode14" value=" " style="background-image:url('../images/BBC/spoil.gif');" onclick="bbstyle(14);" title="Spoiler: [spoil]Text[/spoil]">
</div>
<div class="post-textarea">
<textarea name="post_text" id="post_text" cols="100" rows="30"></textarea>
</div>
<div class="post-button">
<input type="button" name="submittopic" id = "submittopic" value="Submit" onclick="topicPostSubmit();"/>
</div>
<br>
</form>
Javascript:
Final submit button:
function forumssubmit()
{
var subject = document.getElementById("subject").value;
var text = document.getElementById("post_text").value;
if(subject=="" || text=="")
{
alert('Please fill in the subject and text');
return false;
}
return true;
}
function topicPostSubmit()
{
if(forumssubmit())
{
document.getElementById("postingTopicSub").submit(); //This is where the error is coming
}
}
URL submit button js:
function bburlpick()
{
var e = document.getElementById("url_div");
var text = document.getElementById("post_text").value;
var url = document.getElementById("url_input").value;
var url_title = document.getElementById("url_input_title").value;
if (url_title == "")
{
var bburl = "[url]" + url + "[/url]";
}
else
{
var bburl = "[url=" + url + "]" + url_title + "[/url]";
}
text += bburl;
document.getElementById("post_text").value = text;
document.getElementById("post_text").focus();
e.style.display = "none";
}
Color submit button:
function bbcolor()
{
var text = document.getElementById("post_text").value;
var color = document.getElementById("color").value;
var bbcolor = "[color=" + color + "][/color]";
text += bbcolor;
document.getElementById("post_text").value = text;
document.getElementById("post_text").focus();
}
问题是您以与submit
相同的形式命名了其他按钮,因此错误不是获取.submit()
而是获取对submit button
的引用,当然这些submit button
function
因此请尝试将它们重命名为其他名称,然后尝试
Change
<input type="button" name="submit" value="Pick" onclick="bbcolor();">
to
<input type="button" name="btnSubmit" value="Pick" onclick="bbcolor();">
The issue is that your button is named "submit"
"submit is not a function" means that you named your submit button or some other element submit. Rename the button to btnSubmit and your call will work. Just make sure you re-name all the buttons named "submit", you have quite a few.
Check this out: http://www.chovy.com/javascript/javascript-error-submit-is-not-a-function/
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.