Javascript - text field submits to a popup window

断了今生、忘了曾经 提交于 2019-12-11 11:55:48

问题


I need to have this logic

( textfield ) (submit button)

Person enters a string of numbers/letters - if its right; a popup window happens showing a pdf. if its wrong validation happens and they are presented with an error message

I have gotten this to work as a DROP DOWN >> to >> PDF POPUP. But that wont work.

Can anyone help me with this -- spent way to make hours getting the drop to pop working and need to change directions.

note: needs to work in wordpress page + template.

<form style="float:right;">
<table width="369" border="0" align="center" cellpadding="10" cellspacing="0">
 <tr>
 <td><select name="URL" style="font-size:20px;background:yellow;padding:9px 15px;-webkit-      border-radius: 5px;-moz-border-radius: 5px; background: -webkit-gradient(linear, left top, left 25, from(#FFFFFF), color-stop(4%, #000000), to(#FFFFFF)); background: -moz-linear-gradient(top, #FFFFFF, #000000 1px, #FFFFFF 25px);">
 <option value="">Select your number</option>
 <option value="123.pdf">123</option>
 <option value="456.pdf">456</option>
 </select></td>
 <td><p><input type="button" style="padding:9px 15px; background: #617798; border: 0; font-size: 14px; color: #FFFFFF;-webkit-border-radius: 5px;-moz-border-radius: 5px;!important;"   value="Check Number #" onclick="if (this.form.URL.value) window.open(this.form.URL.value, '_blank','toolbar=0','width=30','height=20');" /><br /></td>
 </tr>
 </table>
 </form>

回答1:


HTML:

<form onsubmit="return false;">
    <input type="text"/>
    <input type="submit"/>
</form>
​

Javascript:

$('form').submit(function() {
    if ($('input[type=text]').val() == "some_pdf.pdf") {
        window.open("http://link_to_some_pdf.com/some_pdf.pdf");
    } else if ($('input[type=text]').val() == "some_other_pdf.pdf") {
        window.open("http://link_to_some_other_pdf.com/some_other_pdf.pdf");
    }  else {
        alert("Not a valid PDF! Try again!");
    }
});

jsfiddle: http://jsfiddle.net/vu26C/



来源:https://stackoverflow.com/questions/12015324/javascript-text-field-submits-to-a-popup-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!