Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5959247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:39:28+00:00 2026-05-22T18:39:28+00:00

So I have the following JavaScript: <script language=JavaScript> function reload(form){ var val=form.profile.options[form.profile.options.selectedIndex].value; self.location=’?profile=’ +

  • 0

So I have the following JavaScript:

<script language=JavaScript>
    function reload(form){
        var val=form.profile.options[form.profile.options.selectedIndex].value;
        self.location='?profile=' + val ;
    }
    function init(){
        var form = document.getElementById("myform");
        document.getElementById("id_profile").onchange = reload(form);
    }
    window.onload = init;
</script>

But then it keeps on reloading itself constantly. Which is expected. But how can I assign reload and pass a function instance to it?

I could do:

<script language=JavaScript>
    function reload(){
        var form = document.getElementById("myform");
        var val=form.profile.options[form.profile.options.selectedIndex].value;
        self.location='?profile=' + val ;
    }
    function init(){
        document.getElementById("id_profile").onchange = reload;
    }
    window.onload = init;
</script>

But what if I have more forms? Or I let say I want to reuse reload on multiple pages with different form names.

I would like to avoid setting onchange in the HTML tag though:

onchange="reload(this.form)"

If this is possible at all?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:39:29+00:00Added an answer on May 22, 2026 at 6:39 pm

    But what if I have more forms?

    You can assign the same function to all the profile elements in the forms, and reference the element that received the change event inside the function using this.

    <script type="text/javascript">
        function reload(){
            // In here, "this" is the element that received the event
    
            var val = this.options[ this.options.selectedIndex ].value;
            self.location='?profile=' + val ;
        }
        function init(){
            var len = document.forms.length;
            while( len-- ) {
                document.forms[ len ].profile.onchange = reload;
            }
        }
        window.onload = init;
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following in a jsp page; <script language=javascript> function ClickMe_Click(){ $.ajax({ type:
I have the following code: <script type=text/javascript> function SubmitForm() { form1.submit(); } function ShowResponse()
I have the following code: <script type=text/javascript> $(document).ready(function() { $(#Save).click(function() { $.post(url, { data:
I have the following JavaScript for show running line: <script type=text/javascript language=javascript> //Change script's
i have following lines included at the bottom of my index.php: <script type=text/javascript language=javascript
So I have code like this: <script language=javascript> $(function(){ function hellothere(strng){ showalert(strng); } function
js undefined error we have the following widget code : index.html <script type=text/javascript language=javascript>
I have the following code in javascript: <script type=text/javascript src=#{facesContext.externalContext.requestContextPath}/js/sample-points.js></script> <script type=text/javascript>//<![CDATA[ var cloudmade
I have the following very simple Javascript-compatible regular expression: <script type=text/javascript id=(.+) src=([^]+)> I
I have the following file file: <html> <head> <title></title> <script type=text/javascript src=/Prototype.js></script> <script type=text/javascript>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.