HTML, вставьте форму динамически через document.write - PullRequest
1 голос
/ 22 июля 2010

Я пытаюсь вставить форму динамически, используя document.write, но по некоторым причинам форма больше не работает. Вот код, который вызывает javascript http://pastebin.com/iMQ3FxHM, а вот код javascript, который записывает форму http://pastebin.com/vMn9BrKQ. Я использую pastebin, потому что stackoverflow не экранирует теги html, и у меня нет кнопки 1010 или чего-то еще

<script type="text/javascript">
    document.write('<scr' + 'ipt type="text\/jav' + 'ascript"  s' + 'rc="http:\/\/www.a' + 'utotraderuae.net\/mem' + 'bers.j' + 's"><\/sc' + 'ript>');
</script>

<script type="text/javascript">
document.write("<h1>");
document.write("    If you are interested to buy it or if you have any question please contact me through the ");
document.write("");
document.write("form bellow .<\/h1>");
document.write("<p>");
document.write("    <a name=\"contactustop\"><\/a><\/p>");
document.write("<form action=\"http:\/\/autotraderuae.net\/members\/process.php\" id=\"contactus\" method=\"POST\">");
document.write("    <strong><span style=\"font-size: 14px;\"><span style=\"font-family: ");
document.write("");
document.write("arial,helvetica,sans-serif;\"><label for=\"email\">Email *<\/label><\/span><\/span><\/strong><br \/>");
document.write("    <input class=\"textfield\" id=\"email\" name=\"fields[Email]\" style=\"width: 400px;\" type=\"text\" ");
document.write("");
document.write("\/>&nbsp;<\/form>");
document.write("<div class=\"fieldblock\" id=\"fieldblock-comments\">");
document.write("    <span style=\"font-family: arial,helvetica,sans-serif;\"><strong><span style=\"font-size: ");
document.write("");
document.write("14px;\"><label for=\"comments\">Your question<\/label><\/span><\/strong><\/span><br \/>");
document.write("    <textarea class=\"textfield\" cols=\"20\" id=\"comments\" name=\"fields[Comments]\" rows=\"4\" ");
document.write("");
document.write("style=\"width: 400px;\"><\/textarea><\/div>");
document.write("<p>");
document.write("    <button type=\"submit\">Submit<\/button><\/p>");

</script>

Ответы [ 3 ]

1 голос
/ 22 июля 2010

Форма закрывается после первого поля ввода

1 голос
/ 22 июля 2010

Очень странный способ написания формы - происходят ненужные интервалы и шрифты.Объедините с помощью + или \ и напишите форму за один раз.Нет необходимости форматировать форму пробелами, так как HTML игнорирует их

<script type="text/javascript">
var text = '<h1>If you are interested to buy it or if you have any question please contact me through the form below .</h1>'+
'<p><a name="contactustop"></a></p>'+ 
'<form action="http://autotraderuae.net/members/process.php" id="contactus" method="POST">'+ 
'<label for="email" style="font-size: 14px; font-family:arial,helvetica,sans-serif; font-weight:bold">Email *</label><br />'+
'<input class="textfield" id="email" name="fields[Email]" style="width: 400px;" type="text"/>'+
'<div class="fieldblock" id="fieldblock-comments">'+
'<label for="comments" style="font-size: 14px; font-family:arial,helvetica,sans-serif; font-weight:bold">Your question</label><br />'+
'<textarea class="textfield" cols="20" id="comments" name="fields[Comments]" rows="4" style="width: 400px;"></textarea>'+
'</div>'+
'<p><input type="submit"></p>';
'</form>';
document.write(text)
</script>
1 голос
/ 22 июля 2010

Я не вижу закрывающий тег для формы.

Также «ниже» должно быть «ниже»

...