Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 563
  • Last Modified:

catch selected index onchange event trigger

$event = "window.location='technical-queries.php?jobnumber=".$jobnumber."&id='+this.selectedIndex+';";
      
$html .= '<select name="categories" onclick="this.onchange();" onchange="'.$event.'">'."\n";

I cant get my id value using the above.  Please advise.
0
ellandrd
Asked:
ellandrd
  • 4
3 Solutions
 
Michel PlungjanIT ExpertCommented:
if the ID is the 0 based number of the option then it should work
If it is the value of the selection option you need
this.options[this.selectedIndex].value
0
 
Michel PlungjanIT ExpertCommented:
Too many quotes?

 Question:  $event = "window.location='technical-queries.php?jobnumber=".$jobnumber."&id='+this.selectedIndex;";
0
 
Michel PlungjanIT ExpertCommented:
However if you do the onClick, the user cannot change the dropdown
0
 
Michel PlungjanIT ExpertCommented:
See this:

<script>
 ev = "alert('technical-queries.php?jobnumber=3&id='+this.selectedIndex);";
 html = '<select name="categories" onclick="this.onchange();" onchange="'+ev+'">'+"\n";
 html += '<option value="">Please select'+"\n";
html += '<option value="a">a'+"\n";
html += '<option value="b">b'+"\n";
html += '</select>'+"\n";
alert(html)
document.write(html)
</script>

I would remove the onClick
0
 
ellandrdAuthor Commented:
Thanks Michel.

My original snippet of code had to many quotes to begin with and i also removed the onClick.  It is working nice and smooth now.

Sean
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now