javascript - Texbox value in popup remains null -


i have php page contains block of code:

echo '<div id="popup" style="display:none">'; echo '<form id="addform" name="addform" method="get">'; echo '<table><tr>'; echo '<td>software name: </td><td><input type="text" id="softwarename"/></td></tr>'; echo '<tr><td>software type:</td><td><input type="text" id="softwaretype"/></td></tr>'; echo '<tr><td>license method:</td><td><input type="text" id="licensemethod"/></td></tr>'; echo '<tr><td><input type="button" value="add" onclick="opener.getadddata();"></td><td></td>'; echo '</tr></table>'; echo '</form>'; echo '</div>'; 

buttan calls createpopup():

echo "<input type='submit' value='add' onclick='createpopup();'/>"; 

i opening div popup using following code:

function createpopup() {           var w = null;         w = window.open('index.php?list=softwarelicenseallocations', 'test', 'height=125,width=300');         w.document.write( $("#popup").html());         w.document.close(); } 

code gets textbox values popup:

function getadddata() {        var softwarename = document.getelementbyid('softwarename').value;//.getelementbyid('softwarename').value;     var softwaretype = document.getelementbyid('softwaretype').value;     var licensemethod =document.getelementbyid('licensemethod').value;              alert(softwarename, softwaretype, licensemethod);             addnew(softwarename,softwaretype,licensemethod);  } 

screenshot:

popup

whenever call getadddata() , insert text in popup box , click button, values remain null.

why happening? how can textbox values?

i using pear php , modified version of openit ( , old asset management cms).

if understand you're trying correctly... perhaps this?

change line (just added window):

echo '<tr><td><input type="button" value="add" onclick="opener.getadddata(window);"></td><td></td>'; 

and add window parameter getadddata function:

function getadddata(window) {        var popupdoc = window.document;     var softwarename = popupdoc.getelementbyid('softwarename').value;//.getelementbyid('softwarename').value;     var softwaretype = popupdoc.getelementbyid('softwaretype').value;     var licensemethod = popupdoc.getelementbyid('licensemethod').value;              alert(softwarename, softwaretype, licensemethod);             addnew(softwarename,softwaretype,licensemethod); } 

when call opener.getadddata in popup, dom methods searching in opener document, , not in popup. need pass popup's window object function, knows should inputs in popup's document.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -