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 6771637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:27:20+00:00 2026-05-26T15:27:20+00:00

i’m new into JS. I have done 2 simple functions to change value and

  • 0

i’m new into JS. I have done 2 simple functions to change value and onclick-event for an input-button.

function doAjaxRequest(url, divID, buttonID) {
  $(divID).html('<img src="images/loader.gif" />');
  setTimeout(function(){ $(divID).load(url); }, 600);
  setTimeout(function(){ $(buttonID).attr({
      value: 'Schliessen',
      onClick: 'clear_div(\''+url+'\', '+divID.id+', '+buttonID.id+')'
    });}, 600);
};

function clear_div(url, divID, buttonID) {
    $(divID).empty();
    $(buttonID).attr({
      value: 'Mehr...',
      onClick: 'doAjaxRequest(\''+url+'\', '+divID.id+', '+buttonID.id+')'
    });
};

functions call is

<div id="div1"></div>
<input type="button" id="button1" onClick="doAjaxRequest('test.html', div1, button1);" value="More..."/>

the doctype i’m using for my homepage is

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

the functions both work correctly in IE but in FF they only work if i set the doctype to

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

i also tryed the “loose.dtd” with no effect.

What am i doing wrong with JS?
Hope someone can help me.

Greets
Joe

  • 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-26T15:27:20+00:00Added an answer on May 26, 2026 at 3:27 pm

    The problem is probably that onClick should be onclick (case is significant in attributes in XHTML). But there are a couple of problems.

    1. In your markup here:

      <input type="button" id="button1" onClick="doAjaxRequest('test.html', div1, button1);" value="More..."/>
      

      You haven’t put quotes around div1 or button1, which means you’re relying on the browser dumping those symbols in the global namespace because they’re the IDs of your elements. That’s fairly common (IE and some others do it), but it’s not universal. Instead, I’d pass strings and then look them up properly.

    2. Since you’re using jQuery, there’s no reason to (and several reasons not to) use onclick attributes.

      So:

      function doAjaxRequest(url, divID, buttonID) {
        $('#' + divID).html('<img src="images/loader.gif" />');
        setTimeout(function(){
          $('#' + divID).load(url);
        }, 600);
        setTimeout(function(){
          $('#' + buttonID)
            .attr({value: 'Schliessen'})
            .click(function() {
              clear_div(url, divID, buttonID);
          });
        }, 600);
      }
      
      function clear_div(url, divID, buttonID) {
          $('#' + divID).empty();
          $('#' + buttonID)
            .attr({value: 'Mehr...'})
            .unbind('click')
            .click(function() {
              doAjaxRequest(url, divID, buttonID);
            });
      }
      

      And similarly, your button hookup originally should be:

      $("#button1").click(function() {
        doAjaxRequest('test.html', 'div1', 'button1');
      });
      

      …rather than using the onclick in the HTML. That code needs to appear after the button in the HTML (it’s fairly common to recommend putting script tags at the bottom of the document, just before the closing </body> tag), or you can wrap it in a jQuery ready handler:

      jQuery(function($) {
          $("#button1").click(function() {
            doAjaxRequest('test.html', 'div1', 'button1');
          });
      });
      

      …so it runs only when the DOM has loaded.

    Notes:

    • Now we’re using real functions for the event handlers, and hooking them up in a modern way.
    • We’re using the IDs of the elements, not the global instances of them (which aren’t entirely reliable).
    • We’re using unbind to remove all previous click handlers before adding our new one.
    • There’s no need for a semicolon after a function declaration. Semicolons terminate statements. Function declarations aren’t statements (they’re declarations). That said, putting a semicolon there is harmless. 🙂

    And finally: Rather than removing the old click handler and putting in a new one, I think I’d probably just have the click handler change its behavior based on some flag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.