开发者

jQuery + IP Validation + Data not reflecting upon reverting until page reload

I'm trying to implement IP address validation on my page.

  1. I have a test box displaying my current IP address
  2. A hidden开发者_运维知识库 variable having the same

I have two buttons Save & the other Revert, On Save the new IP address is written to the DB; on Revert, I need to restore the old IP address from the hidden variable to the visible box.

I'm using the plugin available @ http://mlntn.com/2009/12/30/jquery-ip-address-plugin/ to do my validation.

Here is the

$(function(){
                $('#ipAddress').ipaddress();
});

(function() {
               $('#cancel')
                .button()
                .click(function() {
                    $("#ipAddress").text($("#oldIPAddress").text());
});

This work fine, but my text box ipAddress does not reflect the data until page is refreshed :(

    <s:textfield name="ipAddress[abcd][]" id="ipAddress" cssClass="text ui-widget-content ui-corner-all" label="IP Address" value="%{ipAddress}"/>

<s:hidden name="resIpadd" id="resIpadd" value="%{ipAddress}"/>

Is there a way to get the data to be reflected without refreshing the page?


(function() {
           $('#cancel')
            .button()
            .click(function() {
                $("#ipAddress").text($("#oldIPAddress").text());
});

That code is executed asap, try to move it into

$(document).ready(function(){
}

Since you're accessing several DOM elements, it might be possible that those are just not accessible at the time that code is executed. jQuery's ready() function is fired when the DOM is 'ready'.


The problem was the way its implemented, when we use the plugin

jquery-ip-address-plugin

The IP address text box is split into 4 different text-boxes internally and hence, while reverting it back, we need to use those 4 fields.

Even though I would have created a single textbox, the plugin splits it. I've resolved it.

Thanks for the help!!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜