Jump to content

how to get id of select menu?


shortysbest

Recommended Posts

<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

Link to comment
Share on other sites

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);">

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.