javascript - need help regarding global variables on multiple pages with 1 js file -


on home page have 2 input fields (fromzip , tozip). besides them <a> tag calls function window.open. these 2 inputs should share 1 pop page. pop page allow user choose state , city , resulting zipcode posted on home page. here codes:

front page (html):

<script type="text/javascript" src="/zipcodehelper/groupfunctions.js"></script> <input type="text" name="rfromzip" id="rfromzip" placeholder="from zip code" ></input>                   <a class="zipbutton" id="rfromzip" name="rfromzip" onclick="openpage()">?</a>                                        <input type="text" name="rtozip" id="rtozip" placeholder="to zip code" ></input>                     <a class="zipbutton" id="rtozip" name="rtozip" onclick="openpage2()">?</a> 

js file:

var choice; function openpage() {     choice == "fromzip";     window.open('http://cheapestmovingquote.com/zipcodehelper/residentialfromzip.php', 'popupwindow', 'height=300,width=500,left=500,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=no'); }  function openpage2() {     choice == "tozip";     window.open('http://cheapestmovingquote.com/zipcodehelper/residentialfromzip.php', 'popupwindow', 'height=300,width=500,left=500,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=no'); }  function post_value() {     if (choice == "fromzip") {         alert(window.choice);         window.opener.document.getelementbyid("rfromzip").value = document.getelementbyid("citybox").value;         self.close();     }      if (choice == "tozip") {         alert(window.choice);         //window.opener.document.getelementbyid("rtozip").value = document.getelementbyid("citybox").value;         self.close();     }  } 

so happen is: home->user click button->select city->select state->dropdown generates zip->click submit->value of zip posted on home page. since 2 <a> shares same window.open, don't know how tell script post whether on fromzip or tozip.

its unclear asking, should help.

assignment statements should use single =

function openpage() {     choice = "fromzip";     window.open('http://cheapestmovingquote.com/zipcodehelper/residentialfromzip.php', 'popupwindow', 'height=300,width=500,left=500,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=no'); }  function openpage2() {     choice = "tozip";     window.open('http://cheapestmovingquote.com/zipcodehelper/residentialfromzip.php', 'popupwindow', 'height=300,width=500,left=500,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=no'); } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -