views:

82

answers:

2

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?

+2  A: 
(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'.

jAndy
@jAndy: I tried to move it into $(document).ready, but no help, unless I reload the page the reverted data is not displayed :(
Panther24
A: 

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!!

Panther24