/    Sign up×
Community /Pin to ProfileBookmark

JavaScript fails to fire after innerHTML change is made in document?

Hi

just a quickie .. i am adding some very quick drop down filtering for a
job I’m on .. rather than make an extra round trip each time one drop
down changes I am trying to do it all client side by using IE’s
innerHTML property (see code below) .. it works just fine until after
its fired to first time then the code doesnt fire at all .. I am
guessing I maybe need to move the script into the head or something (as
if its in the body and I change the body with client side dhtml it
invalidates the code .. dunno tbh .. and am hoping someone here has a
quick solution for my furrowed brow ..

[code]
<script language=”javascript”>
function filterRoles()
{
var selIndex = document.forms[‘submit_search’].mapid.selectedIndex;
var sel =
document.forms[‘submit_search’].mapid.options[selIndex].value;
var opt = “”;
var roles = [
[“Biomedical Data Sciences”, 1],
[“CDMA TA Representative”, 2],
[“CPDM”, 2],
[“CRF developer”, 1],
[“CSR Contributing Authors”, 1],
[“CSR Contributing Authors”, 2],
[“CSR Coordinating Author”, 1],
[“CSR Coordinating Author”, 2],
[“CSR Lead Author”, 1],
[“CSR Lead Author”, 2],
[“Centrally based monitor”, 1],
[“Clin. Ops. Monitoring staff”, 1],
[“Clinical Matrix Team”, 1],
[“Clinical Matrix Team Leader”, 1],
[“Clinical Publishing”, 1],
[“Clinical Publishing”, 2],
[“Clinical Study Manager”, 1],
[“Clinical Study Manager”, 2],
[“Clinical Trial Supplies”, 1],
[“Commercial Matrix Team Leader”, 1],
[“Commercial Matrix Team Leader”, 2],
[“Contractor/CRO may perform task”, 1],
[“Contractor/CRO may perform task”, 2],
[“Contractor/CRO to Attend Meeting”, 1],
[“Contractor/CRO to Attend Meeting”, 2],
[“Contractor/CRO would perform task”, 1],
[“Contractor/CRO would perform task”, 2],
[“Country Medical Department”, 1],
[“DMPK/Biomet”, 2],
[“External Process”, 1],
[“GCSP”, 1],
[“GCSP”, 2],
[“GHO, CPDM, Genetics, Epidem.”, 1],
[“GHO, CPDM, Genetics, Epidem.”, 2],
[“GRGC”, 1],
[“GRGC”, 2],
[“Global Clinical Supplies Director”, 2],
[“Global Resourcing Grants & Contracts”, 1],
[“Global Study Manager”, 1],
[“Investigator”, 1],
[“Monitor”, 1],
[“Monitor’s supervisor”, 1],
[“Monitor’s supervisor”, 2],
[“NA Clinical Operations rep. on Clinical Matrix Team”, 1],
[“NA and Canada Clinical Operations staff”, 1],
[“NPS Matrix Team Leader”, 2],
[“Project Manager”, 2],
[“Project Statistician”, 1],
[“Project Statistician”, 2],
[“Project Statistician Leads”, 1],
[“Project Statistician Leads”, 2],
[“Protocol Review Group”, 1],
[“Protocol Writer”, 1],
[“Regional Clin. Ops. rep.”, 1],
[“Regional Monitoring Leaders”, 1],
[“Regional Resourcing Contact”, 1],
[“Regional Resourcing Head”, 1],
[“Regional Study Manager”, 1],
[“Responsible Parties identified at Startup meeting”, 1],
[“Responsible Parties identified at Startup meeting”, 2],
[“Safety Assessment”, 2],
[“Safety Board”, 1],
[“Sponsor Signatory”, 1],
[“Study Manager (US)”, 1],
[“Study Managers”, 1],
[“Study Monitor”, 1],
[“Study Monitor”, 2],
[“TA Study Management Head”, 1],
[“Technical Approver”, 1],
[“Territory Development Leaders”, 1],
[“Virology”, 1],
[“Virology”, 2] ];
var _index = 0;
var _count = roles.length;
while (_index < _count)
{
if (roles[_index][1] == sel || sel == “–all–“)
opt += “<option value='” + roles[_index][0] + “‘>” + roles[_index][0]
+ “n”;
_index++;
}
var list = “<select name=’mapid’>n” + opt + “</select>n”;
alert(list);
roles_div.innerHTML = list;
document.forms[‘submit_search’].mapid.onchange = filterRoles;
}

[/code]

cheers muchly

Antony Gorman
Technical Lead
[url=http://www.objectmonkey.com]objectmonkey.com[/url]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisJan 28.2003 — Have you tried just putting the onchange into the select tag?

[font=monospace]var list = "<select name='mapid' onchange='filterRoles()'>n" + opt + "</select>n";[/font]
Copy linkTweet thisAlerts:
@antony_gormanauthorJan 28.2003 — w00t .. totally not the right answer .. but you drew my attention to a very silly swicth of names I'd made in code (bsaically I was replacing one select list with another .. which worked fine .. but then in my client side code I was renaming the new select to the same name as teh one that cuased it to change .. DOH! ..

sorted ..

cheers ?
Copy linkTweet thisAlerts:
@khalidali63Jan 28.2003 — it looks like a tiny logical (Unless I am missing some thing very IE epecific) error to me.

try this

<i>
</i>&lt;script type="text/javascript"&gt;
function filterRoles(){
var opt = "";
var roles = [
["Biomedical Data Sciences", 1],
["CDMA TA Representative", 2],
["CPDM", 2],
["CRF developer", 1],
["CSR Contributing Authors", 1],
["CSR Contributing Authors", 2],
["CSR Coordinating Author", 1],
["CSR Coordinating Author", 2],
["CSR Lead Author", 1],
["CSR Lead Author", 2],
["Centrally based monitor", 1],
["Clin. Ops. Monitoring staff", 1],
["Clinical Matrix Team", 1],
["Clinical Matrix Team Leader", 1],
["Clinical Publishing", 1],
["Clinical Publishing", 2],
["Clinical Study Manager", 1],
["Clinical Study Manager", 2],
["Clinical Trial Supplies", 1],
["Commercial Matrix Team Leader", 1],
["Commercial Matrix Team Leader", 2],
["Contractor/CRO may perform task", 1],
["Contractor/CRO may perform task", 2],
["Contractor/CRO to Attend Meeting", 1],
["Contractor/CRO to Attend Meeting", 2],
["Contractor/CRO would perform task", 1],
["Contractor/CRO would perform task", 2],
["Country Medical Department", 1],
["DMPK/Biomet", 2],
["External Process", 1],
["GCSP", 1],
["GCSP", 2],
["GHO, CPDM, Genetics, Epidem.", 1],
["GHO, CPDM, Genetics, Epidem.", 2],
["GRGC", 1],
["GRGC", 2],
["Global Clinical Supplies Director", 2],
["Global Resourcing Grants &amp; Contracts", 1],
["Global Study Manager", 1],
["Investigator", 1],
["Monitor", 1],
["Monitor's supervisor", 1],
["Monitor's supervisor", 2],
["NA Clinical Operations rep. on Clinical Matrix Team", 1],
["NA and Canada Clinical Operations staff", 1],
["NPS Matrix Team Leader", 2],
["Project Manager", 2],
["Project Statistician", 1],
["Project Statistician", 2],
["Project Statistician Leads", 1],
["Project Statistician Leads", 2],
["Protocol Review Group", 1],
["Protocol Writer", 1],
["Regional Clin. Ops. rep.", 1],
["Regional Monitoring Leaders", 1],
["Regional Resourcing Contact", 1],
["Regional Resourcing Head", 1],
["Regional Study Manager", 1],
["Responsible Parties identified at Startup meeting", 1],
["Responsible Parties identified at Startup meeting", 2],
["Safety Assessment", 2],
["Safety Board", 1],
["Sponsor Signatory", 1],
["Study Manager (US)", 1],
["Study Managers", 1],
["Study Monitor", 1],
["Study Monitor", 2],
["TA Study Management Head", 1],
["Technical Approver", 1],
["Territory Development Leaders", 1],
["Virology", 1],
["Virology", 2] ];
var _index = 0;
var _count = roles.length;
while (_index &lt; _count) {
opt += "&lt;option value='" + roles[_index][0] + "'&gt;" + roles[_index][0]+ "n";
_index++;
}
var list = "&lt;select name='mapid'&gt;n" + opt + "&lt;/select&gt;n";
roles_div.innerHTML = list;
document.forms['submit_search'].mapid.onchange = process;
}
function process(){
var selIndex = document.submit_search.mapid.selectedIndex;
var sel =document.submit_search.mapid[selIndex].value;
alert("Value selected = "+sel)
}
window.onload=filterRoles;


&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form name="submit_search"&gt;
&lt;div id="roles_div"&gt;&lt;/div&gt;
&lt;/form&gt;
Copy linkTweet thisAlerts:
@AntonJan 28.2003 — are you guys making HTML by your selfe?

How?

what programe doyou use to make it?
×

Success!

Help @antony_gorman 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 5.12,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...