搜索表单通过内联JavaScript提交帖子数据

时间:2014-01-28 06:31:58

标签: javascript

我正在使用GODADDY电子邮件营销活动进行营销。在这里,我可以使用设计器选项设计自己的html模板。当我添加表单以提供搜索选项时,系统会自动从模板中删除表单标记,然后我无法通过电子邮件进行搜索。但我能够获得表单元素,如输入文本框和提交buttom但不能形成开始和结束标记。

为此我计划编写内联javascript以将发布数据发送到搜索网址。为此,我尝试了一点,但我不熟悉内联JavaScript。

<input name="search" type="text">          

<input class="button" onclick="javascript:document.createElement('form');" type="submit" value="Go">

Javscript模型(根据我创建的想法不工作)

function search() {
        var theForm;
        theForm = document.createElement('form');
        theForm.action = 'search.php';
        theForm.method = 'post';
        var searchVal = document.getElementsByName('search').value;
        newInput1.name = 'searchVal';
        newInput1.value = searchVal;
        theForm.submit();
    } 

预期的内联JavaScript

 <input class="button" onclick="javascript: function(){ var theForm;        theForm = document.createElement('form'); theForm.action = 'search.php';  theForm.method = 'post'; var searchVal = document.getElementsByName('search').value; newInput1.name = 'searchVal';   newInput1.value = searchVal;theForm.submit();}" type="submit" value="Go">

1 个答案:

答案 0 :(得分:0)

如果你的系统真的允许你使用JS,试试这个:

<强> HTML:

<input id="search" name="search" type="text">
<input class="button" onclick="search();" type="submit" value="Go">

<强> JS:

 function search() {
        var theForm;
        theForm = document.createElement('form');
        theForm.action = 'search.php';
        theForm.method = 'post';
        var searchVal = document.getElementById('search').value;
        newInput1 = document.createElement('input');
        newInput1.name = 'searchVal';
        newInput1.value = searchVal;
        theForm.appendChild(newInput1);
        theForm.submit();
    }

或内联:

<input id="search" name="search" type="text">
<input class="button" onclick="var theForm;theForm = document.createElement('form');theForm.action = 'search.php';theForm.method = 'post';var searchVal = document.getElementById('search').value;newInput1 = document.createElement('input');newInput1.name = 'searchVal';newInput1.value = searchVal;theForm.appendChild(newInput1);theForm.submit();" type="submit" value="Go">