JavaScript - How To Make Text Appear After The Prompt.
Hello All,
I have made a prompt and marked it in bold below. I would like text to appear after what the person has entered At current it reads Hello (Name Prompt) I would like it to appear saying something on the lines of Hello (Name Prompt) Enjoy The Game. Any Ideas? <html> <body> <SCRIPT LANGUAGE="JavaScript"> <head> <TITLE>Find the Correct Number Game</TITLE> </head> a=(prompt('please enter your name:',0)); // prompt for player name document.write(' Hello ' ,a); var guessme=Math.round(Math.random()*(49)+1); var speech='Choose a number between 1 and 50'; function process(hiddennumber) { var guessnumber=document.forms.guesstable.guessnumber.value; var speech='"'+guessnumber+ '" Letters are not allowed. Please enter digits only!.'; document.forms.guesstable.guessnumber.value=''; if (guessnumber==hiddennumber) { document.forms.guesstable.prompt.value='Congratulations! '+hiddennumber+' is correct!'; alert ('Well done - the mystery number is '+hiddennumber+'! \n\nIf you want to play again click the button.'); speech=''; document.location=document.location; } if (hiddennumber<guessnumber) { speech='Less than '+ guessnumber; } if (hiddennumber>guessnumber) { speech='Greater than '+ guessnumber; } if (guessnumber=='') { speech='You didn\'t guess anything!' } document.forms.guesstable.prompt.value=speech; document.forms.guesstable.guessnumber.focus(); } </SCRIPT> </body> </html> <FORM onSubmit="" NAME="guesstable"> <CENTER> <TABLE ALIGN="left" BGCOLOR="#888889" BORDER="5" CELLPADDING="5"> <TR> <TD BGCOLOR="#004081"> <FONT COLOR="#ffffff" FACE="Arial"><B>Find the Correct Number</B></FONT> </TD> </TR> <TR> <TD> <CENTER> <INPUT TYPE="text" NAME="prompt" SIZE="31" MAXLENGTH="60" VALUE="Find the correct number which is between 1 and 50"><BR> <INPUT TYPE="text" NAME="guessnumber" SIZE="3" MAXLENGTH="3" VALUE=""> <INPUT TYPE="button" VALUE="Enter" onClick='process(guessme)'> </CENTER> </TD> </TR> </TABLE> </CENTER> </FORM> Similar TutorialsHi there, I want to prompt a user to enter their name, if the user entry includes numbers I would like to prompt them to re-enter their name using only text. I have tried: Code: var userName = prompt ("Please enter your name", " "); if (userName == null || !isNaN(userName)) { prompt ("Please enter a valid name, and do not include any numbers in this field"); userNamm.focus(); } else { document.write("Welcome back " +userName); } It isn't working, I would like to monitor the user entry for only text values, can anyone help me to clean this up? hey im new to javascript and im working in this function , i can't get it work here is my code PHP Code: <SCRIPT LANGUAGE="JavaScript"> function text(form1) { var j = document.form1.diary.value; j = j.italics(); document.form1.diary.value = j ; } </SCRIPT> whats the problem ? Hello, I wonder if you guys.girls would be kind enough to help me. I have some code, but I need to make the " Total price will be :$xx " text to be in bold. Here is the code I have atm Code: <script type=text/javascript> function getTotal(){ var form=document.theForm; var inputs=form.getElementsByTagName('input'); var length=inputs.length; var total='0'; for(i=0;i<length-1;i++){ if(inputs[i].type=='radio'){ var checked=inputs[i].checked?1:0; if(checked){ var value=inputs[i].value.split("~~")[0]; total-=-value; } } } document.getElementById('totalspan').innerHTML="Total price will be: $"+total total='0'; } </script> </html> Hello guys! Subject is not clear, but I will have it as clear as I can! First, I am totally new to the JS! I have some skills but not too much! here is a code: PHP Code: <? include('func.php'); ?> <html> <head> <script language="JavaScript" type="text/javascript"> function editfield(u){ var user = document.getElementById(user); } </script> </head> <body> <table border="1"> <tr> <td> username </td> </tr> <? while ($row = mysql_fetch_array($SQL)) { echo '<tr>'; echo '<td name="user" onDblcilck="editfield()">' . $row['username'] . '</td>'; echo '</tr>'; } // HOWEVER! I need to edit $row['username']. So, on double click i need it to change to <input type="text" /> field! // And then I need to get that variable of the edited username, and submitted it through a form to the db! ?> </table> </body> </html> I need when dblclick to convert the <td> to <input />! And I want to get the value of the edited user to submitted to the database! Ok, so i got two buttons made with css, that i want to link to two different text that will appear in a <div> when i press them. Quote: <a href="#" class="title4"value="Click" onclick="document.getElementById('introduktion').innerHTML=''"/> Introduktion </a> <a href=".pdf" class="title4" > CV </a> <a href="#" class="title5"value="Click" onclick="then var name =.innerHTML;document.getElementById('presentation').innerHTML=''"/ >Presentation </a> </div> <div class="post"> <div class="text" style="; height:387px; width:400px; overflow:auto;"> <br> <span id="introduktion" href="#"> <font size="2"> text 1 </span> <span id="presentation" href="#">text 2 </span> The button works, but when i press them more than once everything disappears... Do anyone have any idea on how to solve this problem? Hi, I found the following code on a web site. It displays text as if it were being typed but it only does it once. I have been trying to use various functions to make the effect continuous, i.e. make the header appear as typing text, clear the text, again make the header appear as typing text, clear the text, and so on. I wish this to continue for as long as the web page is open. But I just can't get it to work. I wonder if anyone has any suggestions? I would be very grateful for all help. [code] <h2 id="fly">Header</h2> <script type="text/javascript"> //Use "$" for linebreak //By default, set to just grab the text from element with ID="fly" message = document.getElementById("fly").innerHTML; // $ = taking a new line distance = 50; // pixel(s) speed = 200; // milliseconds var txt="", num=0, num4=0, flyofle="", flyofwi="", flyofto="", fly=document.getElementById("fly"); function stfly() { for(i=0;i != message.length;i++) { if(message.charAt(i) != "$") txt += "<span style='position:relative;visibility:hidden;' id='n"+i+"'>"+message.charAt(i)+"<\/span>"; else txt += "<br>"; } fly.innerHTML = txt; txt = ""; flyofle = fly.offsetLeft; flyofwi = fly.offsetWidth; flyofto = fly.offsetTop; fly2b(); } function fly2b() { if(num4 != message.length) { if(message.charAt(num4) != "$") { var then = document.getElementById("n" + num4); then.style.left = flyofle - then.offsetLeft + flyofwi / 2; then.style.top = flyofto - then.offsetTop + distance; fly3(then.id, parseInt(then.style.left), parseInt(then.style.left) / 5, parseInt(then.style.top), parseInt(then.style.top) / 5); } num4++; setTimeout("fly2b()", speed); } } function fly3(target,lef2,num2,top2,num3) { if((Math.floor(top2) != 0 && Math.floor(top2) != -1) || (Math.floor(lef2) != 0 && Math.floor(lef2) != -1)) { if(lef2 >= 0) lef2 -= num2; else lef2 += num2 * -1; if(Math.floor(lef2) != -1) { document.getElementById(target).style.visibility = "visible"; document.getElementById(target).style.left = Math.floor(lef2); } else { document.getElementById(target).style.visibility = "visible"; document.getElementById(target).style.left = Math.floor(lef2 + 1); } if(lef2 >= 0) top2 -= num3 else top2 += num3 * -1; if(Math.floor(top2) != -1) document.getElementById(target).style.top = Math.floor(top2); else document.getElementById(target).style.top = Math.floor(top2 + 1); setTimeout("fly3('"+target+"',"+lef2+","+num2+","+top2+","+num3+")",50) } } stfly() </script> [code] Here is my validation script from dreamweaver i also have it in php for server side. But I trying to get a checkbox to make a text field required when you select it. Right now I have it so when you hit submit whether the text field is filled out or whether the checkbox is selected or not the error message comes up no matter what i do please help. the link to the page is http://www.mark-10.com/inquiries2 Code: function validateCheckbox() { if(document.forms["form1"].sales.checked) { if(document.forms["form1"].telephone.value.length < 12) { // xxx-xxx-xxxx return false ; } else { return true; } } } function MM_validateForm() { //v4.0 if (document.getElementById){ var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]); if (val) { nm=val.name; if ((val=val.value)!="") { if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n'; } else if (test!='R') { num = parseFloat(val); if (isNaN(val)) errors+='- '+nm+' must contain a number.\n'; if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); min=test.substring(8,p); max=test.substring(p+1); if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; } } if(!validateCheckbox()) { errors+="If checkbox checked, please include telephone number"; } if (errors) alert('The following error(s) occurred:\n'+errors); document.MM_returnValue = (errors == ''); } } //--> I've been asked to create a program which allows meteorologists to input a certain amount of data inputs of snowfall, and then the individual snowfall of each input itself. In my mind this should prompt me for a data input as many times as their are inputs, however, it works only for the first data input, then it returns to blank page without prompts for the second input... Any clues as to where I'm going wrong? After searching this site I could not find any old posts on how to position the PROMPT box. As default (as you all most likely know) the prompt box in IE browser comes up in the top left corner. not very visable and would like to center it so it would be more visiable to the user being prompted. Can someone help me with this? thanks John Trying to get this prompt window to work so I can begin a calulation function--Am I even in the ballpark? var chargeAmount = window.prompt("Enter a charge amount", Enter charge amount here."); var discountPercent; var totalCharges; function confirmSubmit() { if (document.forms[0].name.value == "" || document.forms[0].name.value == "Enter your name") { window.alert("You must enter your name."); return false; } function confirmReset() { var resetForm = window.confirm("Are you sure you want to reset the form?"); if (resetForm == true) return true; return false; } } /* ]]> */ </script> </head> <body> <h2>Charge Information</h2> <form action="FormProcessor.html" method="get" enctype="application/x-www-form-urlencoded" onsubmit="return confirmSubmit();" onreset="return confirmReset();"> <p>Customer Name: <input type="text" name="name" value="Enter your name" /> </p> <p>Customer Type:</p> <input type="radio" name="rb" value="regular" />Regular<br /> <input type="radio" name="rb" value="silver" />Silver<br /> <input type="radio" name="rb" value="gold" />Gold<br /> <br /><br /> Total Charges:  <input type=text value="" name="total charges" size=10;> <br /><br /> Discount:  <input type=text value="" name="discount" size=10;> <br /><br /> Payment:  <input type=text value="" name="payment" size=10;> <input type="button" name="calc" value="Calculate Payment" onClick="return calcpay(this.form)"> <input type="reset" name="reset" value="Reset Form" > </form> </body> Code: <script> var name = prompt('What\'s your name?'); function myOnLoad() { document.getElementsByTagName('name').innerHTML = name; } </script> <body onLoad="myOnLoad()"> This person's name is <name></name>.<br> <name></name> is someone who has just passed thorought this page.<br> Say bye to <name></name>! How come this code doesn't work? I'm working on an html form that will be launched from within another application, but every time it launches the form none of the JS coding works because of the stupid IE security. If I launch the form from outside the application I just have to select "allow blocked content" from that stupid information bar that says "to help protect your security IE has restricted the webpage from running scripts...." I added the application site to our trusted sites and basically turned off security for that zone but it still doesn't work. Obviously there is a way to run JS without allowing the content, but I don't do enough coding to know how that is done. Can someone help me out please? I need the JS to run automatically without that information bar appearing at all. When you do an alert confirm you can make if statements to say if they click ok do this and if they click cancel stop the program. Well I am trying to make a prompt that first asks the user to enter in a url and after they do and click enter they url is wraped with img tags. I would like to make it so that if the user clicks cancel the program ends b/c right now if the user click okay with no value the result is [img][/img] and if the user clicks cancel the result is [img]null[/img]. Any step in the right direction would be greatly appreciated! PHP Code: <script language="javascript"> function imgGenerator(){ var question=confirm("Would you like to share an image?"); if (question==true){ var obj=document.getElementById("mngl-board-post-input"); var imgurl = prompt("To Share an image paste the image url here"); var txt=document.createTextNode("[img]"+imgurl+"[/img]"); obj.appendChild(txt); } else {} } </script> We were given a task at school today. Basically we need to have a prompt box popup, and the user enters numbers 1-12 (1 for each month of the year). The prompt keeps popping up until the user types "stop". It will display the months that were entered. Could anyone assist me with this, thanks. How do i use html forms in the same way as prompts? I want to do something like this: Code: <html> <head> <script type="text/javascript"> var cpu= prompt("What brand of CPU would you like?"); var ram= prompt("What brand of RAM would you like?"); var hdd= prompt("What brand of Hard Drive would you like?"); </script> </head> <body> <script type="text/javascript"> document.write("The brand of CPU I want is "+cpu); document.write("<br> The brand of RAM I want is "+ram); document.write("<br> The brand of Hard Drive I want is "+hdd); </script> </body> </html> But instead of having a notification box, I want a form. Is this possible? I dont like how it pops up... I am fairly new to Javascript. From what I can compare to sample codes this should work. I have a button with an onclick that opens a prompt. Compares whats written to a php SESSION variable. If true redirects, if false displays an alert. However, all of this means nothing because when I press the button, no prompt comes up! Heres the code Code: <head> <script type="text/javascript"> function passPrompt() { var pass=prompt("Please enter your password:","") if pass = <?php $pwd ?> header('Location: setup.php'); else alert("Password is incorrect"); } </script> </head> ... <input id="settings" type="button" name="settings" value="Settings" onclick="passPrompt()" /> I am ignorant in java scripting. I want to use the following java script to create the radiobutton in obiee reporting. This java script will change the regular prompt to radio button,however I do not know how to debug if it is working. Waiting for kind reply. Anil PHP Code: <script type="text/javascript"> function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; } var tables = getElementsByClass('DashboardPromptViewTable',null, 'table'); for (var table = 0; table < tables.length; table++){ var stringFunc = ''; var selects = tables[table].getElementsByTagName('select'); if ( selects.length == undefined || selects.length == 0 || selects[0].name === 'Match'){ if (debug === 1) { document.write("No selects found. Continue to next record."+"<BR>");} continue; // This DB Prompt doesn't have any select statements } var spans = getElementsByClass('minibuttonOn',tables[table],'span'); spans[0].style.display="none"; stringFunc = String(spans[0].getElementsByTagName('a')[0].onclick); stringFunc = stringFunc.substr(stringFunc.indexOf('{')+1, stringFunc.length - 2 - stringFunc.indexOf('{')); for (var s =0; s < selects.length; s++){ var new_form = document.createElement('form'); var options = selects[s].getElementsByTagName('option'); new_form.name = selects[s].name+"_radio"; new_form.id = selects[s].id+"_radio"; for (var o=0; o<options.length; o++) { var new_input = document.createElement('input'); new_input.type = 'radio'; new_input.value = options[o].value; new_input.name = selects[s].name+"_radio"; if(selects[s].selectedIndex == o){ new_input.checked = true; } var onClickStringFunc = "var sel = document.getElementById(this.name.substr(0,this.name.length-6));" + "if ( sel == null){"+ "return;"+ "}"+ "var opts = sel.getElementsByTagName('option');"+ "for( var opt = 0; opt < opts.length; opt++){"+ "if( opts[opt].value == this.value){"+ "sel.selectedIndex = opt;"+ "}"+ "}"; new_input.onclick = new Function(onClickStringFunc + stringFunc); var new_text = document.createTextNode(options[o].innerHTML); new_form.appendChild(new_input); new_form.appendChild(new_text); } // end options for loop selects[s].parentNode.insertBefore(new_form,selects[s]); selects[s].style.display="none"; } // end selects for loop } // end table foor loop </script> Figured it out. Thanks
I am new to learning JS and am trying to create an array through a prompt. It seems to work, but I believe it is treating the prompted numbers as strings not numbers. I am parsing the negatives and zeros, and positives and counting them. It doesn't recognize the negative sign. Here's my js: function counter() { var numArr = new Array(Number(prompt("Please enter and array of numbers, in any order, separated by a comma..." + '\n' + "In the following format: -2,0,2"))); var positives = 0; var negatives = 0; var zeros = 0; for (var i = 0; i < numArr.length; i++) { switch (true) { case numArr[i] < 0: negatives++; break; case numArr[i] == 0: zeros++; break; case numArr[i] > 0: positives++; break; } } alert("You entered:"+ '\n' + "Number of Negatives: " + negatives + '\n' + "Number of Zeros: " + zeros + '\n' + "Number of Positives: " + positives); } counter(); Any suggestions? Issue: I have a java script that bring up a simple password box, It works great in Chrome, Safari, firefox but I get a box in Internet explorer asking my customers to take another step to allow access. This is not good, Customers did not now what to do. Error: This website is using a scripted window to ask you for information. If you trust this website, click here to allow scripted windows Microsoft response: "Internet Explorer has blocked a website from using a small program (called a script) to display a separate window. Hackers sometimes use scripted windows to mimic legitimate windows, such as login screens, that appear on websites. If you trust the website and want to allow the scripted window, click the Information Bar, and then click Temporarily Allow Scripted Windows. To always allow scripted windows, check the Allow websites to prompt for information using scripted windows custom security setting." Objective: I now there is likely no way to by pass this, so i need a different solution. Possible a Form Box to be present on the site that when information is entered it passes the password to the javascript code to allow access? Please help, this is actually urgent as I have already lost a customer :-( Code: : <script> function getStyle() { var temp = document.getElementById("admintable").style.visibility; return temp; } function switchMain() { var isAuthed = authenticate(); if(isAuthed){ var current = getStyle(); if( current == "visible" ){ document.getElementById("admintable").style.visibility = "hidden"; }else{ document.getElementById("admintable").style.visibility = "visible"; } } } function authenticate() { if(readCookie('authenticated')!=null) { return true; } else{ var password=prompt("Enter Code","") if (password =="1234") { createCookie('authenticated',true); return true; } } return false; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } </script> Here is what I found online: http://www.anyexample.com/webdev/jav...lternative.xml UPDATE: I am a n00b, I need to incorporate this code below to the one above. Thanx Philip Code: <input type = "password" name = "pwd" id = "pwd" onchange = checkPassword(this.value)" <script type = "text/javascript"> function checkPassword(which) { if (which != "1234") { // password is visible!!! alert ("Incorrect password - please try again"); document.getElementById("pwd").value =""; return false; } else { alert ("Password is correct!"); //do more stuff here, e.g create the cookie } } </script> |