/    Sign up×
Community /Pin to ProfileBookmark

Help accessing values

Hello, I am using AJAX to load a control into 2 different spans on a page. I need to know how to get the selected values

I am calling a JS function onclick of the button

[CODE]function get_droplist_users()
{
//need to know how to access each of the values here. An alert would suffice

}[/CODE]

Here is the HTML

[CODE]
<form name=”frm_generic”>….

<tr>
<td valign=”top”>
<span id=”reg_users”><select name=”drp_users” onchange=”createCookie( ‘ActiveUser’, this.options[ this.selectedIndex ].value );”>
<option value=””>– Select a User –</option>
<option value=”2″>Glenn</option>
<option value=”4″>Jef</option>
<option value=”3″ selected=”selected”>Tim</option>
</select>
</span>
</td>
<td>
<span id=”reg_users2″><select name=”drp_users” onchange=”createCookie( ‘ActiveUser’, this.options[ this.selectedIndex ].value );”>
<option value=””>– Select a User –</option>
<option value=”2″ selected=”selected”>Glenn</option>
<option value=”4″>Jef</option>
<option value=”3″>Tim</option>
</select>
</span>
</td>
</tr>
<tr>
<td>
<input class=”btn_Save” name=”btn_Save” id=”btn_Save” onclick=”get_droplist_users();” value=”Save” type=”button”>
</td>
</tr>
[/CODE]

If you can give me a way to alert each of the values of the 2 droplists in my function onclick of the button that would rock. I have tried a few things but really have no idea how to do this using two fields of the same name…I was hoping I could get to the value through the different IDs in the spans (reg_users and reg_users2)

Normally I only use this control once on a page and just access the cookie I set, but since I am naming the cookie inside the control itself, I am basically over riding the cookie before it. SO I just want to access the value instead of the cookie in this instance.

Thank you for any help with this

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@tripwaterauthorDec 14.2007 — I figured out my problem and this is how I resolved it.

[CODE]function get_droplist_users()
24 {
25 var elem = document.forms[ 'frm_generic' ].elements;
26
27 var userfrom = elem[ 0 ];
28 var userto = elem[ 1 ];
29
30 alert(userfrom.options[userfrom.selectedIndex].value);
31
32 alert(userto.options[userto.selectedIndex].value);
33 }
[/CODE]


I just said screw getting to it by id and got to each by their element array
×

Success!

Help @tripwater spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...