Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to reference select/option value in href? 2

Status
Not open for further replies.

wvdba

IS-IT--Management
Jun 3, 2008
465
US
<form name=frm1>
<SELECT NAME="available_classes" SIZE="1">
<OPTION>carpentry</option>
<OPTION>metal works</option>
<OPTION>electrical works</option>
</SELECT>
</form>
..
..
..
..
<a href="enroll_student.asp?class=document.frm1.available_classes.options(frm1.available_classes.options.selectedindex).text "
alt="Enroll student">Enroll a student</a>
how would i pass the value of select class to this href please?
 
Something like:
Code:
<a href="javascript:location.href='enroll_student.asp?class=' + document.frm1.available_classes.options[frm1.available_classes.options.selectedindex].text " alt="Enroll student">Enroll a student</a>

Lee
 
Except you gotta remember that Javascript is case sensitive, unlike VBScript:

selected[red]I[/red]ndex

Lee
 
[tt]<a href="#"
onclick="this.href='enroll_student.asp?class='+document.frm1.available_classes.options[document.frm1.available_classes.options.selectedIndex].text"
alt="Enroll student">Enroll a student</a>[/tt]
 
thanks tsuji & trollacious.
i got it to work. i think my mistake was case sensitivity and brackets instead of parentheses, plus other issues.
cheers.
 
Upon re-read your select options. [1] You should better add "value" attribute to the option tag. If you're happy with the text, add the value exactly the same as the text; [2] Your text(es) have at least some whitespaces, if not other escapable characters. In that case, a partial and easier device is to escape() the text when you want to pass it to the querystring constriction. (Sometimes, knowing half of the story - the client-side - just is not enough. You have to know what is anticipated at the server. The above is meant to supplement some server-side functional spec in the construction of it.)
[tt]
<a href="#"
onclick="this.href='enroll_student.asp?class='+[blue]escape([/blue]document.frm1.available_classes.options[document.frm1.available_classes.options.selectedIndex].text"[blue])[/blue]
alt="Enroll student">Enroll a student</a>
[/tt]
 
Amendment
Misplaced closing parenthesis. A re-take.
[tt]
<a href="#"
onclick="this.href='enroll_student.asp?class='+escape(document.frm1.available_classes.options[document.frm1.available_classes.options.selectedIndex].text[red])[/red]"
alt="Enroll student">Enroll a student</a>[/tt]
 
thanks tsuji
i remember the "value" thing. i ran into problem with this before. the code that i inherited, came like that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top