更改表单提交位置

时间:2017-05-21 07:22:44

标签: javascript php html

我想要更改提交表单的位置,因为我希望用户选择一个域但是当我提交表单时它没有工作,当我提交表单而没有下拉列表时它工作

我的HTML:

<form method="post" action="http://order.Freehostnoads.usa.cc/register2.php" id="form1">
<table>
<tr><th style="text-align: left;">Free Subdomain<td><input type="text" name="username" size="30" maxlength="25" onkeyup="return ismaxlength(this)">
<select id="domain" size="1" onChange="javascript:chgAction()">
      <option value="http://order.freehostnoads.usa.cc/register2.php" selected="selected">.freehostnoads.usa.cc</option>
      <option value="http://order.3eehost.usa.cc/register2.php">.3eehost.usa.cc</option>
      <option value="http://order.3eehosting.usa.cc/register2.php">.3eehosting.usa.cc</option>
      <option value="http://order.3eehosting.igg.biz/register2.php">.3eehosting.igg.biz</option>
      <option value="http://order.3eehost.igg.biz/register2.php">.3eehost.igg.biz</option>
      <option value="http://order.3eehosting.flu.cc/register2.php">.3eehosting.flu.cc</option>
      <option value="http://order.3eehost.flu.cc/register2.php">.3eehost.flu.cc</option>
      <option value="http://order.3eehosting.nut.cc/register2.php">.3eehosting.nut.cc</option>
      <option value="http://order.3eehost.nut.cc/register2.php">.3eehost.nut.cc</option>
      <option value="http://order.fg.nut.cc/register2.php">.fg.nut.cc</option>
      <option value="http://order.hs.igg.biz/register2.php">.hs.igg.biz</option>
      <option value="http://order.pw.usa.cc/register2.php">.pw.usa.cc</option>
      </select>

我的javascript:

<script>
function chgAction(){
    $('#form1').attr({'action':$('option:selected').attr('value')});
}
</script>

我希望将此网站放在:http://freehostnoads.usa.cc/free-hosting-signup.php

1 个答案:

答案 0 :(得分:0)

这是有效的(这里是SO)。我将事件处理程序代码移出了标记

分配prop或attr为.prop("name","value")

也许您的免费网站正在删除您的链接。看看&#34; Inspect&#34;和控制台

&#13;
&#13;
$(function() {
  $("#domain").on("change",function() {
    $('#form1').prop('action',this.value);
  });
}).change(); // initialise 
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" action="http://order.Freehostnoads.usa.cc/register2.php" id="form1">
<select id="domain" size="1" >
      <option value="">Please select</option>
      <option value="http://order.freehostnoads.usa.cc/register2.php" selected="selected">.freehostnoads.usa.cc</option>
      <option value="http://order.3eehost.usa.cc/register2.php">.3eehost.usa.cc</option>
      <option value="http://order.3eehosting.usa.cc/register2.php">.3eehosting.usa.cc</option>
      <option value="http://order.3eehosting.igg.biz/register2.php">.3eehosting.igg.biz</option>
      <option value="http://order.3eehost.igg.biz/register2.php">.3eehost.igg.biz</option>
      <option value="http://order.3eehosting.flu.cc/register2.php">.3eehosting.flu.cc</option>
      <option value="http://order.3eehost.flu.cc/register2.php">.3eehost.flu.cc</option>
      <option value="http://order.3eehosting.nut.cc/register2.php">.3eehosting.nut.cc</option>
      <option value="http://order.3eehost.nut.cc/register2.php">.3eehost.nut.cc</option>
      <option value="http://order.fg.nut.cc/register2.php">.fg.nut.cc</option>
      <option value="http://order.hs.igg.biz/register2.php">.hs.igg.biz</option>
      <option value="http://order.pw.usa.cc/register2.php">.pw.usa.cc</option>
      </select>
<form>
&#13;
&#13;
&#13;