0

I'm trying to pass a textarea value to the server side. The textarea cant be runat=server though. heres my code:

<script type="text/javascript">
        function replace() {
            //Replace < and > on textarea
            var obj = document.getElementById('recipient_list');
            var str = obj.value;
            str = str.replace(/</i, "(");
            str = str.replace(/>/i, ")");
            obj.value = str;
            alert("rec_lst.value: " + document.getElementById('recipient_list').value);

            //Pass value to server.
            alert("passing to server");
            document.getElementById("ctl00$ContentPlaceHolder1$txtEmails").value = str;
            alert("Passed to server");
            alert("txtEmails.value: " + document.getElementById("ctl00$ContentPlaceHolder1$txtEmails").value);
        }
    </script>

This isn't working though... Any ideas how to fix or better implement this??..

1
  • What exactly is not working? Also, ctl00$ContentPlaceHolder1$txtEmails (among others) looks a lot like a ASP.NET control name, not an id. Maybe try ctl00_ContentPlaceHolder1_txtEmails instead? Commented Apr 11, 2011 at 19:40

2 Answers 2

2

Try this:

var txtEmail = document.getElementById("<%=txtEmails.ClientID%>");
txtEmail.value = str;

However this won't pass anything to the server, just change text box value.

To have it sent to the server user will have to click submit button, or if you have server side button have such code to "auto click" it thus performing post back:

document.getElementById("<%=btnSubmit.ClientID%>").click();
Sign up to request clarification or add additional context in comments.

3 Comments

...OR perform some Ajax action. More complicated though.
@Nova depends what he want to do with the changed value.. :)
Alright, maybe there's an easier way to do what I wanna do. Basically I'm using the plaxo widger so I've a textarea (which can't be runat=server) with an email list which contain "<" and ">". Due security reasons, ASP.net wont take anything with < and >. So, on the javascript function I'm replacing < and > with ( and ). Now, I need to pass whatever is in the textarea to the server so I can get the email addresses.
0

you cant pass value from client to server using JS .

JS is only a client side code.If you can do something like this, Hacking will be so easy :)

one thing you can do is add some text or label control as invisible and assign the value to the control and pass it to server when some event happens.

Sample code

 <asp:TextBox ID="textbox1" runat="server" ></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button"  OnClientClick="callOnEvets()"/>



function callOnEvets()
    {document.getElementById('textbox1').value = 10; }

2 Comments

I tried to do that, somehow it didn't work when I had runat=server on the textbox, any ideas?
you can add an invisible control that can be a runat=server ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.