Submit Your Article Forum Rules

Results 1 to 3 of 3

Thread: Calling a JavaScript on a option Value on a Jump menu

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    2

    Exclamation Calling a JavaScript on a option Value on a Jump menu

    I have a call of a JavaScript working when is call as a href. My problem is I want to trigger that script in a option value on a jump menu.

    Any body have a suggestion to accomplish this JavaScript " javascript:ajax('/Video/Greek/reddress.php','VideoContentArea');"
    as a option value on the jump menu?
    Thanks in advance


    WORKING

    <ul id="test">
    <li><a href="javascript:ajax('/Video/Greek/reddress.php','VideoContentArea');">test</a></li>
    <li><a href="#">Google</a></li>
    </ul>

    NOT WORKING

    <form name="form" id="form">
    <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
    <option value="#">item1</option>
    <option value=<form action="javascript:ajax('/Video/Greek/reddress.php','VideoContentArea');">item2</option>
    <option value="#">item3</option>
    </select>
    </form>






    I have the following function for it

    function MM_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
    }

  2. #2
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,785
    Code:
    <form name="form" id="form">
    <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
    <option value="#">item1</option> 
    <option value= *** <form action="javascript:ajax('/Video/Greek/reddress.php','VideoContentArea'); *** ">item2</option>
    <option value="#">item3</option>
    </select>
    </form>
    OPTION VALUE="%STRING/%URI"

    We cannot put an HTML element (or JavaScript) inside an option attribute value, so *** this *** is an outright syntax error that will never render according to plan.

    In the case of MM_jumpMenu(), the value is a URI which will open a new page in the target window. ('parent' would be the current window.)

    We have no way of knowing what your ajax() function does, so have very little to go on by way of suggesting a solution. We'll need to see more. If you're using AJAX, I hardly think a DW3 script is the way to go. AJAX generally keeps its document scope and jumpMenu() clearly refreshes the page (fresh window object) which means overlays and such get wiped.

    In other words, if we're jumping to another webpage, that page will have to contain the content (and methods) we're jumping to. This was handy in the days before AJAX but became moot in the days following. That's why the only discussion you can find on it is in old MX 4 and earlier threads.

    Look for some newer script would be my suggestion. And definitely work on that syntax in your HTML. Show us more, please, and we might be able to offer more help.

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    2
    Thanks for your reply. Really appreciate it.

    What I'm trying to do, and it works in a regular href, is to load an external php file onto a <div id="MenuContentArea"></div>
    The ajax code below. Could be a jQuery jump menu the solution to call the javascript:ajax function?





    Code:
    var runOnce = 0;
    
    function ajaxBasic(URL,func) {
    	
    	$.ajax({
    	  url: URL,
    	  cache: false,
    	  beforeSend: function(  ) {
    		$("#"+func).html('<img src="/images/loading.gif" border="0" />');
    		},
    	  success: function(html){
    		$("#"+func).html(html);
    	  }
    	});
    
    }
    function ajax(URL,func, frm) {
    	// begin fix
    	if(URL.indexOf('?')==-1){
    		URL= URL+'?rand='+ randomNum();
    	}else{
    		URL= URL+'&rand='+ randomNum();
    	}
    	// end fix
    	var xmlHttp; try {
    	// Firefox, Opera 8.0+, Safari
    	xmlHttp=new XMLHttpRequest();
    	} catch (e) {
    	// Internet Explorer
    	try {
    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	} catch (e) {
    	try {
    	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	} catch (e) {
    	alert("Your browser does not support AJAX!");  
    	return false;
    	}
    	}
    	} xmlHttp.onreadystatechange=function() { 
    		if(xmlHttp.readyState<4) { 
    			ObId = document.getElementById(func)
    			if(ObId){
    				ObId.innerHTML = '<img src="/images/loading.gif" border="0" />';
    			}else{
    				RunFunc = func + "('<img src=\"/images/loading.gif\" border=\"0\" />')";
    				eval(RunFunc);			
    			}
    	
    		}
    		if(xmlHttp.readyState==4) { 
    			ObId = document.getElementById(func)
    			if(ObId){
    				ObId.innerHTML = (xmlHttp.responseText);
    				PanelMenu();
    			}else{
    				RunFunc = func + "('" + escape(xmlHttp.responseText) + "')";
    				eval(RunFunc);	
    				PanelMenu();		
    			}
    	
    		} 
    	} 
    	paramstring = ""
    	if(frm){
    		alert(frm.elements.length);
    		for (var i=0 ; i<frm.elements.length ; i++ ) {
    			paramstring += frm.elements[i].name +"="+ escape(encodeURI(frm.elements[i].value)) + "&"
    		}
    	}
    	method = frm ? "POST" : "GET" ; 
    	xmlHttp.open(method, URL, true); 
    	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
    	xmlHttp.setRequestHeader("Content-length", paramstring.length);
    	xmlHttp.send(paramstring);
    	
    
    }
    function loadContent(url) {	
    	ajax(url,"contentArea") 
    }
    function loadContentLeft(url) {	
    	ajax(url,"contentAreaLeft") 
    }
    function randomNum( min, max ) {
        
        var argc = arguments.length;
        if (argc === 0) {
            min = 0;
            max = 2147483647;
        } else if (argc === 1) {
            throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
        }
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }
    function PanelMenu(){
    	//if(runOnce!=0)return;
    	
    	if ($(".accordion2 .Myheader").length){// check to see if this classes exist.
    		//runOnce =1;
    		//$(".accordion2 .Myheader").eq(2).removeClass("active");
    		//$(".accordion2 .Myheader").eq(2).addClass("active");
    		//$(".accordion2 p").eq(2).show();
    		//$(".accordion2 .Myheader").remove();
    		$(".accordion2 .Myheader").unbind("click");
    		$(".accordion2 .Myheader").click(function(){
    			$(this).next(".MyMenuBody").slideToggle("slow")
    			.siblings(".MyMenuBody:visible").slideUp("slow");
    			$(this).toggleClass("active");
    			$(this).siblings(".Myheader").removeClass("active");
    		});
    		
    		// second child
    		//$(".MyMenuBody .Myheader2").eq(2).addClass("active");
    		$(".MyMenuBody .Myheader2").unbind("click");
    		$(".MyMenuBody .Myheader2").click(function(){
    			$(this).next(".MyMenuBody .MyMenuBody2").slideToggle("slow")
    			.siblings(".MyMenuBody2:visible").slideUp("slow");
    			$(this).toggleClass("active");
    			$(this).siblings(".Myheader2").removeClass("active");
    		});
    	}
    }

Tags for this Thread

Posting Permissions

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