开发者

javascript update controls onload

iv'e got 2 html pages one performs a "get" method on the other these pages are duplicates in that they own they both poses a form with the same control types and control names

when i submit my form from the source开发者_如何转开发 page my url string consist of the values appended together after a '?' char

  ....?txtName=era&txtAge=28&gender=male&langHe=on&langEn=on&select=1   

in the detestation page onload i call a function which splits the control names and their values and sets them

        // this is called from <body onload="f();">
        function f() {
        var st = new String(location.search);
        st = st.substring(1, st.length);                        
        var input = st.split('&');

        var value;
        var ctrl;
        var val;
        var _control; 

        for (var i = 0; i < input.length; i++) 
        {
            value = input[i].substring(0, input[i].length);
            ctrl = value.substring(0, value.indexOf('='));
            val = value.substring(value.indexOf('=') + 1, value.length);
            _control = document.getElementsByName(ctrl);                
            _control.value = val; 
        }                                                                        
    }

i debugged this function and checked that every thing is put in to place as it should the problem is that after the value are set to the controls

they do not appear on the page , as if they didn't get set at all

additionally in Google chrome i get a "Aw,Snap!" Error after these actions (Aw Snap happens only when i debug )

i'm new to java-script and i'm guessing there's a problem with the way i'm assigning these values , i tried also just the first control which is a text type input and it also does not get updated .

any idea's on why this doesn't work ? thanks in advance eran.


Try changing the last line to:

_control[0].value = val;

UPDATE:

It would be a lot easier if you used jQuery:

$('[name='+ctrl+']').val(val);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜