shortysbest Posted September 24, 2010 Share Posted September 24, 2010 <select class="attendance-presence" id="<?php print $row['id'];?>" onchange="send_attendance(this.value);"> <option selected>--Select--</option> <option value="1">Present</option> <option value="2">Tardy</option> <option value="3">Absent</option> </select> with javascript how would i get the id? like this.id. That won't work though, keeps coming back as undefined. I have a list of these menus so it has to get the id of the one u click on Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 24, 2010 Share Posted September 24, 2010 this.id is exactly what you need. If it is coming back as undefined, then I suspect that $row['id'] doesn't have a value. have you looked at the generated HTML code to validate that the fields have values for the ID paramater? I'd bet money thatthe HTML looks like this: <select class="attendance-presence" id="" onchange="send_attendance(this.value);"> Quote Link to comment Share on other sites More sharing options...
shortysbest Posted September 24, 2010 Author Share Posted September 24, 2010 well no, the id is valid. If i change onchange="send_attendance(this.value);" to onchange="send_attendance(this.value);current_id(this.id);" and have a new function in javascript called current_id() and alert() it it comes out correctly. However the problem is i cannot get the id from one function to the other, and i cannot have a function inside of the other function. Quote Link to comment Share on other sites More sharing options...
DavidAM Posted September 25, 2010 Share Posted September 25, 2010 send_attendance(this.value); Is sending the VALUE of the SELECT tag to your function. It is NOT sending the SELECT tag itself, so you can't get the ID (the VALUE has no ID). Simply send "this" to the function and use this.value in the function as well as this.id onchange="send_attendance(this); I'm no Javascript expert, but that is my opinion on the matter. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.