开发者

Trouble setting and retrieving value of hidden input fields of iframe

I am having trouble either to set or retrieve the hidden input fields information of iframe.

On the initial page, I click on "Submit" button to activate showBox function and pass three parameters, name, city, and state successfully. showBox creates a popup box where an iframe should sit on top of the box and do form manipulation. I need to set the value of the three hidden input fields with the value passed from the showBox function. Here is the code for showbox function -

 function showBox(name, city, state)
  {  
    var div = document.createElement('开发者_JS百科div');
    div.style.zIndex = 1;
    div.id = 'box';
    div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
    div.style.top = '20px';
    div.style.left = (width / 2) - (900 / 2) + 'px'; 
    div.style.height = '500px';
    div.style.width = '400px';
    div.style.backgroundColor = 'white';
    div.style.border = '2px solid silver';
    div.style.padding = '20px';
    document.body.appendChild(div);  

    alert("Name: " + name + ", City: " + city + ", State: " + state);

    div.innerHTML = "<iframe id='infopage' src='" + 'info.html' + "' width='100%' height='95%'></iframe>";  

    // set value of the hidden input fields
    var myname = $("#infopage #hiddenname").val(name);
    var mycity = $("#infopage #hiddencity").val(city);
    var mystate = $("#infopage #hiddenstate").val(state);

        // check hidden input fields value - which come back blank so far
    alert("Name from hidden field: " + $("#hiddenname").val() + ", City from hidden field: " + $("#hiddencity").val() + ", State from hidden field: " + $("#hiddenstate").val()); 

    // create close window link
    var a = document.createElement('a');
    a.innerHTML = '<br /><br />Close window';
    a.href = 'javascript:void(0)';
    a.onclick = function() 
    {      
      document.body.removeChild(document.getElementById('box'));
    };

    div.appendChild(a);
  } 

Even though the parameters value got passed to the showBox function successfully, some how I just could not successfully set hidden input fields value with the parameters.

Meanwhile, here is the code for info.html -

<!DOCTYPE html>
<html>
<head>
  <title>Sample person information</title> 
    <style type="text/css" title="currentStyle">        
        @import "css/core.css"; 
    </style>
    <script type="text/javascript" language="javascript" src="js/jquery.js"></script>
    <script type="text/javascript" language="javascript" src="js/jsonreport.js"></script>   
    <script type="text/javascript" src="js/info.js"></script>
</head>
<body>
    <div id="container">
        <div class="full_width big" id="testname">
                <br /> 
            <!--    (it may take a while to load large files) -->
        </div>
        <br />

            <input type="text" name="hiddenname" id="hiddenname" value="" />
            <input type="hidden" name="hiddencity" id="hiddencity" value="" />
            <input type="hidden" name="hiddenstate" id="hiddenstate" value=""/>
            <input id="submit" type="button" value="  Enter  " />

        <div id="AjaxDiv"></div>
    </div>
</body>
</html>

When click on the "Enter" button, an ajax function will be called using the hidden fields value from the iframe. Somehow I have difficult retrieving the hidden input fields value from the iframe also.


from the code you posted here and on fiddler, i see that showbox() is not called, so the iframe is never created?

also try replacing your submit button with this ( to test if it works )

<input id="submit" type="button" onclick="alert(document.getElementById('infopage').src);return false;" value="  Enter  " />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜