JavaScript - Generic Way To Execute Javascript
I am wondering if its possible to execute a JavaScript script as soon as the page is loaded? Perhaps a generic execution?
I tried this, but it didn't work: Code: <SCRIPT type="text/javascript"> if (document.forms["form"]["quantitym"].value > '.$row['sizem'].') { alert ("The quantity for product $row['id'] is no longer available."); } </SCRIPT> <FORM action="updatecart.html" method="post" name="form"> <DIV> <B>Medium:</B> <INPUT name="quantitym" value="'.$content['sizem'].'"> </DIV> </FORM> This is for my shopping cart system. The idea is, the customer might have 4 items in his cart, but whilst he was shopping, someone might of bought the same item, result in only 3 being available, but his cart still says 4. My solution to this is to make a script run through out his shopping when ever the cart items are listed and just prior payment execution, if the quantity he wants is no longer available, he will be alerted. $row['sizem'] is PHP drawing how many items there are from my stock database. If the value of the INPUT exceeds this availability, JavaScript shall alert. Does anyone know why it isn't alerting? Similar TutorialsQuote: Originally Posted by mlseim hmmm .... sort of stumped. For a test, I made a script that pulls a random "bumper-sticker" quote out of a file and sends it back as Javascript. Put this on a test page of yours and see what happens: <script type="text/javascript" src="http://www.catpin.com/bumper_sticker3.php"></script> Wherever that line is, when you view your web page, it should have a random quote. It's using the same code that I had above (in post #2). how would you put <script type="text/javascript" src="http://www.catpin.com/bumper_sticker3.php"></script> into a function for javascript to call this php file? I wish to change the dynamic text in a javascript to that which is in a MySQL database using PHP. this is then used in a flash scroller. currently i have hard coded the text in the javascript file. is there a way to have PHP run in the javascript file before it is sent to the endusers? or another way ? Hi, I'm doing something wrong, I want my script to execute when the browser window opens, can someone please help me? Code: <p><iframe id="myFrame" style="display: none;" width="500" height="300"></iframe> <script type="text/javascript">// <![CDATA[ window.onload=openpdf(); type="text/javascript">// <![CDATA[ function openPdf() { var omyFrame = document.getElementById("myFrame"); omyFrame.style.display="block"; omyFrame.src = "myFile.pdf"; } // ]]></script> Hi, I'd like to create a textarea and a division so that whatever embed code you put in the textarea it gets executed on the division in real-time. Your kind help is greatly appreciated! JavaScript newbie HI peers, i need to run a sql query fromjavascript onclick button and display data in a textarea . is this possible ? than you . First off; i was in two minds if this belonged in the .php forum or the javascript forum; i apologize if i chose the wrong one. I have this .php code: PHP Code: <?php $query = "SELECT mail_id FROM ".TBL_MAIL." WHERE UserTo = '$session->username' and status = 'unread'"; $numUnreadMail = $database->query($query) or die(mysql_error()); $numUnreadMail = mysql_num_rows($numUnreadMail); if($numUnreadMail == 0){ echo '<img src="../images/global/mail_imgs/inbox_0.png" width="22" height="15" />';} if($numUnreadMail == 1){ echo '<img src="../images/global/mail_imgs/inbox_1.png" width="22" height="15" />';} if($numUnreadMail == 2){ echo '<img src="../images/global/mail_imgs/inbox_2.png" width="22" height="15" />';} if($numUnreadMail == 3){ echo '<img src="../images/global/mail_imgs/inbox_3.png" width="22" height="15" />';} if($numUnreadMail == 4){ echo '<img src="../images/global/mail_imgs/inbox_4.png" width="22" height="15" />';} if($numUnreadMail == 5){ echo '<img src="../images/global/mail_imgs/inbox_5.png" width="22" height="15" />';} if($numUnreadMail == 6){ echo '<img src="../images/global/mail_imgs/inbox_6.png" width="22" height="15" />';} if($numUnreadMail == 7){ echo '<img src="../images/global/mail_imgs/inbox_7.png" width="22" height="15" />';} if($numUnreadMail == 8){ echo '<img src="../images/global/mail_imgs/inbox_8.png" width="22" height="15" />';} if($numUnreadMail == 9){ echo '<img src="../images/global/mail_imgs/inbox_9.png" width="22" height="15" />';} if($numUnreadMail == 10){ echo '<img src="../images/global/mail_imgs/inbox_10.png" width="22" height="15" />';} if($numUnreadMail == 11){ echo '<img src="../images/global/mail_imgs/inbox_11.png" width="22" height="15" />';} if($numUnreadMail == 12){ echo '<img src="../images/global/mail_imgs/inbox_12.png" width="22" height="15" />';} if($numUnreadMail == 13){ echo '<img src="../images/global/mail_imgs/inbox_13.png" width="22" height="15" />';} if($numUnreadMail == 14){ echo '<img src="../images/global/mail_imgs/inbox_14.png" width="22" height="15" />';} if($numUnreadMail == 15){ echo '<img src="../images/global/mail_imgs/inbox_15.png" width="22" height="15" />';} if($numUnreadMail == 16){ echo '<img src="../images/global/mail_imgs/inbox_16.png" width="22" height="15" />';} if($numUnreadMail == 17){ echo '<img src="../images/global/mail_imgs/inbox_17.png" width="22" height="15" />';} if($numUnreadMail == 18){ echo '<img src="../images/global/mail_imgs/inbox_18.png" width="22" height="15" />';} if($numUnreadMail == 19){ echo '<img src="../images/global/mail_imgs/inbox_19.png" width="22" height="15" />';} if($numUnreadMail == 20){ echo '<img src="../images/global/mail_imgs/inbox_20.png" width="22" height="15" />';} //Middle Section echo '</a> <div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">'; if($session->isAdmin()){ echo '<a href="http://localhost/admin/admin_mailinbox.php">View Inbox ';} else{ echo '<a href="http://localhost/mailinbox.php">View Inbox ';} //Displays the correct number on drop tab if($numUnreadMail == 0){ echo ' ';} if($numUnreadMail == 1){ echo '(01)';} if($numUnreadMail == 2){ echo '(02)';} if($numUnreadMail == 3){ echo '(03)';} if($numUnreadMail == 4){ echo '(04)';} if($numUnreadMail == 5){ echo '(05)';} if($numUnreadMail == 6){ echo '(06)';} if($numUnreadMail == 7){ echo '(07)';} if($numUnreadMail == 8){ echo '(08)';} if($numUnreadMail == 9){ echo '(09)';} if($numUnreadMail == 10){ echo '(10)';} if($numUnreadMail == 11){ echo '(11)';} if($numUnreadMail == 12){ echo '(12)';} if($numUnreadMail == 13){ echo '(13)';} if($numUnreadMail == 14){ echo '(14)';} if($numUnreadMail == 15){ echo '(15)';} if($numUnreadMail == 16){ echo '(16)';} if($numUnreadMail == 17){ echo '(17)';} if($numUnreadMail == 18){ echo '(18)';} if($numUnreadMail == 19){ echo '(19)';} if($numUnreadMail == 20){ echo '(20)';} ?> which displays in this navigation: <li><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()" class="link_image"> <?php include_once('../include/mailicon_codes.php'); ?> </a> I wondered how or if it is even possible to use javascript to execute the first .php code so that the user would know if he/she had a new message without refreshing the page? Any help is greatly appreciated as i suck at .js cheers, Callum FF, Safari, Opera all execute this javascript code to refresh the page properly, but in IE version 8.0.6001.18904 the page doesn't seem to refresh on click of orange_refresh button. I have checked out a different version of IE8, don't recall exact version, but it did seem to work fine in that one, whatever version it was probably the latest now that I think of it. Check out code below any sug.'s could be helpful, though its probably a bug.. Code: <a href="javascript:document.location.reload();" onmouseover="window.status='Refresh'; return true" onmouseout="window.status='Page Refreshed'"><img src="image/orange_refresh.png" width="30" height="30" border="0" /></a> Basically i dont understand the concept of the timing for animation. I seen some code samples and they seem to subtract two different times from eachother :S you can tell im confused. and also about calculating frames...heres a quote explaining how frames work but stupid me all of a sudden dont seem to understand english anymore Quote: After that, we need to calculate the total number of frames we are going to animate. If a time of 0 or less then 0 is given, then we are just going to have 1 frame. Otherwise, we divide the time by 40. This is just an arbitrary value that means each frame will last 40 milliseconds (which comes out to 25 frames per second). It doesn't matter if the number of frames comes out to a fraction - we are just going to be using that value to calculate the correct amount of movement per frame. thank you I am trying to trigger one custom function or another, depending on whether a radio button is checked or not. How can this be done? (I was hoping that "self" would be the ticket, but I think I was barking up the wrong tree.) Code: function toggleFieldsetByRadio(element){ if(SELF.checked){ enable(element); }else{ disable(element); } } How should I do this? I am hoping to use this function with an onchange event. ~ Mo edit:: got it to work setting inBooth to false in the function where I clear the menu, but then it's refreshing to div so often while you're standing in the booth (30 frames/sec, it's a game) that nothing happens when you click the buttons to buy/sell unless you click really really fast.... anyone know a good way to check whether something is true, then toggle an innerHTML div, then once the value becomes false, toggle the innerHTML div to empty....??simply?? But if I reverse the order the opposite works but then the other doesn't...... Code: if (condition==true ) { generateSale(); inBooth=true; smithShop(); } else {inBooth=false;clearSale();} //IS PLAYER IN VENDOR BOOTH? if (condition2==true ) { generateSale(); inBooth=true; vendorShop(); } else {inBooth=false;clearSale();} Only the "generateSale()" from the second one executes. If I switch the if blocks, the second one with "generateSale()" executes. If I change "clearSale();" to a "setTimeout=('clearSale()',1000)" then both execute "generateSale()" but the div it affects flickers repeatedly as it's cleared/remade. generateSale() changes the innerHTML of a div, clearSale() just overwrites the innerHTML with ' ' Code: var sales2; function clearSale() { sales2=document.getElementById('sales2'); sales2.innerHTML=''; } function generateSale(){ sales2=document.getElementById('sales2'); sales2.innerHTML= 'Buy/Sell: '+' Gold coins: '+playerInventory[lootArray[7]]+'<br>' +' Consumables:<br>' +'You have: '+playerItems[itemArray[4]] +' arrows<br>' +'<input type="button" value="Buy" onclick="buyIt(0);">'+'10 for 50gp<br>' +'<input type="button" value="Sell" onclick="sellIt(0);">'+'10 for 25gp<br>' } Any ideas? Basically when my character enters the range of an image of a building I have a menu pop up saying you're in a vendor booth. I want it to run generateSale() which changes a div on the screen to list a bunch of stuff you can buy/sell. When your character is no longer standing in range, I want it to clear that information, so you have to be standing within range in order to trade items. Currently I can make it generates the sale menu, but it doesn't clear it when you leave the range. I've tried all kinds of "toggle" variables to set whether you're in range or not, but only the second block fires, not the first and I cannot figure out why... Any ideas? The code all works fine it just won't clear for all the different buildings, only one.... hi From inside a javascript function i need to execute a vbscript sub routine. You might be thinking why i can't do it in javascript. well i probably can but i am better at VBscript and it would be a lot easier. Thanks Im alright with .php but not good at javascript at all. this is the javascript code placed in the head tags of my page function confirmation() { var answer = confirm("Delete news item?") if (answer){ window.location = "main.php?id=delete¬e="+noteID+"&status=delete"; } else{ alert("No action taken") } } this is the .php that links to the javascript function PHP Code: if($this->admin){ echo ' <a href="?id=edit¬e='.$this->noteID.'&status=load" class="grey">[Edit]</a>' .'<a href="" onclick="confirmation('.$row['noteID'].')" class="grey">[Delete]</a>'; } this is the .php code that executes if the url is status=delete PHP Code: // This displays if id = Delete A News & user=ADMIN if( $id == "delete" && $session->isAdmin() ) { echo '<div id="major_game_news_header">'; echo '<h1>DELETION OF NOTE</h1></div>'; $stat = $_GET['status']; if($stat == "preview" && $session->isAdmin() ) { $noteID = $_GET['note']; echo '<div id="createnews">Are you sure? <a href="?id=delete¬e={$noteID}&status=delete">' .'Yes</a>. <a href="main.php">No</a></div>'; } if($stat == "delete" && $session->isAdmin() ) { $note->deleteNote();} } this line in the third code snippet works perfect: " PHP Code: <a href="?id=delete¬e={$noteID}&status=delete">Yes</a> " I'm having great difficulty for the "window.location =...... " to navigate to the right url. It doesn't include the noteID which enables me to delete news items. Any help would be greatly apreciated (: I have the following function: Code: function sonKare(sayac, oteki) { var vertical, horizontal = hangiYataySira(sayac, oteki), j, k, l, m, united, tekRakam, actualV = [], actualH = [], numaralar = [1, 2, 3, 4, 5, 6, 7, 8, 9], olmayanlar = []; if(ilkSefer === true) { vertical = hangiDikeySira(rakamlar.length); ilkSefer = false; } else { vertical = hangiDikeySira(rakamlar.length - 1); } for(j = 0; j <= vertical.length - 1; j ++ ) { if(rakamlar[vertical[j]] !== undefined) actualV.push(rakamlar[vertical[j]]); } for(k = 0; k <= horizontal.length - 1; k ++ ) { if(rakamlar[horizontal[k]] !== undefined) actualH.push(rakamlar[horizontal[k]]); } united = actualV.concat(actualH); //---- Olmayan rakamları bulan kısım ------------ outer: for(l = 0; l <= numaralar.length - 1; l++) { for(m = 0; m <= united.length - 1; m++) { if(numaralar[l] === united[m]) continue outer; if(m === united.length - 1 && numaralar[l] !== united[m]) olmayanlar.push(numaralar[l]); } } //---------------------------------------------- if(olmayanlar.length > 1 || olmayanlar.length === 0) { rakamlar = []; document.form1.buton.click(); // THIS LINE DOES NOT WORK SECOND TIME } else { $("_" + oteki + "_" + sayac).value = olmayanlar[0]; rakamlar.push(olmayanlar[0]); sayac++; if(sayac === 10) return; else sonKare(sayac, oteki); //CALLS ITSELF } } This is a recursive function. As stated above there is a line which does not work for the second time. What I mean is, it works perfect for the first time and after function calls itself, it doesn't work. Javascript does execute the line above it but just disregards that document.form1.buton.click(); line. I use Firebug for debugging and I checked it many times, when that expression needs to be executed for the second time, JavaScript just ignores it and immediately goes at the end of the function... I just can't figure out why JS does such a thing? p.s: Don't bother about weird variable names, they are not in English but in Turkish which is my native language For example, how can I write "Hello!" on the page every Friday at 8:40?
Hey guys, I scripted a javascript guessing game and I am not sure how I can configure the random number generator to only generate one number and then stop. Here is my code: Code: <html> <head> <title>Guess it up! </title> </head> <body> <center> <BODY onLoad="GenerateNumber()"> <b><font size="5" ><u><b>Guess it up!<br></b></u> <br > <font size="3"> This is out of: <br> <input id="DefaultNumber" name="DefaultNumber" type="text" size=3><br> Type in your guess: <br> <input id="HisGuess" name="HisGuess" type="text" size=3> <p> <input name="StartButton" type="button" value="Guess" onclick="StartGame()"> </p> <script type="text/javascript"> function GenerateNumber() { var TheRightGuess = Math.round(Math.random() * (document.getElementById("DefaultNumber").value))+1; //Makes the randomly generated right guess. The "+1" makes it 1-5 instead of 0-4. } function StartGame() { var TheRightGuess = Math.round(Math.random() * (document.getElementById("DefaultNumber").value))+1; //Makes the randomly generated right guess. The "+1" makes it 1-5 instead of 0-4. var HisGuess = parseInt(document.getElementById("HisGuess").value);//his guess var DefaultNumber = parseInt(document.getElementById("DefaultNumber").value);//number that they want to guess in. //NUMERIC TEST STARTS HERE if (HisGuess != parseInt(HisGuess) || (DefaultNumber != parseInt(DefaultNumber))) { alert("Please enter numbers only.") } //NUMERIC TEST ENDS HERE if (DefaultNumber <= 0) //Fixed bug:Guessing in zero. { alert("You can't guess in zero!?") } else if (DefaultNumber === 1 && HisGuess === 1 || TheRightGuess == HisGuess && DefaultNumber != 1)//testing if they guessed in 1 and guessed 1. { alert("You got the number!") } else if (HisGuess > DefaultNumber)//if guess is higher then what they guess in. { alert("You can only guess below " + DefaultNumber + ".") } else if (HisGuess != TheRightGuess && HisGuess <= DefaultNumber && DefaultNumber != 1 || HisGuess == 0)//fixed bug: you can't guess 0. { alert("Guess again!") } } </script> </body> </html> Thanks, Fizz All, I have a script that runs some jQuery and appends it to a <div>. I only want this script executed if a user is using IE7 or higher since jQuery doesn't work with IE6. How can I do that? Also, if they aren't using IE7 or higher I don't wnat to display the <div> that the results go into. How would I go about doing this? Thanks! Hello: I have an ajax file to loads the content of another file into a div, here is the js code: PHP Code: <script type="text/javascript"> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getcar.php?q="+str,true); xmlhttp.send(); } </script> the file within xmlhttp (getcar.php) has other js codes that are to be executed once the file is loaded into the div. here is one of those files: PHP Code: <!-- loading, please wait message script begins--> <div id="loading\" class=\"loading-invisible\" z-index: 999> <p><font color=\"black\" size='4'>one moment, please!</font> <font color=#218868> Auto Tech Pro « Initiating... » </font><br /><img border='0' src='images/spinnnnnn.gif' width='215px' height='206px'> </div> <script type=\"text/javascript\"> document.getElementById(\"loading\").className = \"loading-visible\"; var hideDiv = function(){document.getElementById(\"loading\").className = \"loading-invisible\";}; var oldLoad = window.onload; var newLoad = oldLoad ? function(){hideDiv.call(this);oldLoad.call(this);} : hideDiv; window.onload = newLoad; </script> <!-- loading, please wait message script ends--> <script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\"></script> <script src=\"/AJAX/popBox1.2.0.js\" type=\"text/javascript\"></script> <link href=\"/AJAX/popBox1.2.0.css\" rel=\"stylesheet\" type=\"text/css\" /> <script type=\"text/javascript\"> $(document).ready(function () { $('#inputbox').popBox({width:550, newlineString: '<br/>' }); }); </script> this however is not working. If I open getcar.php independently of the ajax, the preceeding js codes work fine, but not once the ajax loads the file into div. Any thoughts on how this is doable? Mossa Hey, I have a page at http://www.webdev70.cocc-webdev.org/contact.html where I have styling on the radio and check boxes. I'm working on another project for class now where I want onclick or onchange functions in the radio buttons. When the radio buttons have the class="styled" on them, the function will not execute. When that's removed, they do. Here is the javascript for the styling: Code: var checkboxHeight = "25"; var radioHeight = "25"; var selectWidth = "190"; document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>'); var Custom = { init: function() { var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active; for(a = 0; a < inputs.length; a++) { if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") { span[a] = document.createElement("span"); span[a].className = inputs[a].type; if(inputs[a].checked == true) { if(inputs[a].type == "checkbox") { position = "0 -" + (checkboxHeight*2) + "px"; span[a].style.backgroundPosition = position; } else { position = "0 -" + (radioHeight*2) + "px"; span[a].style.backgroundPosition = position; } } inputs[a].parentNode.insertBefore(span[a], inputs[a]); inputs[a].onchange = Custom.clear; if(!inputs[a].getAttribute("disabled")) { span[a].onmousedown = Custom.pushed; span[a].onmouseup = Custom.check; } else { span[a].className = span[a].className += " disabled"; } } } inputs = document.getElementsByTagName("select"); for(a = 0; a < inputs.length; a++) { if(inputs[a].className == "styled") { option = inputs[a].getElementsByTagName("option"); active = option[0].childNodes[0].nodeValue; textnode = document.createTextNode(active); for(b = 0; b < option.length; b++) { if(option[b].selected == true) { textnode = document.createTextNode(option[b].childNodes[0].nodeValue); } } span[a] = document.createElement("span"); span[a].className = "select"; span[a].id = "select" + inputs[a].name; span[a].appendChild(textnode); inputs[a].parentNode.insertBefore(span[a], inputs[a]); if(!inputs[a].getAttribute("disabled")) { inputs[a].onchange = Custom.choose; } else { inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled"; } } } document.onmouseup = Custom.clear; }, pushed: function() { element = this.nextSibling; if(element.checked == true && element.type == "checkbox") { this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px"; } else if(element.checked == true && element.type == "radio") { this.style.backgroundPosition = "0 -" + radioHeight*3 + "px"; } else if(element.checked != true && element.type == "checkbox") { this.style.backgroundPosition = "0 -" + checkboxHeight + "px"; } else { this.style.backgroundPosition = "0 -" + radioHeight + "px"; } }, check: function() { element = this.nextSibling; if(element.checked == true && element.type == "checkbox") { this.style.backgroundPosition = "0 0"; element.checked = false; } else { if(element.type == "checkbox") { this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px"; } else { this.style.backgroundPosition = "0 -" + radioHeight*2 + "px"; group = this.nextSibling.name; inputs = document.getElementsByTagName("input"); for(a = 0; a < inputs.length; a++) { if(inputs[a].name == group && inputs[a] != this.nextSibling) { inputs[a].previousSibling.style.backgroundPosition = "0 0"; } } } element.checked = true; } }, clear: function() { inputs = document.getElementsByTagName("input"); for(var b = 0; b < inputs.length; b++) { if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") { inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px"; } else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") { inputs[b].previousSibling.style.backgroundPosition = "0 0"; } else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") { inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px"; } else if(inputs[b].type == "radio" && inputs[b].className == "styled") { inputs[b].previousSibling.style.backgroundPosition = "0 0"; } } }, choose: function() { option = this.getElementsByTagName("option"); for(d = 0; d < option.length; d++) { if(option[d].selected == true) { document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue; } } } } window.onload = Custom.init; The code is way over my head so I'm not sure where the problem is, or if it could be fixed. This is what one of my radio buttons looks like: <input type="radio" name="puppy" value="1" class="styled" onchange="puppycheck()">Black and White Puppy If the style tag is removed it works perfectly. There is CSS too, but I don't think the problem is in there. Hello. This is very long and I think if you look at code it might be quicker. If not, then please read along. Here is the code and the problem: Code: function addtwoboxes { get values from two text boxes, one about width, the other one about height, and store each in a variable; a=width; b=height checkifwidthproblem(); //to see if the boxes are empty and with numbers checkifheightproblem(); //to see if the boxes are empty and with numbers if (width_not_ok==false && height_not_ok==false) { Go Ahead and do calculations and other things } function checkifwidthproblem() { width_not_ok=false; if problems with the data in the textbox (the a variable is being checked). { bring up an alert box width_not_ok=true; } } //end of checkifwidthproblem function function checkifheightproblem() { height_not_ok=false; if problems with the data in the textbox (the b variable is being checked) { bring up an alert box height_not_ok=true; } } //end of checkifheightproblem function I would like this function to be setup the same way as the addtwoboxes function, but right now I am only calling up the checkifwidthproblem function, and it doesn't execute and the form gets submitted. The fillInvoiceNumber function can be called because if I place only an alert of Hello in it, it comes up, and then the form gets submitted. If it do get this working, I would also need to be sure that it is seeing the results of the variables width_not_ok and height_not_ok, just as they are for the addtwoboxes function. function fillInvoiceNumber() checkifwidthproblem(); //to see if the boxes are empty and with numbers checkifheightproblem(); //to see if the boxes are empty and with numbers if (width_not_ok==false && height_not_ok==false) { Go Ahead and do calculations and other things ] This is going to be a bit long, but it's the only way I can be sure of that I have covered everything, so please bear with me and help me out. Thanks. Please Provide Solution Using my way First, Then suggest Better Ways: O.k. Before I post the problem, I know, since I took program classes years ago and since I have done a little research here and here, that there are better, more efficient, and tidier ways to do what I am doing, but I have started already this way and would like to continue this way. I will ask what's the better way to do this in another thread, unless 1) you feel like explaining the bettery way and 2) it's not too long or complicated, but AFTER you have provided me with a solution to doing it my way. The Setup / What My Form is Supposed to Do: I have a form with two buttons. The user has to enter some information into the form and then click the button to have some calculations done and for other text fields to automatically filled in. After that, the user has to click submit. A note about the submit button: The type is image and the name says submit. The form line has the following: <form target="abcco" action="https://www.domainname.com" method="post" id="Form" onsubmit="fillInvoiceNumber()"> I will explain what the fillInvoiceNumber() is doing later on. Data Validation / Verification: 1) I want to ensure that when the user clicks the first button, let's call it GetPrices to make things easier, that it checks to see if data is enterted into the textboxes and that it is the right kind of data. 2) After the GetPrices button is clicked, the user can then enter nonsense into the textboxes and click submit or, never click the GetPrices button, the first button to begin with, and so junk will be submitted. This is what I have going on: For the GetPrices button, I have the following: onclick="addtwoboxes() (the names I have aren't fully descriptive of all that's going on, as I do have more things happening, but for now I have left them like that). in the addtwoboxes function I have it calling up two functions, each for a textbox in which the user has to enter width in one and height in another, and if the textboxes are not empty and have the correct data in them, then the calcuations for the addtwoboxes take place; if not, nothing happens (regarding the calculations; an alert box comes up for either or both of the functions in the addtwoboxes function if something is wrong). So, the two functions that are called in the addtwoboxes() function are checkifwidthproblem() checkifheighthproblem() which I am calling just like that but with a semicolon to the end of each one. This next now is one of the areas where I do believe this can be combined, since only one value is changing, but I will leave it like this for now. The checkifwidthproblem() function starts of with a variable:width_not_ok=false; (after doing some research, I see that this is often set the opposite way or not set at all) if something is wrong with the data entered into the width textbox, an alert box with a message comes up, and I then have the following variable: width_not_ok=false; For the checkifheighthproblem(), it's basically the same as the width problem, except, with it's own set of variables. I had the same ones as the width one, but if things were not ok with the width textbox, but o.k. with the height textbox, the calculations were taking place. So, because of this I used new variables in the height function and had an if statement check both variables for false. So, the checkifheighthproblem() starts of with the variable: height_not_ok=false and if there is a problem with the data entered into the height textbox, an alert box comes up and the variable height_not_ok=true is set. When the user presses the GetPrices button, this function works excellently. Everything goes as it should. The problem is when the form is being submitted. I would like the textboxes to be rechecked. So, right now I have a function called fillInvoiceNumber() in which it is joining two strings together after getting their values from a drop down menu. This has to be done at the time of submission only for the page that's processing the results to have them interpreted the way I want it to. Prior to joining those strings, I would like it check and see if everything is o.k. with the two textboxes by calling the two functions of that check height and width and if they are not, for the alert boxes to come up, for the joining of the strings to not take place, and for the form to not be submitted. However, the fillInvoiceNumber() function is not executing either function at all. If it does work, I would also need to be sure that it is seeing the results of the variables width_not_ok and height_not_ok. Hey all, so im working on a piece of jquery/JS which executes (drops down a new div) when you click a link. I have the links setup as <a href="#" id="d0">Execute 1</a> <a href="#" id="d1">Execute 2</a> <a href="#" id="d2">Execute 3</a> And the jscript detects when d0, d1 or d2 is clicked and executes my script. It all works perfectly, however when you click on a link it will jump to the top of the page as a side effect of the a href="#" I assume? Is there anyway to have my same effect work inline (without jumping the page to the top) ? Thank you very much! |