开发者

javascript firing event when textbox changes programmatically

I have an application in which server is sending data to client that I need to program. Each string of data is sent to a unique text box. I want to catch this data and format开发者_高级运维 it before displaying depending on state of independent selectable list. I cannot fire an event using onchange as it works only for user's input. Is there an easy way of doing that? I couldn't find one straight solution for this.

<input class="dios" id="diosinput" type="text" value="" data-ref="#source" data-path="/abc/0/input" />


<select class="widthed"> 
<option>Hex</option> 
<option>Binary</option> 
</select>
//my function 

function decToHex(d)
{
var displayHex = d.toString(16);

if(displayHex.length<2) displayHex = '0'+ displayHex;

return '0x'+ displayHex.toUpperCase();
}


Try this:

function fireEvent(element,event) {
  if (document.createEventObject) {
    // dispatch for IE
    var evt = document.createEventObject();
    return element.fireEvent('on'+event,evt)
  } else {
    // dispatch for others
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent(event, true, true ); // event type,bubbling,cancelable
    return !element.dispatchEvent(evt);
  }
}

fireEvent(document.getElementById('InsertIdOfYourInput'), 'change');


There are only two way to change a text box from the server:

  1. When the browser loads the whole page

  2. When the browser sends an AJAX request to the server and replaces the text in the input element

There is no way for a web server to "send data to a text box". You probably mean something else but you're missing the right words to express it.

What I can see from the source is data-ref and data-path. This suggests that AJAX is used to fetch a new value from the server and put it into the DOM.

To change this, look at the whole source code of the page (including all JavaScript code) and look for path or data-path or data('path') or data("path")

If you find the place where the request is made, you will know where to add your own callback.


 function Evaluate() {
        var q1 = document.getElementById("<%=txtqty.ClientID %>").value
}

<asp:TextBox ID="txtqty" runat="server" CssClass="txtclass"  Width="40px" ValidationGroup="AddLoan" onchange="return Evaluate();" >
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜