2015-12-18 27 views
1

在我的网站上有一个新的用户将不得不填写的表格,然后将文本信息发送给用户。这是形式的行动看起来如何添加变量到一个表单发布URL用javascript

http://example.com/app_api.php?view=send_sms&&user=username&&pass=password&&message=hello+there+welcome+to+our+group&&sender_id=example&&to=00000000&&key=4 

但由于每个用户的电话号码是不同的,我想用一个替换形式的行动to变量的用户将在文本框输入phone

能谁能帮助我通过

<form id="new_member_sms" name="new_member_sms" method="post" action="http://example.com/app_api.php?view=send_sms&amp;&amp;user=username&amp;&amp;pass=password&amp;&amp;message=hello+there+welcome+to+our+group&amp;&amp;sender_id=example&amp;&amp;to=00000000&amp;&amp;key=4"> 
    <label for="phone"></label> 
    <blockquote> 
    <p> 
     <input name="phone" type="text" id="phone" /> 

    </p> 
    </blockquote> 
</form> 

回答

0

漂亮迷幻的形式通过POST发送,也包括通过行动的查询字符串GET变量,但这里的更换在个电话号码的快速解决方案的jQuery e查询字符串:

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script> 
<script type="text/javascript"> 
$('#new_member_sms').submit(function(){ 
    var formAction = $(this).attr('action'); 
    var newAction = formAction.replace('00000000', $('#phone').val()); 
    $(this).attr('action', newAction); 
}); 
</script>