SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    location.href not working

    I have this code to send my page to a new url:

    parent.location.href = "https://www.mysite.com/mem_res.asp?method=long"+sQueryString;

    but it doesnt work!

    what wrong?

    monkey
    monkey - the rest is history

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    try

    Code:
    window.replace = "https://www.mysite.com/mem_res.asp?method=long"+sQueryString;

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well...replace() is a method of Location, and you pass it a url argument, you don't assign it to one. Only use it if you need to avoid a history entry for the current page. Unless you're in a frameset, you don't need to reference parent - although it just points to window in a stand-alone window and shouldn't do any harm (I'd use top for this).

    What you've posted looks OK....where is sQueryString defined?
    ::: certified wild guess :::

  4. #4
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by adios
    Well...replace() is a method of Location, and you pass it a url argument, you don't assign it to one. Only use it if you need to avoid a history entry for the current page.
    What would be the proper syntax for that?

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ::: certified wild guess :::

  6. #6
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Gracias

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    De nada.
    ::: certified wild guess :::

  8. #8
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still not really sure which I should be using. The history thing is not a problem, so do I still use location.href?

    location.href = "https://www.nhw-wilts.org.uk/cms23nhw/members/mem_results?method=long"+sQueryString;

    If I create a var for the url string and alert it, everything looks fine, but the page does nothing, not even errors!?

    the sQueryString var is created the line before the href is executed.

    Monkey
    monkey - the rest is history

  9. #9
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This problem is very weird! I have found another thread where someone has the same problem:

    http://www.webmaster-talk.com/showthread.php?t=11136

    I also found this, which refers to a problem with form submitting:

    http://groups.google.co.uk/groups?hl...Bnot%2Bworking

    As you can see from my code below, I have a form but not relevant when the javascript is called (I have stripped the code so you should be able to cut and paste it into an editor and use it). It is the last search which doesnt work? Any ideas?

    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>NHW CMS</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function lbClick(criteria) {
    var sSelFrom = "lbLeft"+criteria;
    var sAddBut = "cmdAdd"+criteria;
    var sRemBut = "cmdRemove"+criteria;
    var sButtonId = (event.srcElement.id==sSelFrom) ? sAddBut : sRemBut;
    var oButton = document.getElementById(sButtonId);
    oButton.disabled = false;
    }
    function lbDblClick(criteria) {
    var sSelFrom = "lbLeft"+criteria;
    var sAddBut = "cmdAdd"+criteria;
    var sRemBut = "cmdRemove"+criteria;
    var sButtonId = (event.srcElement.id==sSelFrom) ? sAddBut : sRemBut;
    var oButton = document.getElementById(sButtonId);
    oButton.click();
    }
    function btnClick(criteria) {
    var oButton = event.srcElement;
    var sAddBut = "cmdAdd"+criteria;
    var sSelLeft = "lbLeft"+criteria;
    var sSelRight = "lbRight"+criteria;
    var sFromId = (oButton.id==sAddBut) ? sSelLeft : sSelRight;
    var oFromLB = document.getElementById(sFromId);
    with (oFromLB) {
    var oFromOption = options[selectedIndex];
    var oToOption = oFromOption.cloneNode(true);
    options.remove(selectedIndex);
    var sToLBId = (id==sSelLeft) ? sSelRight : sSelLeft;
    var oToLB = document.getElementById(sToLBId);
    }
    oButton.disabled = true;
    oToLB.appendChild(oToOption);
    }
    function queryBuild(){
    var sSco = scheme_co.checked;
    var sAco = area_co.checked;
    var sRco = regional_co.checked;
    var sDco = district_co.checked;
    var sAId = selAll(lbRightArea);
    var sRId = selAll(lbRightReg);
    var sDId = selAll(lbRightDist);
    var sQueryString = "&sco=" +sSco+ "&aco=" +sAco+ "&rco=" +sRco+ "&dco=" +sDco+ "&aid=" +sAId+ "&rid=" +sRId+ "&did=" + sDId;
    location.href="https://www.mysite.com/members/results.asp?method=long"+sQueryString;
    return true;
    }
    function selAll(selbox){
    var sSelVals = "";
    var oSelLen = selbox.length;
    for (i=0; i<oSelLen; i++){
    sSelVals += selbox.options[i].value + "~";
    }
    sSelVals = sSelVals.slice(0, -1);
    return sSelVals;
    }
    function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    //-->
    </script>
    </head>
    <body onload="MM_preloadImages('../images/search_ov.gif','../images/addmem_ov.gif','../images/home_ov.gif','../images/help_ov.gif','../images/go_ov.gif')">
    <table width="694" border="0" cellpadding="3" cellspacing="0" class="infoTable">
    <tr>
    <td colspan="3">There are three methods to search for members - All
    Members, Narrow Search and Wide Search.&nbsp; Please choose
    one method, enter your criteria and click the relevant 'Go' or 'Search' button</td>
    </tr>
    <tr><td colspan="3"><hr /></td></tr>
    <tr><td colspan="3"><strong>All Members</strong></td></tr>
    <tr>
    <td colspan="3">To view all members for your division, click herea href="results.asp?method=all" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image9','','../images/go_ov.gif',1)"><img src="../images/go_up.gif" alt="Find all members" name="Image9" width="43" height="22" border="0" align="absmiddle" id="Image9" /></a></td>
    </tr>
    <tr><td colspan="3"><hr /></td></tr>
    <tr>
    <td colspan="3"><strong>Narrow Search</strong></td>
    </tr><form name="form1" id="form1" method="get" onsubmit="return false" action="results.asp?<%=Request.Form()%>">
    <tr>
    <td width="153">Members IDinput name="member_id" type="text" id="member_id" size="6" /></td>
    <td nowrap="nowrap">Scheme IDinput name="scheme_code" type="text" id="scheme_code2" /></td>
    <td nowrap="nowrap">Surnameinput name="surname" type="text" id="surname2" /></td>
    </tr>
    <tr>
    <td><a href="javascript:document.form1.submit();" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image12b','','../images/search_ov.gif',1)"><img src="../images/search_up.gif" alt="Start narrow search" name="Image12b" width="64" height="22" border="0" align="absmiddle" id="Image12b" /></a>
    <input name="method" type="hidden" id="method" value="narrow" /></td>
    </tr></form>
    <tr><td colspan="3" class="nowrap"><hr /></td></tr>
    <tr>
    <td colspan="3" class="nowrap"><strong>Wide Search</strong></td>
    </tr>
    <tr>
    <td nowrap="nowrap" class="nowrap">All scheme Coordinators:
    <input name="scheme_co" type="checkbox" id="scheme_co" value="1" /></td>
    <td align="center" class="nowrap">All area Coordinators:
    <input name="area_co" type="checkbox" id="area_co" value="1" /></td>
    </tr>
    <tr>
    <td class="nowrap">All regional Coordinators:
    <input name="regional_co" type="checkbox" id="regional_co" value="1" /></td>
    <td align="center" class="nowrap">All district Coordinators:
    <input name="district_co" type="checkbox" id="district_co" value="1" /></td>
    </tr>
    <tr>
    <td colspan="3" class="nowrap"><table border="0" cellspacing="0" cellpadding="5" class="infoTable">
    <tr><td>Area/td></tr>
    <tr>
    <td><select name="lbLeftArea" size="4" id="lbLeftArea" onclick="lbClick('Area')" ondblclick="lbDblClick('Area')">
    <option value="395">Abbey Mills</option>
    <option value="217">Aldbourne</option>
    <option value="269">Alderbury 1</option>
    <option value="270">Alderbury 2</option>
    <option value="188">All Cannings</option>
    <option value="292">Allington</option>
    <option value="240">Alton Barnes</option>
    <option value="342">Alvediston</option>
    <option value="343">Ansty </option>
    <option value="51">Ashley</option>
    </select></td>
    <td align="center"><input class="but" type="button" value="Add ->" id="cmdAddArea" name="cmdAddArea" disabled="true" onclick="btnClick('Area')">
    <input type="button" class="but" value="<- Remove" id="cmdRemoveArea" name="cmdRemoveArea" disabled="true" onclick="btnClick('Area')">
    </td>
    <td><select name="lbRightArea" size="4" multiple="multiple" id="lbRightArea" onclick="lbClick('Area')" ondblclick="lbDblClick('Area')">
    </select></td>
    </tr>
    <tr><td>Region/td></tr>
    <tr>
    <td><select name="lbLeftReg" size="4" id="lbLeftReg" onclick="lbClick('Reg')" ondblclick="lbDblClick('Reg')">
    <option value="16">Alderbury</option>
    <option value="17">Amesbury</option>
    <option value="7">Bradford On Avon</option>
    <option value="1">Calne</option>
    <option value="2">Chippenham</option>
    <option value="3">Corsham</option>
    <option value="4">Cricklade</option>
    <option value="12">Devizes</option>
    <option value="5">Malmesbury</option>
    <option value="13">Marlborough</option>
    <option value="8">Melksham</option>
    <option value="14">Pewsey</option>
    </select></td>
    <td align="center"><input class="but" type="button" value="Add ->" id="cmdAddReg" name="cmdAddReg" disabled="true" onclick="btnClick('Reg')" />
    <input name="cmdRemoveReg" type="button" disabled="true" class="but" id="cmdRemoveReg" onclick="btnClick('Reg')" value="<- Remove" />
    </td>
    <td><select name="lbRightReg" size="4" multiple="multiple" id="lbRightReg" onclick="lbClick('Reg')" ondblclick="lbDblClick('Reg')">
    </select></td>
    </tr>
    <tr><td>District/td></tr>
    <tr>
    <td><select name="lbLeftDist" size="4" id="lbLeftDist" onclick="lbClick('Dist')" ondblclick="lbDblClick('Dist')">
    <option value="2">West Wiltshire</option>
    <option value="3">Kennet</option>
    <option value="4">Salisbury</option>
    <option value="5">Swindon Urban</option>
    <option value="9">Swindon Rural</option>
    </select></td>
    <td align="center"><input class="but" type="button" value="Add ->" id="cmdAddDist" name="cmdAddDist" disabled="true" onclick="btnClick('Dist')" />
    <input name="cmdRemoveDist" type="button" disabled="true" class="but" id="cmdRemoveDist" onclick="btnClick('Dist')" value="<- Remove" />
    </td>
    <td><select name="lbRightDist" size="4" multiple="multiple" id="lbRightDist" onclick="lbClick('Dist')" ondblclick="lbDblClick('Dist')">
    </select></td>
    </tr>
    </table>
    </td></tr>
    <tr>
    <td colspan="3" class="nowrap"><a href="javascript:;" onClick="queryBuild(); return true;" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image121','','../images/search_ov.gif',1)"><img src="../images/search_up.gif" alt="Start narrow search" name="Image121" width="64" height="22" border="0" align="absmiddle" id="Image12" /></a> <input name="method" type="hidden" id="method" value="wide" /></td>
    </tr>
    </table>
    </body>
    </html>
    monkey - the rest is history

  10. #10
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doesn't it work in any browser? Just a wild guess, maybe you could try this:
    replace function queryBuild(){ with function queryBuild(anchor){
    replace location.href="https://(...)"+sQueryString with anchor.href="https://(...)"+sQueryString
    replace onClick="queryBuild(); return true;" with onClick="return queryBuild(this);"

  11. #11
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Saturn
    Doesn't it work in any browser? Just a wild guess, maybe you could try this:
    replace function queryBuild(){ with function queryBuild(anchor){
    replace location.href="https://(...)"+sQueryString with anchor.href="https://(...)"+sQueryString
    replace onClick="queryBuild(); return true;" with onClick="return queryBuild(this);"
    Woo Hoo! Why? What is this doing and why didn't my way work?

    Cheers

    monkey
    monkey - the rest is history


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •