SitePoint Sponsor

User Tag List

Results 1 to 21 of 21

Hybrid View

  1. #1
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to add two functions with the same onchange?

    Well

    I'm getting an error called "unknown runtime error" (IE), not sure what it is due to, I was wondering if this might be coming because I've tried to set two functions with the same onchange, like

    Code:
    <select name="nlone" id="nlone" onchange="ajaxFunction(); livrFunction();">
    What do u think?
    Thanks.

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    kigoobe, you need to post more code... That is not enough to see what the problem is.

  3. #3
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Pepejeria

    well, the two functions are -

    Code:
    function ajaxFunction(){
    	
    	var ajaxRequest;  // The variable that makes Ajax possible!
    	
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your are using an old browser or you have disabled javascript. In either condition, this code won't work!");
    				return false;
    			}
    		}
    	}
    	// Create a function that will receive data sent from the server
    	ajaxRequest.onreadystatechange = function(){
    		if(ajaxRequest.readyState == 4){
    			var ajaxDisplay = document.getElementById('ajaxDiv');
    			ajaxDisplay.innerHTML = ajaxRequest.responseText;
    		}
    	}
    	box = document.forms[0].nlone;
    	var age = document.getElementById('nlone').value;
    	<? if ($thisq!='') { ?>
    	if (age == '') {
    	age = <?=$thisq?>;
    	} 
    	<? } ?>
    	var queryString = "?q=" + age + "&lv_id=<?=$lv_id?>&sid="+Math.random();
    	ajaxRequest.open("GET", "getlivra.php" + queryString, true);
    	ajaxRequest.send(null); 
    }
    and

    Code:
    function livrFunction(){
    	
    	var ajaxRequests;  // The variable that makes Ajax possible!
    	
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequests = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequests = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequests = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your are using an old browser or you have disabled javascript. In either condition, this code won't work!");
    				return false;
    			}
    		}
    	}
    	// Create a function that will receive data sent from the server
    	ajaxRequests.onreadystatechange = function(){
    		if(ajaxRequests.readyState == 4){
    			var ajaxDisplays = document.getElementById('ajaxLivr');
    			ajaxDisplays.innerHTML = ajaxRequests.responseText;
    		}
    	}
    	boxs = document.forms[0].nlone;
    	var ages = boxs.options[boxs.selectedIndex].value;
    	<? if ($thisq!='') { ?>
    	if (ages == '') {
    	ages = <?=$thisq?>;
    	} 
    	<? } ?>
    	var queryStrings = "?pq=" + ages + "&newnl=<?=$rapportid?>&newnl2=<?=$newnl2?>&newnl3=<?=$newnl1?>&sid="+Math.random();
    	ajaxRequests.open("GET", "getarticle.php" + queryStrings, true);
    	ajaxRequests.send(null); 
    }
    Basically they are same, i've just changed the variable names ...

    Later, I called them with select onchange, as the first post, and getting the "unknown" error. What do you think here?

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There should be no problem calling 2 functions. What does the JavaScript console in Firefox say (it will even link to the error)?

  5. #5
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    let me execute the page in javascript.

  6. #6
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Strange, I've no error in FF. Things are not working properly, but that's another issue, probably i've some error in the php pages still. But on the javascript, there's no error ...

    What is the javascript console of FF btw?

  7. #7
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JavaScript console will show you JavaScript and CSS errors. Most of the CSS errors can be ignored though.

  8. #8
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great, how to get that?

  9. #9
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Found it, great - http://www.mozilla.org/support/firef...oolsjavascript

    .... I've a lot of warnings there (linked to third part CSS files), but no errors.

  10. #10
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will simply need to do it the hard way and debug it putting alerts here and there. To see where it fails.

  11. #11
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm ... right, thanks.

  12. #12
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not much that can be done from here. Could I access this on any URL? I could then have a look.

  13. #13
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's not yet in the url. But I could send you the page as attachment. may be it would be better for u as there's a lot of mixing of php and javascript there.

    I tried to pm u, but there's no link to attach a file there ... very bad!

  14. #14
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, but I wouldn't help much if you sent me the file. An URL would be the proper way.

  15. #15
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well ............. i got the problem at last .......... here is what happened ...

    I was calling the innterHTML in this way ...
    Code:
    <table><div id="mydiv"></div></table>
    I changed that to
    Code:
    <div id="mydiv"><table></table></div>
    Thanks for speaking about the FF, as when I understood this is an IE only problem, I googled, and found this page to solve this. Many thanks again

  16. #16
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, the first example you have is invalid HTML. Maybe that was the problem. Glad it works.

  17. #17
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. BTW, is there a way to know why this is not working in FF, though its working well in IE? By not working, I mean that the div element that should get loaded thro' the AJAX function, is not coming. No error message, simply nothing happening !!!

  18. #18
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm, tricky one. Try alerting?

  19. #19
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I went out yesterday after posting, now I see that u replied just after ... I wish had I waited sometime ...

  20. #20
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, here's the problem.

    I've a select dropdown. Onchange, I'm calling an ajax function (as above) to load something ( a second select dropdown), and someother variables (a second ajax function, as above).

    This works fine in IE, not in FF. Well, that may be less a problem as I am developing that part for the admins and I can tell admins to stick to IE.

    Problem is, when I try to add a second onchange with the second dropdown. Now since the second dropdown is not a part of the html page (and is only presented by a div, which loads the select from another php page), the code breaks. I mean, doesn't work. So, instead of other functions, I tried to add an alert, onchange for the second dropdown. I'm getting an "Object expected" error.

    It seems that since the second dropdown is not physically present in the final html page, and is represented by a div, that's not getting locatable by the javascript. What do u think?

  21. #21
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, that's solved. I had to move one of the ajax function, from inside the div (the php page) to the main page.

    In fact, since I haven't spent too much time learning JS as I did for php and for the fact that JS often doeesn't throw errors as php does, at times JS appears to be more chineese to me ... but after spending some time, it becomes more english ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •