JavaScript - Help With Javascript, Prompts Etc.. Not Coming Up.
Ok im doing a basic javascript program as i am just starting out....
I believe you will understand what I am trying to do, basically holiday company they have an initial price that the buyer puts in, then asks for age of the person if person <=5 it's free if person <= 15 its initialprice/2 (or I wanted it as a seperate var not sure if thats the best way to go about it though..) else initial price.... the code i have so far for it is.... Code: var initialPrice; var age; var halfPrice; initialPrice = window.prompt('Please enter the advertised price of the holiday in pounds', ''); initialPrice = parseFloat(initialPrice); age = window.prompt('Please enter age of holidaymaker', ''); age = parseFloat(age); halfPrice = initialPrice/2; if (age <= 5} { document.write('Your holiday is Free'); } else if (age < 15) { document.write('Your holdiday is ' + halfPrice + ''); } else { document.write('Your holiday is ' + initialPrice + ''); } </SCRIPT> Really have no idea why i't wont run.. it's really bugging me as I believe it will be something simple and I just need to know what so I remeber it for next time, any help is MAJORLY appreciated and the sooner the better :) Thanks James (yes i saw the one asking about the same question pretty much a few posts down haha) basically I have some programming doing delphi and pascal and im mixing them up with my very very limited javascript... hence why I think i messed something up.... everything seems to be ok ... but the prompts wont come up or anything.... all the var's match up so what am I doing wrong :( also couple of rules.... im assuming the people inputting are using valid numbers (dont need a check) no need to check for sensible values either dont worry about decimal places (basically the stuff like it checking is for a different part of the assignment that I am doing which i can do by myself if i get this actually working...) Similar Tutorialshey friend i am trying to use automatic html input creation using java script for my new project .... my problem is the field "type propositon 1:is it answer? ignore this one:" not come into input variable such as $_POST['prop1'] i used PHP Code: pint_r($_POST) and the result was Code: Array ( [radio1] => on [cid] => 65 [desc] => dfdfdfdfd [submit] => Submit ) why my javascript created input field come into role? my php html code is PHP Code: <table> <form action="new.php" method="post"> <tr><td> question type:<br /> True or False:<input type="radio" name="radio1"> Objective:<input type="radio" name="radio2"> Other:<input type="radio" name="radio3" > </td></tr> <textarea name="desc" rows="6" cols="35" ></textarea> <br /> <a href="javascript:add()" ><b>add proposition</b></a> <div id="cat"></div> <div id="num" style="display:none;"></div> <br> </table> and the java script is ... PHP Code: <script language="javascript" type="text/javascript"> function add() { k=document.getElementById("num").innerHTML k=parseInt(k); if(!k) {document.getElementById("num").innerHTML=1; k=1;} else{ document.getElementById("num").innerHTML=k+1; k++; } document.getElementById("cat").innerHTML+="<tr><td>type propositon "+(k)+":<input type=\"text\" name=\"prop"+k+"\"><td>is it answer? </td> <td> <input type=\"checkbox\" name=\"ans"+k+"\"></td><td><td> ignore this one:</td><input type=\"checkbox\" name=\"ign"+k+"\"></td></td></tr><br>" } </script> Is there a way to create a prompt in javascript where the prompt doesn't actually pop-up and is instead built into the program/site instead??
I am building a website and I need to gather some information but I feel that prompts are unappealing. Maybe something like a form but it defines whatever is typed in as a variable?
Hello, I wonder if someone could help me with this? I want to include a flights search box on a website I'm building and they have given me some JavaScript to produce it. Test page: http://gercia.co.uk/js.html I want to customise the search box but can't see where the css is contained. Can anyone point it out for me? While these questions have probably been asked before, separately, I'd like to know how to put them together. What I want to do, is create a link, that goes to an url that I decide, after which, the page goes back to the previous page and refreshes. It would be ideal, if that could be done with AJAX, but that's probably asking too much. Especially if I want to use it for wordpress. Hello Again everyone. For the life of me I cannot get a handel on how to access a Form Drop Down menu. I have tried many different codes and tried re-writing my own code in different ways but for reason I am unsure of my VAR myselect will not hold the value of document.getElementById(pathPicking) Below is my current code I am using but first I have tried these different vaients and I ether get nothing printed to teh screen or it will say null. Code: <button type="button" onclick="showme();">Lets test this out</button> * * * var myselect=document.getElementById("pathPicking"); The Code above was a different way i wrote my code (when I wasn't passing anything too the showme function) Code: <html> <body> <form id="aform"> <select id="pathPicking" size="1"> <option value="nothing" selected="selected">Select a location</option> <option value="\\\\mycomputer">\\mycomputer</option> <option value="F:">F: Drive</option> <option value="R:">R: Drive</option> </select> </form> <button type="button" onclick="showme(document.getElementById('pathPicking'));">Lets test this out</button> <script type="text/javascript"> function showme(myselect) { document.write("enter showme function <BR />"); document.write("<BR /> " + myselect); document.write("<BR /> " + myselect.options.length); for (var i=0; i<myselect.options.length; i++) { if (myselect.options[i].selected==true) { alert("Selected Option's index: "+i) break } } document.write("<BR />leaving function"); }; </script> </body> </html> I have a dataTable in which on the keyup event, the cursor focuses to the next field. In IE7, after a field, the next field is not coming into the view. Please help. The occField(2nd attachment) comes into view only after focus moves to next field, i.e LTD Buy up. Code: if (currId.indexOf("Occ") >= 0) { if(stdBuyUpSelected){ autoTabFocus("SBuy",index); }else if(ltdBuyUpSelected){ autoTabFocus("LBuy",index); } else if (isStateZipDisp){ autoTabFocus("Zp",index); } } function autoTabFocus(next,index) { var focusElem = document.getElementById(next+index); if (focusElem != null) { focusElem.focus(); } } I have a form that I am using for several different pages as they are exactly the same... however at the top you must make a choice from the drop down box that then shows the appropriate fields to fill in. Can I make the drop down default to a certain option depending on which page they are coming from? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" > <title>Assignment 5 - JavaScript Loops</title> <head> <script type="text/javascript"> function getGrade(){ var i= Number(document.getElementById("input1").value); m=Math.floor(i/2); for(var k=1; k<=i; k++){ for(var j=1; j<=k; j++){ document.write(j+" "); if(j==k){ document.write("\n"); } if(j==i){ decreaseLoop(j, k); } } } function decreaseLoop(j, k){ for(k=k-1; k>0; k--){ for(var l=1; l<=k; l++){ document.write(l+" "); if(l==k){ document.write("\n"); } } } } } </script> <style type="text/css"> #main{ margin:auto; width:70%; } #top{ font-size:20px; font-weight:bolder; color:#007700; text-decoration:underline; } #s1{ font-size:20px; font-weight:bold; color:#7700ff; } #s2{ font-size:20px; font-weight:bold; color:#00ff00; } #s3{ font-size:20px; font-weight:bold; color:#ff0000; } #form1{ width:600px; height:80px; padding:20px; background-color:#aaaaaa; } </style> </head> <body> <div id="main"> <p id="top">Assignment 5 - JavaScript Loops</p> <span id=s1>This is Form for checking Loop</span> <form id=form1 name=form1> <table> <tr><td>Enter Number </td><td>: <input type="text" id=input1 name="input1" /></td></tr> <tr><td><input type="button" name=btn1 value="Get Number" onclick=getGrade() /></td></tr> </table> </form> </div> </body> </html> When I execute this code, on the screen I see all output in one line. Which is not hat I want. But when I see it in Firebug (for firefox)or Developer Tool Bar(for IE) , I see it printed out in pyramid form(as required). So why is this output in one line on screen ? How cn I get it in pyramid form ? Thanks Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. I want to have another go at Javascript. I have several books on the subject but I find that my eyesight is a major problem. Therefore I want to try an on-line solution, preferably free. I have Googled, but there are so many that I am almost dizzy with the choices. Perhaps someone could recommend one. Not too fussy visually. My knowledge is VERY basic. Frank Does anyone know how to make URL links that use Javascript still work when users have Javascript disabled on their browser? The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version. I tried the <script><noscript> tags, but I'm not sure if I'm using it correctly, as my URL completely disappears. Below is my HTML/Javascript code: <p class="download"> <script type="text/javascript">document.write("<span style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\" onclick=\"window.open( 'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+ Math.floor( Math.random()*11 ) );\" >The Child Magazines Media Kit</a></span> (PDF 1 MB) ");</script> <noscript><span style="text-decoration: underline;"><a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf" >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript> </p> Thanks for any help, Michael Hi, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. Hi Guys, I am new at JavaScript and start to do some tutorials.What I am trying to do here is prompting user to input a name and if the name was valid the page(document) will display with all objects like the button.But if user enter a wrong name then the button will be disabled! I create the following code but it did not work <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>New Web Project</title> <script language="JavaScript" type=""> function changeColor(){ document.bgColor = "Gray"; } </script> </head> <body> <script language="JavaScript" type="text/javascript"> var person = ""; person = prompt('What is Your Name:'); if (person == "Foo") { document.write("<h1 />Welcome " + person); document.bgColor = "Yellow"; } else { document.write("<h1 />Access Denied!!!!"); document.bgColor = "Red"; document.getElementById("gree").disabled = true; } </script> <div> <p/><input id="gree" type="button" value="Gray " onClick="changeColor();"> </div> </body> </html> as you can see I used the: document.getElementById("gree").disabled = true; but it did not work , could you please give an idea how I can solve this problem? Thanks I got an index.php Code: <html> <form action="bacakomik.php" method='post'> <select name="kodekomik"> <option value='../komik1/|23'>Judul Komik1</option> <option value="../komik2/|20">Judul Komik2</option> <option value="../komik3/|10">Juduk Komik3</option> <option value="../komik4/|20">Judul Komik4</option> </select> <input type="submit" /> </form> <?php echo ('<select>'); echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); echo ('</select>'); ?> </html> As you can see, each of the option brings specific value "../komik1/|23" komik1 is a directory | is a delimiter 23 is the pages in one chapter and can be considered also as how many images are there on a specific directory This is my bacakomik.php Code: <?php $dirkomik = $_POST['kodekomik']; $exploded = explode("|", $dirkomik); echo ($exploded[0]); //picture directory echo ("<br>"); echo ($exploded[1]); //total page in the comic $pagecount = (int)$exploded[1]; //Take last posted value, process it right away echo ('<FORM name="guideform"> '); echo ('<select name="guidelinks">'); $i=1; do { echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); $i= $i+1; }while($i <= $pagecount); //Printing option and select echo ("</select>"); ?> <input type="button" name="go" value="Go!" onClick="document.getElementById('im').src=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value+'.png';"> </FORM> <img src="img0.jpg" id="im"> With the current code on bacakomik.php, I only can change the img src of id "im" in the same directory only. What I want is that the Javascript could "add" the "$exploded[0]" variable so that the picture can be loaded from different directory. Anyone can do this? I believe that the fix should be somewhere on input tag inside OnClick, or do you know where? Anyway, I found this on the net http://p2p.wrox.com/php-faqs/11606-q...avascript.html Please help me to those who can... Hey, I've got to make the values of some textboxes change the co-ordinates of my sprite on a canvas and havent a clue on how to do it, Here is my form with the two textboxes and submit button: <form> x: <input type="text" name="x" /><br /> y: <input type="text" name:"y" /><br /> <input type="submit" value="Submit"/><br /> </form> And i need it so that they change the values of these: //this shows where my sprite will start on the canvas var block_x; var block_y; searched the internet for hours and cant really find anything i understand or works. any help is much appreciated Hi Guys I am trying to modify the functionality of my page. I want to be able to activate this piece of code using another javascript function. This is the code I want to activate: Code: <script type="text/javascript"><!-- $('#button-cart').bind('click', function() { $.ajax({ url: 'index.php?route=checkout/cart/update', type: 'post', data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea, .date_data input[type=\'text\']'), dataType: 'json', success: function(json) { $('.success, .warning, .attention, information, .error').remove(); if (json['error']) { if (json['error']['warning']) { $('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.warning').fadeIn('slow'); } for (i in json['error']) { $('#option-' + i).after('<span class="error">' + json['error'][i] + '</span>'); } } if (json['success']) { $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.success').fadeIn('slow'); $('#cart_total').html(json['total']); $('html, body').animate({ scrollTop: 0 }, 'slow'); } } }); }); //--></script> And this is how I want the format of the function to be: function testsession() { if there is a session called 'hiredate' { activate the script above } else { var el = document.getElementById("product_data"); } } I just dont know how to write this in javascript Could you help me if possible please I want to insert this js snippet Code: function addText(smiley) { document.getElementById('message').value += " " + smiley + " "; document.getElementById('message').focus(); return false; } to a loaded iframe with name&id chtifrm. I can access it & change embed something in its html via using something like: Code: $(parent.chtifrm.document.body).append('<div id=\"smly\" style=\"cursor:pointer;float:left;top:200px;display:none;position:absolute;\"><\/div>'); .... Code: parent.chtifrm.document.getElementById('chatbox_option_disco').style.display == 'none' but how do I insert js in the head of loaded iframe? All -- I have a JavaScript config file called gameSetting.js which contains a bunch of variables which configures a particular game. I also have a shared JavaScript library which uses the variables in gameSetting.js, which I include like so: <script type="text/javascript" src="gameSetting.js" ></script> <script type="text/javascript" src="gameLibrary.js" ></script> In gameSetting.js I have: $(document).ready(function() { // call some functions / classes in gameLibrary.js } in Firefox, Safari, and Chrome, this works fine. However, in IE, when it's parsing gameSetting.js, it complains that the functions that live in gameLibrary.js aren't defined. When it gets to parsing gameLibrary.js, the variables in gameSetting.js are reported as not being defined. I've tried dynamically bootstrapping the gameLibrary file using this function in document.ready for dynamic load... $.getScript("gameLibrary.js"); However, the same problem still happens in IE, where when it parses the files individually it's not taking into context the file/variables that came before, so it's not an out of load order problem. My options a 1) collapsing all the functions in gameLibrary.js and variables in gameSetting.js into one file. However, this is not practical because this is dealing with literally hundreds of games, and having a gameLibrary.js in ONE location for ONE update is what makes most logical sense. 2) figure out a way to get this to work where variables in file1 are accessible to file2 in IE (as it seems they are in other browsers). jQuery seems to be able to have multiple plugins that all refer to the based jQuery-1.3.2.js, so I know there is a way to get this to work. Help appreciated. Nero I wrote a log function that took note of various function calls. Thinking that functions are first class objects, and objects have properties, I made the name of each logged function a property of that function, e.g., brightenInnerPara.name = "brightenInnerPara"; Every browser I tried (Firefox, MSIE, Opera, Chrome, Safari) accepted the assignment, no problem. In Firefox and MSIE, the result was what I wanted: brightenInnerPara.name == "brightenInnerPara" But in the others, the result was: brightenInnerPara.name == null Question 1. Which Javascript is correct here? I favor Firefox and MSIE, not merely because they were willing to give me what I wanted, but also because it makes no sense to accept an assignment statement without throwing an error and then give it a null semantics, like Chrome, Opera, and Safari did. I found a workaround, using assignments like this: brightenInnerPara.prototype.name = "brightenInnerPara"; To my surprise, that worked in every browser. But I don't know why. It seems that such assignments are enough to cause each function to have its own distinct prototype. Question 2. Just how inefficient is my workaround, and why does it work? |