JavaScript - Displaying A Button With An If Statement
How would I go about having a button similar to this display within an if statement if the statement is true? Thank you in advance for the help.
Code: <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="HEZUCTL9VASYW"> <table> <tr><td><input type="hidden" name="on0" value="Color">Color</td></tr><tr><td><select name="os0"> <option value="White">White </option> <option value="Transparent">Transparent </option> </select> </td></tr> </table> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> Similar TutorialsHi I have the following code...
Code: <!doctype html> <html> <head> <title>Loops</title> </head> <body> <form id = "frmOne"> <table border="1" > <p>Items Remaining: <a id="clicks">5</a></p> <tr> <th> Number One:</th> <th> Number Two:</th> </tr> <tr> <td> <Input Type="Text" Name="txtFirstNumber" Size="5" value=""> </td> <td> <Input Type="Text" Name="txtSecondNumber" Size="5" value=""> </td> </tr> <tr> <td colspan="2"> Totals: <textarea Name="totals" style="width: 400px; height: 300px;"></textarea></td> </tr> <tr> <td colspan="2"> <Input Type="Button" Name="b1" Value="Add Numbers" onClick = calculate()> </td> </tr> </table> </form> <script> var Totals = [ ]; var clicks = 5; function calculate() { var form = document.getElementById("frmOne"); var A = form.txtFirstNumber.value; var B = form.txtSecondNumber.value; Totals.push( A + " + " + B + " = " + (1*A+1*B) ); form.totals.value = Totals.join("\n"); form.txtFirstNumber.value = form.txtSecondNumber.value = ""; clicks -= 1; document.getElementById("clicks").innerHTML = clicks; } </script> </body> </html> I want to add in an if statement that checks to see if the number of items remaining is 0. If it is 0, I want it to say finished and the button be disabled / disappear. Can anyone help? TIA i need to disable a button if a table cell has a certain value inside of it. Code: if (document.getElementById('ba' + roid.value + 'r' + roid2.value + 'c1').innerHTML = " ") { document.getElementsByName('open')[0].disabled=true; } else { document.getElementsByName('open')[0].disabled=false; } That is what i have got. The problem is that the button is constantly disabled no matter what the value and also when it executes it gives that cell the value of . i really dont know what is going on. any help apreciated I have been searching for a way to display facebook api friends.getAppUsers in set of 5. I am able to do this if i hard code it but I cant seem to find and comprehend a method to do this dynamically. What i want to achieve is, if i have 43 friends using the application, the code should allow users to view this result in set of 5. -prevBtn- friend1 friend2 friend3 friend4 friend5 -nextBtn- upon clicking on the nextBtn, -prevBtn- friend6 friend7 friend8 friend9 friend10 -nextBtn- etc i am actually relatively new to Javascript and Facebook Codings.. so any help would really be great! Thanks! here are my codes: Code: <div id="fb-root"></div> <table width="750px" height="185px" background="Image/friends.jpg"> <tr> <td align="right"> <a href="#"onClick="prev();return false"><img src="Image/prevFriend.jpg" width="36" height="154"></a> </td> <td width="89%"> <div id="profile_pics" align="left"></div> </td> <td> <a href="#" onClick="next();return false">Image/nextFriend.jpg" width="36" height="154"></a> </td> </tr> </table> </div> <script src="http://connect.facebook.net/en_US/all.js"></script> <script> var profilePicsDiv = document.getElementById('profile_pics'); var NameDiv = document.getElementById('name'); var containDiv = document.getElementById('container'); FB.init({ appId: 'xxxxxxxxxxxx', status: true, cookie: true, xfbml: true }); FB.Event.subscribe('auth.sessionChange', function (response) { if (response.session) { window.location.reload(); } else { window.location.reload(); } }); FB.getLoginStatus(function(response) { if (!response.session) { profilePicsDiv.innerHTML = '<em></em>'; containDiv.innerHTML = '<em>You are not connected </em> '; return; } FB.api({ method: 'friends.getAppUsers' }, function(result) { var markup = ''; var numFriends = result ? Math.min(5,result.length) : 1; if (numFriends > 0) { for (var i=0; i<numFriends; i++) { markup += ( '<fb:profile-pic size="square" ' + 'uid="' + result[i] + '" ' + 'facebook-logo="false"' + 'linked="false"' + '></fb:profile-pic>' ); } } profilePicsDiv.innerHTML = markup; FB.XFBML.parse(profilePicsDiv); }); }); function next(){ FB.api({ method: 'friends.getAppUsers' }, function(result) { var markup = ''; var numFriends = result ? Math.min(10,result.length):1; if (numFriends > 5) { for (var j=5; j<numFriends; j++) { markup += ( '<fb:profile-pic size="square" ' + 'uid="' + result[j] + '" ' + 'facebook-logo="false"' + 'linked="false"' + '></fb:profile-pic>' ); } } else{ if (numFriends > 0) { for (var j=0; j<numFriends; j++) { markup += ( '<fb:profile-pic size="square" ' + 'uid="' + result[j] + '" ' + 'facebook-logo="false"' + 'linked="false"' + '></fb:profile-pic> ' ); } } }; profilePicsDiv.innerHTML = markup; FB.XFBML.parse(profilePicsDiv); }); } function prev(){ FB.api({ method: 'friends.getAppUsers' }, function(result) { var markup = ''; var numFriends = result ? Math.min(5,result.length):1; if (numFriends > 0) { for (var j=0; j<numFriends; j++) { markup += ( <fb:profile-pic size="square" ' + 'uid="' + result[j] + '" ' + 'facebook-logo="false"' + 'linked="false"' + '></fb:profile-pic>' ); } } profilePicsDiv.innerHTML = markup; FB.XFBML.parse(profilePicsDiv); }); } I am very inexperienced with javasciprt. I am designing a form in coldfusion, and want some dynamic action to take place. My users will be offered 2 selections via radio buttons. Depending on which radio button they select, they will get a few more radio buttons to choose from. I have been told that this can be handled in javascript. So I am appealing to the javascript programmer nation for some assistance in this endeavor. Any help would be greatly appreciated, Thanks. Ahoy, Lemme try to explain this as best as I can. Bullet points might help: When someone clicks on an image here (http://gta.kwivia.co.uk/gta-iv/), the rest of the images collapse and become invisible Below the image, some links appear Also, there will be a "show other images" button which will then show the rest of the images http://gta.kwivia.co.uk/gta-iv/ I will appreciate all solutions to this problem. If you need to know anything, simply ask me. Hello everyone, I am using javascript and I have a radio button that the user selects and I have a function to see which button was selected, but i'm trying to use the return of that if statement in another statement. Basically another part of the function is dependent on what the user selects in the radio button. Here is what I have so far (I have some things in there that might not work because i'm trying to figure out what works): Code: <script type="text/javascript"> function getSelectedRadio() { len = document.dates.dep.length // returns the array number of the selected radio button or -1 if no button is selected if (document.dates.dep[0]) { // if the button group is an array (one button is not an array) for (var i=0; i<len; i++) { if (document.dates.dep[i].checked) { return i } } } else { if (document.dates.dep.checked) { return 0; } // if the one button is checked, return zero } // if we get to this point, no radio button is selected return -1; } function Calculate() { var i = getSelectedRadio(); if (i == -1) { alert("Please select if Marine entered Delayed Entry Program"); } else { if (document.dates.dep[i]) { return document.dates.dep[i].value; } else { return document.dates.dep.value; } } if (document.dates.yearDEAF.value < 1985 && document.dates.monthDEAF.value < 01 && document.dates.dayDEAF.value < 01 && first return from above ) { document.dates.yearDEP.value = (document.dates.yearDEAF.value); document.dates.monthDEP.value = (document.dates.monthDEAF.value); document.dates.dayDEP.value = (document.dates.dayDEAF.value); document.dates.yearPEBD.value = (document.dates.yearDEAF.value); document.dates.monthPEBD.value = (document.dates.monthDEAF.value); document.dates.dayPEBD.value = (document.dates.dayDEAF.value); } else if (document.dates.yearDEAF.value < 1985 && document.dates.monthDEAF.value < 01 && document.dates.dayDEAF.value < 01 && second return from above ) { document.dates.yearPEBD.value = (document.dates.yearAFADBD.value); document.dates.monthPEBD.value = (document.dates.monthAFADBD.value); document.dates.dayPEBD.value = (document.dates.dayAFADBD.value); document.dates.yearDEP.value = "N/A"; document.dates.monthDEP.value = "N/A"; document.dates.dayDEP.value = "N/A"; } } </script> I color coded in red the returns i'm trying to reference and where they need to be. Is this possible, and if so how can I do it? I haven't been able to find anything on the internet so far. Any help is greatly appreciated! Hey guys. This is vague because I dont know what exactly to tell you but please reply with me so I can fix this. I want to add something to my forum. Specifically, I want to add a HTML and Picture button for when you go to reply. Like posting an article here, there are also these options (font, alignment, insert image) I do not know how to achieve this but shouldnt be too hard. Here are the two sources you will need to look through to help me fix the forum. http://neoweather.com/FWFORUM.JS http://static.websimages.com/JS/fw.js THANKS Hey guys. I want to add something to my forum. Specifically, I want to add a HTML and Picture button for when you go to reply. Like posting an article here, there are also these options (font, alignment, insert image) I do not know how to achieve this but shouldnt be too hard. Here are the two sources you will need to look through to help me fix the forum. http://neoweather.com/FWFORUM.JS http://static.websimages.com/JS/fw.js THANKS Hi, I am not entirely sure what I am doing wrong here, and I have been looking at this for ages, so apologies in advance if I have become so bleary eyed I can't see something simple. I use php to create buttons based on values pulled for a table. The problem I have is when you click on the first button the javascript function works great, when you click on the next button you get the same output even though it should be different results. I am working in ff and I can see on my firebug console that the javascript function is being called, but it is not passing the new value of the second or third button, it just keeps repassing the value of the first button. So not entirely sure where I am going wrong here. My page is: Code: <script type="text/javascript"> function loadXMLDoc2(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> <head> <body> <?php $con = mysql_connect("localhost","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $result = mysql_query("SELECT DISTINCT theme FROM goods WHERE category='{$_POST['category']}' ORDER BY theme DESC"); while($row = mysql_fetch_array($result)){ echo '<input type="text" class="hidden" name="theme" id="theme" value="' . $row['theme'] . '" ><input type="button" class="button3" name="product" id="product" value="' . $row['product'] . '" onClick="loadXMLDoc2(\'getShow.php\',\'txtHint\',\'theme=\'+encodeURI(document.getElementById(\'rtheme\').value))" > '; } echo '<br /><br /> <div id="txtHint"><div> <br /> <br />'; mysql_close($con); ?> And getShow.php produces a table with a list of product images, names and prices, based on theme. So basically not sure where I am going wrong here? i'm still a relative noob and this has me stuck - i have a save button with a "save as copy" in the save dropdown list. add new item directs to a premade/formatted project that is used as a template, so on that item i only want/need the "save as copy" but on all other items that use the form i need to only have the "save" function. is there any way to either change the function of the button depending on item that is being viewed in the edit screen OR hide the "save" button and only show the button associated with "save as copy - and vis versa for the rest of the items?? current button code is - protected function getToolbar() { $options = array(); $user = JFactory::getUser(); $create_ms = $user->authorise('core.create', 'com_pfmilestones'); $create_task = $user->authorise('core.create', 'com_pftasks'); $options[] = array( 'text' => 'JSAVE', 'task' => $this->getName() . '.save'); $options[] = array( 'text' => 'Save as new project', 'task' => $this->getName() . '.save2copy', 'options' => array('access' => ($this->item->id > 0))); PFToolbar::dropdownButton($options, array('icon' => 'icon-white icon-ok')); item used as template is id=8 any help or suggestions would be greatly appreciated.. i got javascripts button : Code: <input type="button" value="select" onClick="document.getElementById('input').select()" /> how can i transform "button" to image button (gif) I have 4 rows in a table. Each row consist of 4 radio buttons. Each radio button per row has different values in it but has the same name (group) ex: <input type="radio" name="a" value="1"> <input type="radio" name="a" value="2"> <input type="radio" name="a" value="3"> <input type="radio" name="a" value="4"> <input type="radio" name="b" value="1"> <input type="radio" name="b" value="2"> <input type="radio" name="b" value="3"> <input type="radio" name="b" value="4"> and so on.. If I click radio button A with value 2, I want to output the total at the bottom as "2".. Also, if I click radio button B with value 3, I want to output the total of A and B as 5 and so on.. How can I automatically calculate the answer based on which radio button was click? update: I got my answer from this site: http://stackoverflow.com/questions/1...s-using-jquery No matter what first name and last name I enter I get "Wrong!" I get wrong if I enter john smith or bill shaw Code: <html> <head> </head> <body> <script type="text/javascript"> var input; var first; var last; input = window.prompt("Please Enter First and Last Name (e.g. Joe Smith)"); if ((first == "John" || first == "john") && (last == "Smith"|| last == "smith")){ document.write ("Welcome John Smith"); } if ((first == "Bill" || first == "bill") && (last == "Shaw"|| last == "Shaw")){ document.write ("Welcome Bill Shaw"); } else { document.write("Wrong!"); } </script> <body> </html> Hello CF im wondering how could i use an if statement to have something pop up when visitors visit my site that allows them two choices. it would say something like this. Would you Like to always see the navigation Bar? then they have two options. Yes and No. then depending on what they choose it will either have the code use the absolute or the fixed positioning attribute for the whole code. Or is this just not possible? If you want me to explain it more just ask. can someone help me with this pls: Code: function anything() { var tegenover = document.getElementById("minlas"); var septo = document.getElementById("combo_2"); //prijs verbinder per meter var serr = document.getElementById("comba_2"); //prijs verbinder per meter var seprr = document.getElementById("combb_2"); //prijs verbinder per meter var septrr = document.getElementById("combc_2"); //prijs verbinder per meter var nocho = document.getElementById("wide"); //breedte band in mm document.getElementById("totprijslas").value = Math.round(100*((parseFloat(septo.value) + parseFloat(serr.value) + parseFloat(seprr.value) + parseFloat(septrr.value)) * parseFloat(nocho.value))/1000)/100; } the value returned of totprijslas can be anything between 0 and 1000,but i want the value of "totprijslas" to be a minimum of "50",so for example if result is 30 then i need it to show 50.can someone help me with an if statement for this.thx I am relatively new to JavaScript coding, and I a having some problems with an IF statement. I want the IF statement to tell me when the number is below the minimum. Code: function main (txtpamphletMin,txtpamphletMax,optQuality,selIncrement,txtResults) { var txtpamphletMin,txtpamphletMax,optQuality,selIncrement; var amount = 100; var errorMsg = ""; var results = ""; pamphletMin = pamphletMin.value; //Make sure that the minimum number of pamphlets required is entered if (pamphletMin == "pamphletMin<100") { errorMsg = "Number of pamphlets must be above 100"; } else { pamphletMin = txtpamphletMin.value; //get the number of pamphlets from the text box errorMsg = validatepamphletMin(Minimum Pamphlets); } I know that this is no the entire statement but I am just having problems with this one. Can anyone help? I want to know how I can update my power_points field if a select option is chosen. For example: if animal guardian is chosen Power_points - (attribute_level * 1) if combined attacks is chosen power_points - (attribute_level * 1) if elemental control is chosen power_points - (attribute_level * 3) etc... Here is my current script: Code: <?php session_start(); ?> <form> <table cellpadding="3" cellspacing="3"> <tr> <th>Attribute</th> <th>Level</th> <th>Power Points:</th> <th>Character Points:</th> </tr> <tr> <td><input type="text" readonly="readonly" value="Scout/Knight Powers" size="19" name="attribute1" /></td> <td><select name="level" onclick="power(), remain()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select></td> <td align="center"><input type="text" name="power_points" id="power_points" size="1" readonly="readonly"/></td> <td align="center"><input type="text" name="cp_remain" id="cp_remain" size="1" readonly="readonly" /></td> </tr> </table> </form> <form method="POST" action="test_batosai.php"> <table><tr><td> <div id="dynamicInput1"> <table cellpadding="3" cellspacing="3"> <thead> <tr> <th>Sub-Attribute</th> <th>Level</th> <th>Notes <i>(optional)</i></th> </tr> </thead> <tbody> <tr> <td> <select name="attribute[]" size="1"> <option value="1">Animal Guardian</option> <option value="2">Combined Attacks</option> <option value="3">Elemental Control</option> <option value="4">Emotional Control</option> <option value="5">Item Of Power</option> <option value="6">Knight Attack</option> <option value="7">Rejuvenation</option> <option value="8">Sailor Scout Attack</option> </select></td> <td> <select name="attribute_level[]"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select></td> <td><textarea name="sub_notes[]" rows="1" cols="30"> </textarea></td> </tr> </tbody> </table> </div> <div id="cloneDiv1"> </div> </td> <td> <div id="dynamicInput2"> <table cellpadding="3" cellspacing="3"> <thead> <tr> <th>Neutral Attribute</th> <th>Level</th> <th>Notes <i>(optional)</i></th> </tr> </thead> <tbody> <tr> <td> <select name="attribute2[]" size="1"> <option value="1">Acrobatics</option> <option value="2">Appearance</option> <option value="3">Art Of Distraction</option> <option value="4">Combat Mastery</option> <option value="5">Damn Healthy!</option> <option value="6">Divine Relationship</option> <option value="7">Energy Bonus</option> <option value="8">Extra Attacks</option> <option value="9">Focused Combat</option> <option value="10">Fortified Body</option> <option value="11">Heightened Negaverse Power</option> <option value="12">Heightened Senses</option> <option value="13">Heightened Scout Powers</option> <option value="14">Massive Damage</option> <option value="15">Powerful Mind</option> <option value="16">Special Attack/Defense</option> <option value="17">Speed</option> <option value="18">Strong Soul</option> <option value="19">Supernatural Training</option> <option value="20">Unique Character Attribute</option> </select></td> <td> <select name="attribute_level2[]"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select></td> <td><textarea name="neutral_notes[]" rows="1" cols="30"> </textarea></td> </tr> </tbody> </table> </div> <div id="cloneDiv2"> </div> </td></tr></table> <input type="button" value="Add another Sub-Attribute" onClick="addInput('dynamicInput1','cloneDiv1');"> <input type="button" value="Add another Neutral Attribute" onClick="addInput('dynamicInput2','cloneDiv2');"> <input type="submit" /><input type="reset" /> </form> <script type="text/javascript"> var counter = 1; var limit = 10000000;// Set a limit if you want to function addInput(divFrom,divTo){ if (counter == limit) { alert("You have reached the limit of adding " + counter + " inputs"); } else { var newdiv = document.createElement('div'); newdiv.innerHTML = document.getElementById(divFrom).innerHTML; document.getElementById(divTo).appendChild(newdiv); counter++; } } //function for Power Points function power() { var first,res1; //Take the value of first textbox and convert it to float first=parseFloat(document.forms[0].level.value); res1=(first)*10; //show the result in the result textbox document.forms[0].power_points.value=res1; } //end function for Power Points //function for Character Points remaining function remain() { var first,res2; //Take the value of first textbox and convert it to float first=parseFloat(document.forms[0].level.value); res2=10-((first)*4); //show the result in the result textbox document.forms[0].cp_remain.value=res2; } //end function for Character Points </script> Can anyone help? Hello, I have just started studying JS and don't know a whole lot about it. One exercise I have been given is to use the while statement to ask the user to guess a number between one and ten. this is the code I have attempted so far but it does not work. Simple for any one who is good at this. Impossible to me. Any takershttp://www.codingforums.com/images/smilies/confused.gif <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>While Test</title> <script type="text/javascript"> <!-- function whileTest(){ var number = 4; var answer = 0; while(number != answer ){ answer=prompt("Guesss a number between 1 and ten",""); } alert("4 is the correct answer") //--> </script> </head> <body onLoad="whileTest();"> </body> </html> I'm not very familiar with java script at all, but could someone please explain how to make an if else else statement that follows these guidelines? 1. If the income is $70,000 or above the tax rate starts at 70% (the % sign will not show) 2. If the income is $20,000 or below the tax rate starts at 10% (the % sign will not show) 3. Otherwise the tax rate starts at 25% Thank you SO much! Code: function showResults( results ) { if ( results.length == 0 ) { msg = "no projects found"; } else {msg = results [0]; } document.getElementById("RESULTS").innerHTML = msg; //= results.join( "<br/>" ); cannot get it to show "no projects found" for 0 results and also to show all multiple results if multiple are found. works right now for 1 result but not multiple. the =results.join( "<br/>" ); works if multiple but then it will not say no projects found for 0 results. |