2015-07-20 6 views
2

У меня есть форма подписки Feedburner с двумя кнопками, одна для ежедневных новостей и одна для еженедельных новостей. Вопрос в том, как изменить значение скрытого поля ввода с именем 'uri' перед отправкой? Мое решение не работает.Как изменить значение скрытого поля ввода перед отправкой [SOLVED]

Это то, что я пытаюсь использовать:

<form id="feedburner" action="https://feedburner.google.com/fb/a/mailverify" 
    method="post" target="popupwindow"> 
    <p> 
     <input autocomplete="off" value="Enter your email…" 
      onblur="if (this.value == '') {this.value = 'Enter your email…';}" 
      onfocus="if (this.value == 'Enter your email…') {this.value = '';}" 
      type="text" name="email"/> 
     <input type="hidden" name="uri"/> 
     <input type="hidden" name="loc" value="en_US"/> 
    </p> 

    <input type="submit" value="Daily" onsubmit="document.getElementsByName('uri').value = 'androidinfodaily'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfodaily', 'popupwindow'); return true" checked> 

    <input type="submit" value="Weekly" onsubmit="document.getElementsByName('uri').value = 'androidinfoweekly'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfoweekly', 'popupwindow'); return true"> 

</form> 

UPDATE

Спасибо всем, полученные ответы Я установил свой код, и теперь он работает. Это окончательный вариант:

<form id="feedburner" action="https://feedburner.google.com/fb/a/mailverify" 
    method="post" target="popupwindow"> 
    <p> 
     <input autocomplete="off" value="Enter your email…" 
      onblur="if (this.value == '') {this.value = 'Enter your email…';}" 
      onfocus="if (this.value == 'Enter your email…') {this.value = '';}" 
      type="text" name="email"/> 
     <input type="hidden" name="uri" /> 
     <input type="hidden" name="loc" value="en_US"/> 
    </p> 

    <input type="submit" value="Daily" onclick="document.getElementsByName('uri')[0].value = 'androidinfodaily'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfodaily', 'popupwindow'); return true"> 

    <input type="submit" value="Weekly" onclick="document.getElementsByName('uri')[0].value = 'androidinfoweekly'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfoweekly', 'popupwindow'); return true"> 

</form> 

ответ

4

submit event обжигают на элементе формы, кнопки не на отправить, так что используйте click обработчики

Обратите внимание, что подать обжигают только на элементе формы, а не или submit ввод. (Формы представляются, а не кнопки.)

<form id="feedburner" action="https://feedburner.google.com/fb/a/mailverify" 
    method="post" target="popupwindow"> 
    <p> 
     <input autocomplete="off" value="Enter your email…" 
      onblur="if (this.value == '') {this.value = 'Enter your email…';}" 
      onfocus="if (this.value == 'Enter your email…') {this.value = '';}" 
      type="text" name="email"/> 
     <input type="hidden" name="uri"/> 
     <input type="hidden" name="loc" value="en_US"/> 
    </p> 

    <input type="submit" value="Daily" onclick="document.getElementsByName('uri')[0].value = 'androidinfodaily'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfodaily', 'popupwindow'); return true" checked> 

    <input type="submit" value="Weekly" onclick="document.getElementsByName('uri')[0].value = 'androidinfoweekly'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfoweekly', 'popupwindow'); return true"> 

</form> 

Также будет лучше speprate сценарий к функции как

<form id="feedburner" action="https://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow"> 
    <p> 
     <input autocomplete="off" value="Enter your email…" onblur="if (this.value == '') {this.value = 'Enter your email…';}" onfocus="if (this.value == 'Enter your email…') {this.value = '';}" type="text" name="email" /> 
     <input type="hidden" name="uri" /> 
     <input type="hidden" name="loc" value="en_US" /> 
    </p> 
    <input type="submit" value="Daily" onclick="return beforeSubmit('androidinfodaily')" checked /> 
    <input type="submit" value="Weekly" onclick="return beforeSubmit('androidinfoweekly')" /> 
</form> 

затем

function beforeSubmit(type) { 
    document.getElementsByName('uri')[0].value = type; 
    window.open('https://feedburner.google.com/fb/a/mailverify?uri=' + type, 'popupwindow'); 
    return true 
} 
+0

также попробовать http://jsfiddle.net/arunpjohny/bedsaagk/2/ –

+1

Также должно быть 'document.getElementsByName ('uri') [0] .value' как' getElementsByName' возвращает коллекцию –

2

You может иметь обработчик события щелчка для кнопки и изменить тип кнопки на type="button", чтобы он не отправил форму напрямую. Внутри обработчика кликов присвойте balue uri, а затем отправьте форму.

HTML:

<form id="feedburner" action="https://feedburner.google.com/fb/a/mailverify" 
    method="post" target="popupwindow"> 
    <p> 
     <input autocomplete="off" value="Enter your email…" 
      onblur="if (this.value == '') {this.value = 'Enter your email…';}" 
      onfocus="if (this.value == 'Enter your email…') {this.value = '';}" 
      type="text" name="email"/> 
     <input type="hidden" name="uri"/> 
     <input type="hidden" name="loc" value="en_US"/> 
    </p> 

    <input type="button" value="Daily" id="daily"> 

    <input type="button" value="Weekly" id="weekly"> 

</form> 

JQuery:

$(function(){ 
    $('#daily').click(function(){ 
     $('input[name="uri"]').val('androidinfodaily'); 
     window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfodaily', 'popupwindow'); 
     //submit form 
     $('#feedburner').submit(); 
    }); 

    $('#weekly').click(function(){ 
    $('input[name="uri"]').val('androidinfodaily'); 
     window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfoweekly', 'popupwindow'); 
     //submit form 
     $('#feedburner').submit(); 
    }); 
}); 
1

не забудьте [0] для первого элемента:

document.getElementsByName('uri')[0].value = 'androidinfodaily'; 
Смежные вопросы