By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

Pass a select value to javascript function?

100+
P: 219
I know I can pass this.form to a javascript function and that will represent the form I'm working with, but how can I pass an element of the form to the javascript function? I have a select field called selDateTime. I want to pass that element to the function because I'm calling this function a few places throughout my html. I tried just passing the element name but that didn't work.
Oct 11 '07 #1
Share this Question
Share on Google+
5 Replies


10K+
P: 13,264
I know I can pass this.form to a javascript function and that will represent the form I'm working with, but how can I pass an element of the form to the javascript function? I have a select field called selDateTime. I want to pass that element to the function because I'm calling this function a few places throughout my html. I tried just passing the element name but that didn't work.
Do not post questions in the articles section.

Moved to the forum section.
Did you try this.formName.selDateTime?
Oct 11 '07 #2

gits
Expert Mod 5K+
P: 5,390
hi ...

please post some code regarding to your problem ... so that we may have a closer look at it ...

kind regards
Oct 11 '07 #3

100+
P: 219
Do not post questions in the articles section.

Moved to the forum section.
Did you try this.formName.selDateTime?
I'm sorry about that. The articles and forums links should be moved apart....the option list for them are exactly the same so I messed up. Sorry about that. I'll post some of the code I have when I get to work.
Oct 11 '07 #4

100+
P: 219
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function readDateTime(form_name,sel_name){
  3.         var n = form_name.sel_name.selectedIndex; //get selected index value
  4.     var val = form_name.sel_name[n].text; //get selected value
  5.     //alert('You entered: ' + val);
  6.     form_name.refreshDT.value = val;
  7.     alert(form_name.refreshDT.value);
  8.     //window.location.href = window.location.href + '?datetime=' + val;
  9. }
  10. </script>
  11.  
Expand|Select|Wrap|Line Numbers
  1. <cfoutput><form name="eddatetimeFrm" method="post" action=""></cfoutput>
  2.     <SELECT name="ed_dt" onChange="readDateTime(this.form,ed_dt)">
  3.     <cfoutput query="EDV2_dt">
  4.     <cfset ed_date=#DateFormat(date,"mmm dd yy")#>
  5.     <cfset ed_time=#TimeFormat(time,"HH:mm")#>
  6.                 <cfset DT=#ed_date# & ' ' & #ed_time#>
  7.             <option>#DT#</option>
  8.     </cfoutput>
  9.     </SELECT>
  10.     <input type="hidden" name="refreshDT" value="">
  11.     <cfif isDefined("ed_dt")>
  12.         <cfset #CLIENT.ED_Date_Time# = #ed_dt#>
  13.     </cfif>
  14.     <input type="submit" name="dateSub" value="Refresh">
  15.     </form>
  16.  
Mind you, this is Coldfusion, but this did work fine when I wasn't passing values to the function and just used:

eddatetimeFrm.ed_dt......

I want to be able to call the readDateTime function more than once because the above html code is re-used two other times in my html, but with different names for the elements. That's why I want to pass the select name as a variable rather than call the static version. I'm assuming there's an issue with the way I'm passing (ed_dt).
Oct 11 '07 #5

acoder
Expert Mod 15k+
P: 16,027
I'm assuming there's an issue with the way I'm passing (ed_dt).
Yes, there is. Use 'this' (without quotes) instead.
Oct 15 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.