0

I have this script on a mafia game where I have 4 worlds/servers. I have index.php where I want to login directly to one of the servers by selecting it from a option

I have this code and I need to change form action

<form action="/ro1/index.php?action=login" method="post">
<input id="user" name="user" class="text" type="text" value="Name"/><br>
<input name="clear" type="hidden" value="true" />
<input id="password" name="password" type="password" value="Pass"/>

<select id="server_select" class="server_select" name="server">
<option value="/ro1/index.php?action=login" selected >World 1</option>
<option value="/ro2/index.php?action=login">World 2</option>
<option value="/ro3/index.php?action=login">World 3</option>
<option value="/ro4/index.php?action=login">World 4</option>
</select>
<input type="image" src="graphic/index/login1.png" name="submit">
</form>

Hope you understood what I need.

4

1 回答 1

0

最好在服务器上处理用户选择,并在那里执行重定向或根据需要处理操作。但是如果你真的想在客户端处理它,你应该使用 javascript。包含 jQuery 库后,以下内容应该可以工作:

$('#server_select').change(function(){
   $(this).parents('form').attr('action', $(this).val());
});

更具体地说,将以下代码添加到 html 文件的 head 部分。

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>

<script type="text/javascript">
  $('#server_select').change(function(){
    $(this).parents('form').attr('action', $(this).val());
  });
</script>
于 2009-12-19T03:16:32.657 回答