Refreshing a href variable using OnChange of a select list

Discussion in 'ASP General' started by Paul Eghbal, Sep 15, 2003.

  1. Paul Eghbal

    Paul Eghbal Guest

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

    <script language="javaScript">
    function setrepto(){
    document.aForm.repno.value =
    document.aForm.rep.options[document.aForm.rep.selectedIndex].value;
    }
    </script>

    On the following form (Partly in asp):

    <form name="aForm">
    <select name="rep" OnChange="setrepto();">
    <option value="ALL">Select a Rep Here</option>
    <%
    while not slsrs.eof
    repno = slsrs("SLS#")
    repname = slsrs("SLSNAM")%>
    <option value="<%=repno%>"><%=repname%></option>
    <%slsrs.movenext
    wend%>
    </select>
    </form>

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

    <a href="nextpage.asp?rep=<%=repno%>">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
     
    Paul Eghbal, Sep 15, 2003
    #1
    1. Advertising

  2. Paul Eghbal

    MDW Guest

    I *think* what you're saying is that you'd like to change
    the page when the user makes a selection from that list?
    If that's the case, try this:

    <script language="JavaScript">
    function setrepto()
    {
    var myRep =
    document.aForm.rep.options
    [document.aForm.rep.selectedIndex].value;

    self.location = "nextpage.asp?rep=" + myRep;

    }
    </script>

    You can get rid of the anchor link altogether...


    >-----Original Message-----
    >Hi all,
    >I'm trying to use the following script:
    >
    ><script language="javaScript">
    >function setrepto(){
    > document.aForm.repno.value =
    >document.aForm.rep.options

    [document.aForm.rep.selectedIndex].value;
    >}
    ></script>
    >
    >On the following form (Partly in asp):
    >
    ><form name="aForm">
    ><select name="rep" OnChange="setrepto();">
    > <option value="ALL">Select a Rep Here</option>
    > <%
    > while not slsrs.eof
    > repno = slsrs("SLS#")
    > repname = slsrs("SLSNAM")%>
    > <option value="<%=repno%>"><%=repname%></option>
    > <%slsrs.movenext
    > wend%>
    ></select>
    ></form>
    >
    >To change the value of 'repno' in the following href,

    which is on the
    >same page:
    >
    ><a href="nextpage.asp?rep=<%=repno%>">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
    >.
    >
     
    MDW, Sep 15, 2003
    #2
    1. Advertising

  3. Paul Eghbal

    GIMME Guest

    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="JavaScript">
    <!--
    function onChange_Rep(ob){
    var ii = 0
    var ix = ob.selectedIndex
    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,true)
    len = document.aForm.thread.length;
    document.aForm.thread.options[len] = new
    Option("http://joinarnold.meetup.com", "1",false,true)
    }

    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,true)
    len = document.aForm.thread.length;
    document.aForm.thread.options[len] = new
    Option("http://www.totalrecall2003.com", "1",false,true)
    }

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

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

    //-->
    </script>
    </head><body onLoad="do_onload()" 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="onChange_Rep(this)" >
    <option value="0">Arnold 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>
     
    GIMME, Sep 15, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    489
    =?Utf-8?B?Y2xpY2tvbg==?=
    Aug 4, 2006
  2. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    218
    Harlan Messinger
    Aug 3, 2006
  3. Paul Eghbal
    Replies:
    3
    Views:
    160
    Paul Eghbal
    Sep 18, 2003
  4. kelvlam
    Replies:
    6
    Views:
    374
    kelvlam
    Jul 18, 2006
  5. ruds
    Replies:
    1
    Views:
    113
    David Mark
    Nov 19, 2008
Loading...

Share This Page