JavaScript - Div Onclick Not Running Function
I have an external js file which contains the function which for now opens an alert box. The div on the page should run the function when it is clicked but it isn't.
I have tried changing the function to an alert to check the click event is working and i have tried running the javascript in the address bar Code: javascript:hasFocus(); to ensure it has loaded correctly. Both are working fine and i am getting no errors. Below is a snippet of the code: Code: function hasFocus() { alert("a"); } Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" language="javascript" src="scripts/cms.js"></script> </head> <body> <div id="tab_panel"> <div id="tabs"></div> <div id="content" contenteditable="true" onclick="hasFocus();"></div> </div> </body> </html> Thanks in advance Similar TutorialsHey Guys, Im a PHP developer and am quite new with javascript. I wanted some help on the hyperlink onclick event. Bascially I output a list of a href hyperlinks on a html page that goes all the way to the bottom of the screen. I wanted to add a onclick event to the a href tag that would pust the user right to the top of the page. I want to achieve this using javascript onclick event. Can someone plz point me in the right direction! Thanks, Ket Have spent over 40 hours trying to make something like this work. Any help will be received with profound gratitude. Code: <!-- First, we reference a script whose purpose is to create a space for session variables similar to cookies. Works if it appears early in body of Drupal page, so this is not the issue (Drupal parses pages down for display so there is no user <head> tag). --> <script type="text/javascript" src="sessvars.js"></script> <script language = "javascript"> <!-- We create the variable whichpage because we will be creating a session variable sessvars.whichpage courtesy of the sessvars.js script--> var whichpage; <!-- Next, we create a lookup table: --> var myTable = new Array(); myTable[1] = "001_Front_Cover_jpg.jpg"; myTable[2] = "002_Inside_Front_Cover_jpg.jpg"; myTable[3] = "003_Frontispiece_Design_jpg.jpg"; </script> <!-- Next, we create a table with thumbnails; each thumbnail image is a hyperlink which, onClick, is supposed to run a script assigning a value to sessvars.whichpage, so when Drupal node 23 is reached, it can use the value of sessvars.whichpage to select the array (myTable) element which corresponds to the full-sized picture we want to load. Node 23 also has the lookup array (myTable). The node inserts the snippet contained in the myTable element into a URL of the picture to load. --> <!-- Here we define the table --> <!-- Next, we have a series of hyperlinks which present the table with thumbnails so clicking on the thumbnail assigns a value to sessvars. whichpage and then transfers to the node that uses that value: --> <a href="23" onClick="<script language = 'javascript'> sessvars.whichpage=1; </script>" <img> </img> </a> <a href="23" onClick="<script language = 'javascript'> sessvars.whichpage=2; </script>" <img> </img> </a> <a href="23" onClick="<script language = 'javascript'> sessvars.whichpage=3; </script>" <img> </img> </a> <!-- The problem is that this flat does not work. When we get to node 23 sessvars.whichpage shows as undefined. It used to work when I called a function instead of put the script into each link, but I found there was no simple way to get the value (1,2,3 etc.) to the function --> Is there an answer. Thank you so much in advance. Leon Malinofsky I'm currently working on a project and I am doing a bunch of image switching. I'm having a problem with the following... I have seven medium image objects and one small one. One is at the top and the other 7 are below. When one of the 7 is clicked, it then becomes the one up top and the one up top then takes the place of the image clicked. This needs to be able to happen no matter which of the seven i click. Also when you click one of the seven it runs a script to change 9 other images in the center of the page. this isnt too important because i have it working already. What i have is, each of the seven images run their function that changes the 9 center images and then it runs another function. What i need is for that function to determine which company for example(shaws, lowes, target) the top image belongs to and replace the image that was clicked with the top one. But i also need to replace the NAME="" and ONCLICK="function()" with the proper ones for the original company up top. Please if you can understand what im trying to do let me know, if you need further clarification i can do so. i can draw a picture of what im trying to do or the layout if needed but i cant necessarily show anyone the project due to a non-disclosure. I have changed my event listener around a bit. Basically the "compare_fields" function is running when the "load_doc" function is run. Here is my JavaScript: PHP Code: function load_doc(doc, parent) { document.getElementById(parent).innerHTML = "<h1>Loading...</h1>"; var http = getHTTPObject(); if (http != undefined) { http.onreadystatechange = function() { req_doc(doc, parent, http); }; http.open("GET", doc, true); http.send(""); } } function req_doc(doc, parent, req) { if (req.readyState == 4) {//only if req is loaded if (req.status == 200) {//And if its okay document.getElementById(parent).innerHTML = req.responseText; add_event_listeners(page) } else { document.getElementById(parent).innerHTML = "Error fetching data: " + req.status + "\n" + req.statusText; add_event_listeners(); } } } //Script used to hide elements. Usage: expand(element id) function expand(elm) { var ex = document.getElementById(elm).style.display; if (ex == "none") { var obj = document.getElementById(elm); obj.style.display = "inline"; } else if (ex == "inline") { var obj = document.getElementById(elm); obj.style.display = "none"; } } function check_database(obj) { //Not written yet } //Function to test the password validation, should rewrite in future //to make it multifunctional function compare_fields(obj) { alert("com"); var field2 = obj.split("_"); field2 = document.getElementById(field2[1]+"2"); if (obj == field2) { if (obj.length >= 4) { document.getElementById("pass_status").style.color = "#00CC00"; document.getElementById("pass_status").innerHTML = "OK!"; } else { document.getElementById("pass_status").innerHTML = "Please must be between 5 - 14 characters long! "; document.getElementById("pass_status").style.color = "#FF0000"; } } else { document.getElementById("pass_status").innerHTML = "Passwords do not match!"; document.getElementById("pass_status").style.color = "#FF0000"; } } Global JavaScript: PHP Code: //Get httpobject function getHTTPObject() { var http = false; if (window.XMLHttpRequest) { http = new XMLHttpRequest(); } else if (window.ActiveXObject) { http = new ActiveXObject("Microsoft.XMLHTTP"); } return http; } //This function attaches events to elements. var addEvent = function( elm, evt, fun ) { if ( elm.addEventListener ) { elm.addEventListener( evt, fun, false ); } else if ( elm.attachEvent ) { elm.attachEvent( 'on' + evt, fun ); } else { elm [ 'on' + evt ] = fun; } }; Here is the first form, this contains the button: Code: <div style="border-color:#09C; border-width:1px; border-style:solid;"> <div class="register_button" onClick="load_doc('pages/forms/register_form.php', 'login_form')">Register</div> <h1>Login</h1> <h3>DrawSomething - WordGuesser</h3> <br /> <form id="login" action="php/check_login.php" method="post"> Username<br /><input type="text" name="username" class="text login_field"><br /> Password<br /><input type="password" name="password" class="text login_field"><br /> <input type="submit" value="Login" class="button blue" /> </form> <br /> <h2>Forgot Username/Password?</h2> <span class="expand" onClick="expand('forgot_p')"></span> <form class="forgot_p" action="php/forgot_p.php" method="post" style="display:none;" id="forgot_p"> Email<br /> <h3>Recover username</h3> <input type="text" name="forgot_email" class="text login_field"><br /> <span style=" font-weight:bold; font-size:21px;">- OR -</span><br /> Username<br /> <h3>Recover password</h3> <input type="text" name="forgot_password" class="text login_field"><br /> <input type="submit" value="Recover" class="button" /> </form> </div> Form which is loaded, this is when the "comare_fields" function is run when it shouldn't be. Edit: Oh and here is the PHP script which creates the event listeners. PHP Code: include "js/common.js"; include $js[$page]; //Write JS variables for event listeners $page_listeners = $listeners[$page]; //Check if there are some event listeners for this page if (count($page_listeners) > 0) { ///Start function echo "function add_event_listeners() { "; //Start loop to add event listeners for ($i = 0; $i < count($page_listeners); $i++) { $doc_elm = "document.getElementById('".$page_listeners[$i][1]."')"; echo "addEvent(\"document.getElementById('".$page_listeners[$i][0]."')\", \"".$page_listeners[$i][1]."\", ".$page_listeners[$i][2].");"."\n"; } //End function echo "}"; } Code that is written with the above PHP Code: function add_event_listeners() { addEvent("document.getElementById('reg_username')", "click", check_database); addEvent("document.getElementById('reg_email')", "click", check_database); addEvent("document.getElementById('reg_password')", "click", compare_fields('reg_password')); } And here are global PHP variables: PHP Code: <?php //Define page titles $titles = array( "login" => "Login - DrawSomething", "main" => "DrawSomething - Word Guesser", "admin" => "Administrator" ); //Require JavaScript files when onscreen HTML is selected $js = array( "login" => "js/login_js.js", "main" => "js/main_js.js", "admin" => "js/admin_js.js" ); //Pages to require $pages = array( "login" => "pages/login_page.php", "main" => "pages/main_page.php", "admin" => "pages/admin_page.php" ); //Event listeners to add $listeners = array( "login" => array(array("reg_username", "click", "check_database"), array("reg_email", "click", "check_database"), array("reg_password", "click", "compare_fields('reg_password')") ), ); ?> Hello I am setting up a Javascript function in a page called functions.php function onAddBookmarkPressed() { <? mail("XXXXXXX", "Mail","Bookmark"); ?> } And calling it from another place within the page <div class="barstepimg"><img src="http://staggan.com/my_dir/images/progress_bar/fb_buttons/add_bookmark.gif" onclick="onAddBookmarkPressed();"/></div> I include functions.php in my index.php page... When I run the index.php page the function above runs and emails me... Any idea why? It would be great if anyone can help me with this list-scrolling animation problem. The animation works fine but I want another action to execute only after the animation finishes. Made several unsuccessful attempts, but here is the basic code. Code: function coreAnimate(obj, elm, begin, end, duration, fps) { if(!duration) duration = 1000; if(!fps) fps = 20; begin = parseFloat(begin); end = parseFloat(end); duration = parseFloat(duration); fps = parseFloat(fps); var change = end-begin; var interval = Math.ceil(1000/fps); var totalframes = Math.ceil(duration/interval); var step = change/totalframes; for(i = 1 ;i <= totalframes; i++) { (function() { var frame=i; function inner() { var increase = linearTween(frame, begin, change, totalframes); unit = 'px'; obj.style[elm] = increase+unit; }; timer = setTimeout(inner,interval*frame); }) (); }; }; function linearTween(t, b, c, d) { return c*t/d + b; }; Thanks, Chris Is it possible to set onmouseover only in js file without running the function on html code? P.S. I found a coding thread here but I don't understand it and it's too old (2005 archive). Thank you very much How can I run function neutral() within function front()? Code: <SCRIPT type="text/javascript"> function neutral() { document.getElementById("front").style.color = "silver"; document.getElementById("front").style.cursor = "pointer"; document.getElementById("back").style.color = "silver"; document.getElementById("back").style.cursor = "pointer"; } function front() { / WILL RUN HERE document.getElementById("front").style.color = "rgb(255,215,0)"; document.getElementById("front").style.cursor = "text"; } </SCRIPT> i have an image with an onclick function and parameters 0,1 i want to change the parameters of the onclick function through the same function? Code: <img id="down0" onclick=swap(0,1) /> <javascript> function swap(a,b){ var imgda=document.getElementById('down'+a); imgda.onclick = swap(b,b+1); } </javascript> normally it should change the onclick to swap(1,2) but it remains 0,1 whats happening?? p.s. plz dont tell me about the javascript tag, its just for quick explaining... I guess it is because it is 2am and had a few beers but i cannot get this to work and i know its pretty simple to do - see the code below: Code: {if ""|fn_needs_image_verification == true} {assign var="is" value="Image_verification"|fn_get_settings} <p{if $align} class="{$align}"{/if}>{$lang.image_verification_body}</p> {assign var="id_uniqid" value=$id|uniqid} {literal} <script language="javascript" type="text/javascript"> function reloadCaptcha() { captcha = document.getElementById("captureURLID").src; return captcha += 'reload'; } </script> {/literal} {if $sidebox} <p><img id="verification_image_{$id}" class="image-captcha valign" src="{"image.captcha?verification_id=`$SESS_ID`:`$id`&`$id_uniqid`&"|fn_url:'C':'rel':'&'}" alt="" onclick="this.src += 'reload' ;" width="{$is.width}" height="{$is.height}" /></p> {/if} <p><input class="captcha-input-text valign" type="text" name="verification_answer" value= "" autocomplete="off" /> {if !$sidebox} <img id="verification_image_{$id} captureURLID" class="image-captcha valign" src="{"image.captcha?verification_id=`$SESS_ID`:`$id`&`$id_uniqid`&"|fn_url:'C':'rel':'&'}" alt="" onclick="this.src += 'reload' ;" width="{$is.width}" height="{$is.height}" /> {/if} <img src="{$images_dir}/icons/icon_reload.png" height="25" width="25" alt="Reload Captcha Image" onclick="reloadCaptcha();" class="valign image-captcha" /></p> {/if} now the following works totally fine, when you click the captcha code changes..... "onclick="this.src += 'reload'" you will notice i have added a custom reload button image below this with a onclick calling a custom function "reloadCaptcha(); which i want to reload the captcha image above it - however it is not working, i have done the function so it grabs the src from the element ID, i have added 2 ID's to the IMG but cannot remember if you can have multiple IDs or not which if not could be causing the problem but not 100% sure how to include the smarty code for the generated ID on that image. Any ideas on the code above from having a quick glimps? as the code stands i get the error: Error: captureURL is null Many Thanks I am creating a weather widget for the iphone. The program creates an xml request for a weather feed and then parses the response. Depending on the response different information is displayed. A different icon for each weather pattern. I have all of this working so far. What I want to integrate is the option to refresh the weather when a user taps on the icon. Here is my code: Code: document.getElementByID("weatherIcon").innerHTML="<img src=\"Icon Sets/"+iconSet+"/"+MiniIcons[obj.icon]+iconExt/" border=2 onclick=\"refresh();\">" Code: function refresh() { weatherRefresherTemp(); } I know that the function refresh works because it is called from another function that allows the refresh to happen automatically every 30 min. However, wanting to integrate an option to manually refresh I am trying to do it this way. The code never seems to fire, nothing happens. I've added the border option for testing and don't even see that. I've been using a javascript editor and I do not get any errors. Any suggestions would be greatly apprectiated. I'm having a small issue with being able to use the onclick more than once. When I load the page and click the link the request works fine the first time. But if I cancel the request then goto click the link again, nothing happens. Code: <a href="javascript:void();" onclick="sendRequest()">Send the request</a> <script> var request = { method: 'postrequest', message: 'You will like it', data: '123key' }; function sendRequest() { postReq(request, function (a) { if (a && a.post_id) { //Do something if sent } else { //Do something if cancelled } }) } </script> Hi guys. I have made a PHP script that queries a database and uses the reponse to display multiple radio boxes (using a while loop). What I would like to do is have the page URI updated when a radiobox is clicked, without the user having to press on a "Submit" button or something. This is where Javascript comes into play. As this is a while loop, there is no specific number of responses or prefixed names. I've found a lot of stuff on Google with functions calling ID's, and then if the ID matches do a predefined response. Of course that wouldn't work in this situation, and to be frank I don't need anything near as complex. What I'm looking to do is call a Javascript function to redirect the page to "...?location=<get location from PHP var>&id=<get ID from checkbox ID/name>". When the page reloads, I can then use the PHP $_GET["id"] function to display data. It sounds SO simple in theory! Can anyone help? What i've done (and failed): Code: echo "<form>"; while ($explode_count_dec > "0"): $while_query = mysql_query("SELECT * FROM printers WHERE ID LIKE '$explodedata[$explode_number]'"); $while_result = mysql_fetch_assoc($while_query); echo "<input type='radio' value='".$explodedata[$explode_number]."' name='printer' onClick='showmore(".$explode_number.")' />".$while_result["Model"]." <BR /> "; ++$explode_number; --$explode_count_dec; endwhile; echo "</form>"; and the JS: Code: <script type="text/javascript"> function showmore($text) { var room = "<?= $get_location; ?>"; window.location = "?location=" + room + "&id=" + <?php $text; ?> // Couldn't do just $text here? I wish I knew JS.. } </script> The following coding works in Konqueror 3.5.10 on Ubuntu 8.04.3 LTS but not on Firefox 3.0.10 Linux/3.5.7 XP, Opera 10.10 Linux or IE8 XP. I can't see why but it may be to do with the recursion (showtable calls onclick calls addit which calls showtable ...). Somehow it is not seeing the addit routine the second time round. It is meant just to add a line. Eventually it needs to be a complex table but this is for illustration. There are other ways to solve this but this would be the simplest - if it worked! What happens is that one line is added OK but then it chokes. This is what makes me think it is the recursion but I can't see otherwise how to make it write the updated text. I realise I should have a document.close() in it as well and I have tried adding <![CDATA[ ... ]]> as well. Other than in Konqueror, it gives an error message saying object not found (in IE8) or more explicitly: Code: function onclick(event){ addit(4); } with 'addit is not defined' in Firebug. In Konqueror it works sweetly. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> <head> <script language='Javascript' type='text/javascript'> if(typeof(sections) == 'undefined'){ var sections=['Text 0','Text 1','Text 2']; } function addit(ilocal){ sections.splice(sections.length,0,'Text '+ilocal); showtable(); } function showtable(){ var i,j,ip1; for(i=0;i<sections.length;i++){ ip1=i+1; document.write('Section ',i,': ',sections[i],'<br>'); } document.write("<input type='button' value='Add' onClick='addit(",ip1,")' /><br>"); for(j=0;j<sections.length;j++){document.write(sections[j]," ");} } </script> </head><body> <script language='Javascript' type='text/javascript'> showtable(); </script> </body> </html> Clues would be very much appreciated - my baldness coefficient is increasing daily! Hello and thanks for letting me on this forum! Im pretty new to JScript and I am still getting used to it all. I am trying to make a Website that allows values to be selected from one form, transferred to the next form as a summary and then completed. The values are sent to the page fine but my Validation is broken. Here is my LINK code In the Form Code: <form id="Tickets" onsubmit="return ValidateForm()" action="Details.html"> And in the Submit Button Code: <input type="submit" id="OrderTickets" value="Order Tickets" onclick="return ValidateForm()" > My validation is as follows Code: <script type = "text/javascript"> function ValidateForm() { if( document.getElementById('DepartingStation').selectedIndex == " ") { alert( "Please provide a Departing Station!" ); document.getElementById('DepartingStation').focus() ; return false; } if( document.getElementById('ArrivingStation').selectedIndex == " ") { alert( "Please provide an Arriving Station!" ); document.getElementById('ArrivingStation').focus() ; return false; } var Depart = document.getElementById('DepartingStation').value; var Arriv = document.getElementById('ArrivingStation').value; if( Depart==Arriv){ alert( "Train cannot depart and arrive at the same station!" ); return false; } if ( document.getElementById('ReturnTravel').checked=true; { var valueDate = document.getElementById('OutwardDate').value; if ( valueDate== null || valueDate== '') { alert('Please provide an Outward Travel Date!'); return false; } } var valueRetDate = document.getElementById('ReturnDate').value; if ( document.getElementById('ReturnTravelType').checked==true && (valueRetDate== null || valueRetDate== '' )) { alert('Please provide a Return Travel Date!'); return false; } } Id appreciate any help anyone can share on this! Thanks. Hi, I want to call a javascript function without having a button click and it is nestled within php. I have the function OpenChat() in my main page - this works fine. I have the below sub page that is called by an onclick event (originally I had the script launch through a button but I am over loading my server at the moment and need to find a different way to call the function). So I tried the below, which doesn't work. The function just isn't working. My script is: PHP Code: <?php session_start(); if (!(isset($_SESSION['login']) && $_SESSION['login'] !='')){ header ("Location: Welcome.php"); } $SMyPId=$_SESSION['MyPId']; include("dbconnect.php"); $result = mysql_query("SELECT (chatterspace) FROM chat WHERE chatter='{$SMyPId}' AND EndDate IS NULL group by chatterspace"); while($row = mysql_fetch_array($result)){ $oak = $oak . ';' . $row['chatterspace']; } $beach=explode(";",$oak); $divonecount=$beach[1]; $divtwocount=$beach[2]; $divthreecount=$beach[3]; $divfourcount=$beach[4]; $divfivecount=$beach[5]; if($divonecount=='chat1'){ $chat1='full'; }else if($divtwocount=='chat1'){ $chat1='full'; }else if($divthreecount=='chat1'){ $chat1='full'; }else if($divfourcount=='chat1'){ $chat1='full'; }else if($divfivecount=='chat1'){ $chat1='full'; }else if($divonecount=='chat2'){ $chat2='full'; }else if($divtwocount=='chat2'){ $chat2='full'; }else if($divthreecount=='chat2'){ $chat2='full'; }else if($divfourcount=='chat2'){ $chat2='full'; }else if($divfivecount=='chat2'){ $chat2='full'; }else if($divonecount=='chat3'){ $chat3='full'; }else if($divtwocount=='chat3'){ $chat3='full'; }else if($divthreecount=='chat3'){ $chat3='full'; }else if($divfourcount=='chat3'){ $chat3='full'; }else if($divfivecount=='chat3'){ $chat3='full'; }else if($divonecount=='chat4'){ $chat4='full'; }else if($divtwocount=='chat4'){ $chat4='full'; }else if($divthreecount=='chat4'){ $chat4='full'; }else if($divfourcount=='chat4'){ $chat4='full'; }else if($divfivecount=='chat4'){ $chat4='full'; }else if($divonecount=='chat5'){ $chat5='full'; }else if($divtwocount=='chat5'){ $chat5='full'; }else if($divthreecount=='chat5'){ $chat5='full'; }else if($divfourcount=='chat5'){ $chat5='full'; }else if($divfivecount=='chat5'){ $chat5='full'; } $result = mysql_query("SELECT * FROM allusers WHERE PId='{$mulberry}'"); while($row = mysql_fetch_array($result)){ $nosegay=rand(). rand(). rand(). rand(). rand(); $nightshade="{$SMyPId};{$mulberry};{$row['fullname']};{$nosegay}"; $elm=$row['pphoto']; $helmlock=$row['fullname']; } $poplar=$_POST['chat']; if($chat1 !=='full'){ echo '<script type="text/javascript"> function This(){ OpenChat(\'chatheader1.php\',\'chat1\',\'chat=' . $poplar . '\',\'ChatID=0\',\'getDisplayChat1.php\',\'ChatDisplayOne\',\'getThisChat1.php\',\'displaytalkOne\',\'artemis=' . $poplar . '\')"; alert("chat1"); } </script>'; }elseif($chat2 !=='full'){ echo '<script type="text/javascript"> function This(){ OpenChat(\'chatheader2.php\',\'chat2\',\'chat=' . $poplar . '\',\'ChatID=0\',\'getDisplayChat2.php\',\'ChatDisplayTwo\',\'getThisChat2.php\',\'displaytalkTwo\',\'artemis=' . $poplar . '\')"; alert("chat2"); } </script>'; }elseif($chat3 !=='full'){ echo '<script type="text/javascript"> function This(){ OpenChat(\'chatheader3.php\',\'chat3\',\'chat=' . $poplar . '\',\'ChatID=0\',\'getDisplayChat3.php\',\'ChatDisplayThree\',\'getThisChat3.php\',\'displaytalkThree\',\'artemis=' . $poplar . '\')"; alert("chat3"); } </script>'; }elseif($chat4 !=='full'){ echo '<script type="text/javascript"> function This(){ OpenChat(\'chatheader4.php\',\'chat4\',\'chat=' . $poplar . '\',\'ChatID=0\',\'getDisplayChat4.php\',\'ChatDisplayFour\',\'getThisChat4.php\',\'displaytalkFour\',\'artemis=' . $poplar . '\')"; alert("chat4"); } </script>'; }elseif($chat5 !=='full'){ echo '<script type="text/javascript"> function This(){ OpenChat(\'chatheader5.php\',\'chat5\',\'chat=' . $poplar . '\',\'ChatID=0\',\'getDisplayChat5.php\',\'ChatDisplayFive\',\'getThisChat5.php\',\'displaytalkFive\',\'artemis=' . $poplar . '\')"; alert("chat5"); } </script>'; }else{ echo '<script type="text/javascript"> function This(){ alert("You have reached your IM capacity, please close a chat box"); } </script>'; } mysql_close($con); ?> this is my html page.. Code: <html> <head> <script type="text/javascript" language="JavaScript"> function general_formats() { window.open('http://www.test.com/general_formats.php'); } </script> </head> <body> <a href="general_formats.php"><onclick="general_formats(); return false">General Formats</a> </body> </html> When i click ' general Formats ' , a window is opened , i dont need that . What i need is , when i click the link , it should direct to general_fomats.php.. please help me to solve it . .any help will be appreciated . This is hopefully a simple fix and I hope someone can help me out, I'm pretty new at coding. I have a form on an html page and I want to make it so when a button is clicked, it adds one to the input to the right of it, and when a button to the right of the input is clicked, it will delete one to the left of that button. I don't want to resort to making a new function for each and every form, because there will be a lot. Here is the form and input parts: Code: <form name="calculate"> <input type="button" onClick="add()" /> <input name="result" type="input" readonly="readonly" value="0" /> <input type="button" onclick="sub()" /> </form> Here is what the function code looks like: Code: function add() { var add = 1 * calculate.name.value; add = add + 1; calculate.name.value = add; } function sub() { var add = 1 * calculate.name.value; add = add - 1; calculate.name.value = add; } Note: where I called the calculate.name.value, that obviously doesn't work, and I need some way, rather than making multiple functions and changing the name part, to be able to call to a name near the button, if at all possible. Any and all ideas are appreciated, Thanks! Hi there, I am wondering if it is possible to navigate anchor links using a button onclick event. I want next and previous hit buttons to navigate the already existing hits (#hit1, #hit2, etc.). For instance, I have: Code: <script type="text/javascript"> var numHits = {HITS}-1; function nextHit(){ if(numHits > 0){ numHits--; } return("location.href=" '#hit" + numHits + " ' ");//added spaces for visibility } </script> <input type="button" value=">" onclick="nextHit()" /> I have tried onclick="nextHit();", onclick="nextHit(); return true/false", onclick=" return nextHit()" and a bunch of others, with no luck. I have seen working examples with the href tag (e.g. <a href="#" onclick="func();return false">), but nothing with buttons. I also can't seem to get the working href examples to work on my server. For instance, I cannot get this code to work, it just goes to js_required.html: <a href="js_required.html" onclick="doSomething(); return false;">go</a> function doSomething(){ alert("test"); } It seems so simple, I'm assuming I'm missing something very basic. I would greatly appreciate any help! ~Bobio I've been doing some searching and I can't seem to find what I am looking for. I hope someone can help. I am trying to target a link to an iframe window. The catch is that I need to use an onClick function in a TD tag... Here is an example: <TABLE HEIGHT="40" WIDTH="780" CELLSPACING="0" CELLPADDING="0" BORDER="1"> <TBODY> <TR> <TD ALIGN="CENTER">HEADER 1</TD> </TR> <TR> <TD OnClick="location='http://www.ophil.com'" BGCOLOR="#FFFFFF">Ophil</TD> </TR> </TBODY> </TABLE> </TD> </TR> <table width="100%" border="0" cellspacing="0" cellpadding="1"> <tr> <td><a name="bidframe"> <IFRAME SRC="bid_item_instructions.html" TITLE="IFRAME" SCROLLING="no" NAME="bidpage" WIDTH="100%" HEIGHT="450" ALIGN="center" FRAMEBORDER="yes" > </IFRAME> </a></td> </tr> </table> </CENTER> </BODY> </HTML> I need the results of that onclick to appear in the iframe window I have called bidframe... Any ideas? |