the_coder_in_me the_coder_in_me - 2 years ago 177
Javascript Question

Append user-inputted URL to action tag in aspx form

I have a value in clientURLTxtBox which is some address such as: http://localhost/ClientServer/ClientPages/ClientHomePage.aspx

I have a form that wants to post certain values to the above URL.

How do I append the user inputed clientURLTxtBox to my action tag in the form?
Basically, I want to achieve this....

<form id="form1" runat="server" method="post" action= ##clientURLTxtBox.Text##>


I am providing the code for additional reference:



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" method="post" action="<%clientURITxtBox.Text %>">




<div>

Hi.. This is the Server Start Page

</div>

<p>
<asp:TextBox ID="clientIDTxtBox" runat="server" Visible="False" Rows="1" style="position: absolute; z-index: 1; left: 237px; top: 53px; right: 1055px" TextMode="MultiLine"></asp:TextBox>
<asp:TextBox ID="clientIDHeader" runat="server" OnTextChanged="clientURITxtBox0_TextChanged" style="position: relative; top: 1px; left: -1px; width: 195px" Visible="False">ClientID:</asp:TextBox>
</p>

<p>
<asp:TextBox ID="clientSecretHeader" runat="server" OnTextChanged="clientURITxtBox0_TextChanged" style="position: relative; top: -16px; left: -4px; width: 195px" Visible="False">Client Secret:</asp:TextBox>
<asp:TextBox ID="clientSecretTxtBox" runat="server" style="position: relative; top: -4px; left: 21px; width: 203px;" Visible="False" TextMode="MultiLine"></asp:TextBox>
<asp:TextBox ID="clientURIHeader" runat="server" OnTextChanged="clientURITxtBox0_TextChanged" style="position: relative; top: 42px; left: -416px; width: 195px" Visible="False">Client URI:</asp:TextBox>
</p>

<p>
<asp:TextBox ID="clientURITxtBox" runat="server" style="position: relative; top: -2px; left: 222px; width: 204px"></asp:TextBox>
</p>
<p>
&nbsp;</p>
<asp:Button ID="SendClientButton" type="submit" runat="server" style="position: relative; top: -1px; left: 61px; width: 145px" Text="SendToClient" Visible="False" />
</form>




Answer Source

Found the answer and seems to be working fine.

<script>
    function myFunc() {
        var action_src =  document.getElementById("clientURITxtBox").value;
        var form1 = document.getElementById('form1');
        form1.action = action_src;
        return action_src;
    }
</script>
<body>
<form id="form1" runat="server" method="post" action="http://localhost/OAuthBasic/ROWebPage/RegisterClient.aspx" onsubmit="myFunc()">

On the server end: Receive the post values by:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.Form["TextBox1"]))
        {
            // whatever operation you want to perform
        }

    }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download