Refreshing a href variable using OnChange of a select list

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Eghbal

    #1

    Refreshing a href variable using OnChange of a select list

    Hi all,
    I'm trying to use the following script:

    <script language="javaS cript">
    function setrepto(){
    document.aForm. repno.value =
    document.aForm. rep.options[document.aForm. rep.selectedInd ex].value;
    }
    </script>

    On the following form (Partly in asp):

    <form name="aForm">
    <select name="rep" OnChange="setre pto();">
    <option value="ALL">Sel ect a Rep Here</option>
    <%
    while not slsrs.eof
    repno = slsrs("SLS#")
    repname = slsrs("SLSNAM") %>
    <option value="<%=repno %>"><%=repname% ></option>
    <%slsrs.movenex t
    wend%>
    </select>
    </form>

    To change the value of 'repno' in the following href, which is on the
    same page:

    <a href="nextpage. asp?rep=<%=repn o%>">Click here</a>

    So basically, as a user changes the selection, the value of repno in
    the above href should change.

    Can't get it to work. Can anyone help?

    TIA,
    Paul
  • Lee

    #2
    Re: Refreshing a href variable using OnChange of a select list

    Paul Eghbal said:[color=blue]
    >
    >Hi all,
    >I'm trying to use the following script:
    >
    ><script language="javaS cript">
    >function setrepto(){
    > document.aForm. repno.value =
    >document.aForm .rep.options[document.aForm. rep.selectedInd ex].value;
    >}
    ></script>
    >
    >On the following form (Partly in asp):
    >
    ><form name="aForm">
    ><select name="rep" OnChange="setre pto();">
    > <option value="ALL">Sel ect a Rep Here</option>
    > <%
    > while not slsrs.eof
    > repno = slsrs("SLS#")
    > repname = slsrs("SLSNAM") %>
    > <option value="<%=repno %>"><%=repname% ></option>
    > <%slsrs.movenex t
    > wend%>
    ></select>
    ></form>
    >
    >To change the value of 'repno' in the following href, which is on the
    >same page:
    >
    ><a href="nextpage. asp?rep=<%=repn o%>">Click here</a>
    >
    >So basically, as a user changes the selection, the value of repno in
    >the above href should change.[/color]

    The repno variable in your HREF attribute is an ASP variable, and so
    only exists on the server before the page is sent to the user's browser.

    The simplest solution may be to replace your onChange handler and your
    link with a button element in your form, whose onClick handler gets the
    current selected value and changes the value of the location object:

    <input type="button"
    value="Click here"
    onclick="locati on.href='nextpa ge.asp?rep='+th is.form.rep.opt ions[this.form.rep.s electedIndex].value">

    Comment

    • GIMME

      #3
      Re: Refreshing a href variable using OnChange of a select list

      Paul,

      Study this example. Paste this html code into a file and view it.

      You'll need to make a javascript function for each rep from in the
      ASP.

      <html><head>
      <SCRIPT LANGUAGE="JavaS cript">
      <!--
      function onChange_Rep(ob ){
      var ii = 0
      var ix = ob.selectedInde x
      var cat_value = ob.options[ix].value
      // hardcoded these categories, can generalize later
      if (cat_value == "0")
      load_SW_urls()
      if (cat_value == "1")
      load_GD_urls()
      }

      function load_SW_urls(){
      // Keep deleting first item til all gone
      while (document.aForm .thread.length)
      document.aForm. thread.options[0] = null
      len = document.aForm. thread.length;
      document.aForm. thread.options[len] = new
      Option("http://www.joinarnold. com", "0",false,t rue)
      len = document.aForm. thread.length;
      document.aForm. thread.options[len] = new
      Option("http://joinarnold.meet up.com", "1",false,t rue)
      }

      function load_GD_urls(){
      // Keep deleting first item til all gone
      while (document.aForm .thread.length)
      document.aForm. thread.options[0] = null
      len = document.aForm. thread.length;
      document.aForm. thread.options[len] = new Option("http://www.aclu.org",
      "0",false,t rue)
      len = document.aForm. thread.length;
      document.aForm. thread.options[len] = new
      Option("http://www.totalrecall 2003.com", "1",false,t rue)
      }

      function button_focus()
      {
      document.aForm. rep.focus()
      }

      function do_onload() {
      load_SW_urls();
      button_focus();
      }

      //-->
      </script>
      </head><body onLoad="do_onlo ad()" bgcolor=efefaaa >
      <center>
      <form name=aForm>
      <table cellpadding=3 cellspacing=0 border=1 bgcolor=silver width=280 >

      <td bgcolor=silver>
      <p>
      <font face="Tacoma, Verdana, Helvetica" size=2>
      <b>Rep</b></font>
      <td bgcolor=silver>
      <p>
      <font face="Tacoma, Verdana, Helvetica" size=2>
      <b>Thread</b></font>
      </tr>

      <tr bgcolor=silver>
      <td valign=top>
      <select name="rep" onChange="onCha nge_Rep(this)" >
      <option value="0">Arnol d Schwarzenegger</option>
      <option value="1">Graay Daviss</option>
      </select>

      <td rowspan=3 valign=top>
      <select name="thread" size=1 >
      <option value="bogus">_ _______________ ____</option>
      </select>
      </tr>


      </table>
      </form>

      </center>
      </body>
      </html>

      Comment

      • Paul Eghbal

        #4
        Re: Refreshing a href variable using OnChange of a select list

        >[color=blue]
        > The simplest solution may be to replace your onChange handler and your
        > link with a button element in your form, whose onClick handler gets the
        > current selected value and changes the value of the location object:
        >
        > <input type="button"
        > value="Click here"
        > onclick="locati on.href='nextpa ge.asp?rep='+th is.form.rep.opt ions[this.form.rep.s electedIndex].value">[/color]

        Lee,
        Thanks for your help. This is a better solution.

        Paul

        Comment

        Working...