Need help with JavaScript function

         $(function () {
              $("#date2").datepicker({
                  numberOfMonths: 2,
                  showButtonPanel: true
              });
          });

I have above function in the MasterPage.
All my Content pages use the MasterPage.

I need to change above function to pass id of the INPUT box (in this case it is hard-coded as #date2) from Content page.
I think I need to give the name for this function (maybe) and call from Content page (not sure).

I need to execute above function from Content page so that it can assign value to the INPUT box.

How do I code this?

Thanks,
Ashok
LVL 13
AshokAsked:
Who is Participating?
 
dejaanbuCommented:
in all of your content pages, put a specific class for the input boxes that you want to be a datepicker

that is something like this

<input id='mycontrol' class='datePick' type='text'/>

and in master page, you could have

$(function () {
              $(".datePick").datepicker({
                  numberOfMonths: 2,
                  showButtonPanel: true
              });
          });

so that it will make all inputboxes which have 'datePick' as the class  , as a datepicker

0
 
RickCommented:
The best way is to keep the Javascript code in a separate file.

Take a look at this link.
0
 
AshokAuthor Commented:
That article is posted on February 2004.

I am using VS 2010 so it complains that the above is OBSOLETE.

Thanks,
Ashok
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
RickCommented:
Ashok,

It still works (even though it says it is obsolete).
But if you want to use the new way of registering a startup script, just change to this:

Page.ClientScript.RegisterStartupScript(type As System.Type, Key As String, script as String)


For example:

Page.ClientScript.RegisterStartupScript(GetType(Page), "MyScript", "<script>MyFunction();</script>")
0
 
AshokAuthor Commented:
in my aspx page (content page), I have

                    <p>
                        <span class="copy">Returning:</span><br />
                        <input id="date2" class='datePick' type="text" name="firstinput7" size="20" />
                    </p>

and

$(function () {
              $(".datePick").datepicker({
                  numberOfMonths: 2,
                  showButtonPanel: true
              });
          });

but when I click on date2 input box, the calendar does not show up.

Thanks,
Ashok
0
 
AshokAuthor Commented:
in my aspx page (content page), I have

                    <p>
                        <span class="copy">Returning:</span><br />
                        <input id="date2" class='datePick' type="text" name="date2" size="20" />
                    </p>

and

$(function () {
              $(".datePick").datepicker({
                  numberOfMonths: 2,
                  showButtonPanel: true
              });
          });

but when I click on date2 input box, the calendar does not show up.

Thanks,
Ashok
0
 
AshokAuthor Commented:
No answer to my question.
Please close this question.

I have opened another question similar to this for the same problem.

Ashok
0
 
AshokAuthor Commented:
I've requested that this question be deleted for the following reason:

No answer to my question.<br />Please close this question.<br /><br />I have opened another question similar to this for the same problem.<br /><br />Ashok
0
 
dejaanbuCommented:
though u have closed  ur question quickly, i am giving a little suggestion to it.

did u check Firefox ErrorConsole for any js errors ?
0
 
AshokAuthor Commented:
dejaanbu,

I should have checked.  How do I bring it up.  I have never used it.
Do I have to install anything on top of default FireFox?

In any case, my problem is solved with another question at
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27510803.html

Should I just place one jQuery in MasterPage and use only one version of the jQuery?
YES (is the answer).

Thanks,
Ashok
0
 
dejaanbuCommented:
your pbm is already solved. though,

In default firefox (if u have current version), you can see it in Firefox -> Web Developer ->Error Console


further,


i will give u a short description about Firebug.

it is a firefox addon that integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.

from, here you can install it,

https://addons.mozilla.org/en-US/firefox/addon/firebug/
0
 
AshokAuthor Commented:
Need to give points to dejaanbu (last comment after Close request).
0
 
AshokAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.