Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

javascript - How to exchange value between an input and and asp:textbox controler

how to use something like this :

<asp:TextBox ID="txt_place_name" CssClass="form-control ltr"  ValidationGroup="add" runat="server"></asp:TextBox>

    <input type="text" id="txt_newpl" value="placeName" runat="server" />

and javascript code is :

    <script>
var tmp = document.createElement("input");
tmp.appendChild(document.getElementById('txt_newpl'));

google.maps.event.addListener(marker, "click", function (e) {
    var infoWindow = new google.maps.InfoWindow({
       content: 
       '<div>'+tmp.innerHTML+'</div>'
    })
});

document.getElementById("<%= txt_place_name.ClientID%>").value = txt_java.value;
</script>

I want to transfer the value of the txt_newpl to the txt_place_name. What is my wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you are doing it wrong. You create an element input and then append your textbox to it, after that you try to get value of element input (txt_java.value), which is wrong, you want value of textbox (document.getElementById('txt_newpl').value).

<script>
    // .. rest of the code ...
    document.getElementById("<%= txt_place_name.ClientID%>").value = document.getElementById('txt_newpl').value;
</script>

Also, wouldn't be easy if you add your <asp:TextBox ... /> to the info window to be completed, like this. In this way you won't complicate your code with unnecessary exchange of values.

<asp:TextBox ID="txt_place_name" CssClass="form-control ltr" ValidationGroup="add" runat="server"></asp:TextBox>

<script>
    var tmp = document.createElement("input");
    tmp.appendChild(document.getElementById("<%= txt_place_name.ClientID %>"));

    google.maps.event.addListener(marker, "click", function (e) {
        var infoWindow = new google.maps.InfoWindow({
            content:
            '<div>' + tmp.innerHTML + '</div>'
        })
    });
</script>

You can do this because <asp:TextBox .../> control will be rendered to an html element <input type="text" ... />. This render (transforming) process is happening on sever side.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...