/    Sign up×
Community /Pin to ProfileBookmark

How to use form parameter in JavaScript

Hi all
This code below is done by JMRKER on this forum.

[code]
<html>
<head>
<title>DD Times</title>
<script type=”text/javascript”>
// From: http://www.webdeveloper.com/forum/showthread.php?t=210346

function PopulateTimes(IDS,selection) {
var AmPm= [‘am’,’pm’];
var Hrs = [12,1,2,3,4,5,6,7,8,9,10,11];
var Qtr = [’00’,’15’,’30’,’45’];
var elem = document.getElementById(IDS);
elem.options.length = 0;
for (var i=0; i<AmPm.length; i++) {
for (h=0; h<Hrs.length; h++) {
for (q=0; q<Qtr.length; q++) {
t = Hrs[h]+’:’+Qtr[q]+AmPm[i];
elem.options[elem.options.length] = new Option(t,t);
}
}
}
elem.selectedIndex = selection;
}
function CheckTimes(ID1,ID2) {
var bt = document.getElementById(ID1);
var et = document.getElementById(ID2);
if (bt.selectedIndex > et.selectedIndex-1) {
et.selectedIndex = bt.selectedIndex+1;
}
}
</script>
</head>
<body>
Start Times:
<select id=”StartTimes” onblur=”CheckTimes(‘StartTimes’,’EndTimes’)”>
<script type=”text/javascript”>PopulateTimes(‘StartTimes’,48)</script>
</select>
End Times:
<select id=”EndTimes” onblur=”CheckTimes(‘StartTimes’,’EndTimes’)”>
<script type=”text/javascript”>PopulateTimes(‘EndTimes’,49)</script>
</select>
</body>
</html>
[/code]

I’m trying to use it again with bit of modification but I’m not quite sure if this is possible. I’m working on JSP pages I’ve passed a textfield ID parameters and received it on other page(jsp) like so;
Code:

[code]<%= request.getParameter(“id”) %>[/code]

I’m gonna use this ID as a [B]StartTime[/B]. How can I use this with [B]StartTime [/B]that is in this JavaScript function so that [B]StartTime [/B]would be what the [B]ID [/B]is and EndTime can be choosen by dropdown box? I hope I’m making sense.

Some help will be most appreciated.
Zed

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JavaServletJan 18.2010 — Use EL and not scriptlet for fetching parameters in JSP.

Form example:
<i>
</i>&lt;select name="StartTimes" id="StartTimes" onblur="CheckTimes('StartTimes','EndTimes')"&gt;
&lt;script type="text/javascript"&gt;PopulateTimes('StartTimes')&lt;/script&gt;
&lt;/select&gt;
End Times:
&lt;select name="EndTimes" id="EndTimes" onblur="CheckTimes('StartTimes','EndTimes')"&gt;
&lt;script type="text/javascript"&gt;PopulateTimes('EndTimes')&lt;/script&gt;
&lt;/select&gt;


JSP requesting parameters example:
<i>
</i>StartTimes = ${param.StartTimes}&lt;br&gt;
EndTimes = ${param.EndTimes}
Copy linkTweet thisAlerts:
@zed420authorJan 18.2010 — Thank you

[B]JavaServerlet [/B]that was a greate help, this is what I end up and worked;
[CODE]function PopulateTimes(IDS)
{
var AmPm= ['am','pm'];
var Hrs = [12,1,2,3,4,5,6,7,8,9,10,11];
var Qtr = ['00','15','30','45'];
var elem = document.getElementById(IDS);
elem.options.length = 0;
for (var i=0; i<AmPm.length; i++)
{
for (h=0; h<Hrs.length; h++)
{
for (q=0; q<Qtr.length; q++)
{
t = Hrs[h]+':'+Qtr[q]+AmPm[i];
elem.options[elem.options.length] = new Option(t,t);
}
}
}
for(i=0;i<document.getElementById(IDS).length;i++)
{
if(document.getElementById(IDS).options[i].value == '${param.id}')
{
document.getElementById(IDS).selectedIndex = i;
document.getElementById('EndTimes').selectedIndex = i+1;
}
}
}
function CheckTimes(ID1,ID2) {
var bt = document.getElementById(ID1);
var et = document.getElementById(ID2);
if (bt.selectedIndex > et.selectedIndex-1) {
et.selectedIndex = bt.selectedIndex+1;
}
}
[/CODE]

Zed
×

Success!

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