/    Sign up×
Community /Pin to ProfileBookmark

dynamic options help

I pieced together this simple dynamic date feature from some other posts. I tried using some scripts from one of the open source libraries but was unable to modify them to my needs most likely because I didn’t understand how they worked. I’m not very competent with JS yet and writing the script myself generally helps me learn it better.

I’m not getting any errors from Firefox, but it is also not producing the days option menu.
Script:

[CODE] function populate(month) {
month = Number(month);
days = new Array();
days[0] = new Array(“January”, 31);
days[1] = new Array(“February”, 28);
days[2] = new Array(“March”, 31);
var root= document.getElementById(‘pdate_d’);
while(root.hasChildNodes()){//removes the old options
root.removeChild(root.childNodes[0])
}
if(month.selectedIndex == 1) {
for(var i = 0; i <= days[0][1]; i++) {
var opt = root.createElement(‘option’);
opt.setAttribute(“name”, i);
opt.setAttribute(“value”, i);
opt.setAttribute(“text”, i);
root.appendChild(opt);

}
}
}[/CODE]

HTML:

[CODE] <td colspan=”3″><select class=”bodytext” name=”pdate_m” type=”text” id=”pdate_m” size=”1″ maxlength=”2″ onChange=”populate(pdate_m.value);” title=”Postdate determines when the event will become active/posted to the BME website.”/>
<option value=”1″>1</option>
<option value=”2″>2</option>
<option value=”3″>3</option>
<option value=”4″>4</option>
<option value=”5″>5</option>
<option value=”6″>6</option>
<option value=”7″>7</option>
<option value=”8″>8</option>
<option value=”9″>9</option>
<option value=”10″>10</option>
<option value=”11″>11</option>
<option value=”12″>12</option>
<option selected=”selected”> </option>
<option value=”” selected=”selected”></option>
</select>
/
<select class=”bodytext” name=”pdate_d” type=”text” id=”pdate_d” size=”1″ maxlength=”2″ />
<option value=”” selected=”selected”></option>
</select>
/
<select class=”bodytext” name=”pdate_y” type=”text” id=”pdate_y” size=”1″ maxlength=”4″/>
<option value=”” selected=”selected”></option>
<option value=”2005″>2005</option>
<option value=”2006″>2006</option>
<option value=”2007″>2007</option>
<option value=”2008″>2008</option>
</select>[/CODE]

Any help would be appreciated. Thanks. Happy New Year!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@bwalker_lt___gt_authorJan 01.2006 — I noticed I forgot to change an old variable in the script. x in the 'set attributes' lines should be i. Script still doesn't work so I still could use some assistance. Sorry for the oversight.
Copy linkTweet thisAlerts:
@bwalker_lt___gt_authorJan 01.2006 — I got it to work (finally). Sorry if anyone wasted much time with this.

[CODE] function populate(month) {
month = Number(month);
days = new Array();
days[0] = new Array("January", 31);
days[1] = new Array("February", 28);
days[2] = new Array("March", 31);
var root = document.getElementById('pdate_d');
while(root.hasChildNodes()){//removes the old options
root.removeChild(root.childNodes[0])
}
if(month == 1) {
for(var i = 1; i <= days[0][1]; i++) {
var opt = document.createElement('option');
opt.setAttribute("name", i);
opt.setAttribute("value", i);
opt.text = i;
root.appendChild(opt);
}
}
}[/CODE]
×

Success!

Help @bwalker_lt___gt_ 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,
)...