Refreshing a href variable using OnChange of a select list

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Refreshing a href variable using OnChange of a select list

    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 Guest

  2. Similar Questions and Discussions

    1. calling variable in onchange function
      I am using a javafunction (onclick in select) in which i am calling a function in php (thats why i send this to both php and javascript...
    2. Parse problem passing a variable through an a href
      This is probably just a silly error, although I can't see it. I'm wanting to pass a variable I've set through an a href. I know the variable...
    3. Setting a CF variable onChange in <select>
      Hi, How can I compare and a variable when a specific selection is made from a <select> list. ie. The select list looks like this... <select...
    4. Select a list of items into an aliased field when doinga select
      OK I know this is going to sound weird, but I'm wondering if this is possible. I have a task table. (tblTask) These tasks can be assigned to...
    5. Refreshing values in a lookup list
      I am having a problem with refreshing. If the value a user is needing is not on a list, they have to click "add value". They can then type in...
  3. #2

    Default Refreshing a href variable using OnChange of a select list

    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 Guest

  4. #3

    Default Refreshing a href variable using OnChange of a select list

    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 Guest

  5. #4

    Default 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="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 Guest

  6. #5

    Default 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="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 Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139