JavaScript - How To Change Option Tag Values With Prompt Window Inputs...
I am working on an interest and investment calculator for a class project. On my list of drop down options, one of the options isnt an integer value like the rest. It's value is "other", while the other three are 1000, 5000, 1000, and 25000. What I would like to do is when the user chooses the "other amount" option from the drop down list, a prompt window will come up asking the user for an investment amount. I am having problems creating a function in my javascript file for this, and then taking the value entered and assigning a variable in another function with that new value so that it calculates with the users input. Please help. The first part of the attachment is the label with the "other" value I explained. And the second piece of code is my mess of a function that I tried to create for the prompt window to come up and store the users value and then change the value of the option. I'm new at this and am lost.....
This is in my HTML: <label for="investment">One-Time Investment:</label> <select name="investment" id="investment" <optgroup label=""> <option value="1000">$1,000</option> <option value="5000">$5,000</option> <option value="10000">$10,000</option> <option value="25000">$25,000</option> <option value="other" >Other value</option> </optgroup> </select><br /> This is in my javascript file: var show_prompt = function() { if ($("other").checked ==true){ var number = prompt("please enter an investment amount", "1000"); var numb = parseFloat(number); $("other").value = numb; }else{ alert("Please enter your investment amount"); } return numb; } Similar TutorialsFigured it out. Thanks
I'm slowly learning javascript, have a little java background. I wanted to just make a button you push to enter a prompt. The problem was I want the prompt message to print in a new window. Here is what I have. Can anyone help me with this? <html> <head> <script type="text/javascript"> function show_prompt() function openindex() { OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no"); { var name=prompt("Please enter your name",""); if (name!=null && name!="") { OpenWindow.document.write("Hello " + name + "! How are you today? Welcome to my Demo page, Enjoy!"); } } } </script> </head> <body> <input type="button" onclick="show_prompt()" value="Click Me " /> </body> </html> Dear all I have been working with with window.promt() and i noticed a weird behaviour. In some cases (i do not known why) my prompt cannot get over a certain limit of characters. But in some other cases it can get as many characters as i want. Anyone know about this? Thanks Alex This is what I have so far which prompts the user three numbers and then displays the max of the numbers and all three of them. Now the last thing I was wanting to do is change it from three prompts to just one prompt. How could I prompt to type in three numbers in one prompt and get the max from those three numbers.? Any help would be greatly appreciated. Thank you in advance! Code: <head> <title>Maximum Number</title> </head> <body> <center><h2>Maximum Number</h2> <script language="Javascript" type="text/javascript"> function Max(num1, num2,num3) { var largest=arguments[num1, num2, num3] for (i=0; i<arguments.length; i++) { if ((num1>num2)&&(num1>num3)) largest=num1 else if((num2>num1)&&(num2>num3)) largest=num2 else largest=num3 } return(largest) } document.write("</br>") var num1=prompt("Enter the first number: ", "") var num2=prompt("Enter the second number: ", "") var num3=prompt("Enter the third number: ", "") var max= Max(num1, num2, num3) document.write("You entered: ", num1, ", ", num2, ", ", num3) document.write("</br>") document.write("The Maximum number is: ", max) </script></center> </body> </html> Hi, In our static few page website, when user open the home page, I want to open one "prompt" kind of window with my own input fields: e.g. One Simple Text Line One anchor link to external link One Text Box to input product key Ok Button Cancel Button. I want this "prompt" kind of window compulsory to attend. Means user will not be able to access the page without responding this window. According to user button pressed "OK" or "Cancel", I want to display the corresponding text in the home page. In short, it will be close to the "window.prompt" but customized and compulsory to respond. Thanks, Hi All, I need to replace the dropdown option values when a different dropdown value is changed. I am calling the javascript function with onChange successfully, but I'm struggling to make the changes. Original Code: <select name="People"> <option value="A">Person A</option> <option value="B">Person B</option> <option value="C">Person C</option> </select> Change to Code: <select name="People"> <option value="X">Person X</option> <option value="Y">Person Y</option> <option value="Z">Person Z</option> </select> Can someone provide an example? Thanks You in Advance for Your Help! i have a archive of data that i want to be loaded in iframes since i have reached a length limit within that page. so what i have is a script that put in a value into a text area, but now i am trying to convert it to putting an src value inside an i frame. i am not the best with javascript so any help would be great. Code: <script type="text/javascript"> function ddl_changed(obj) { var pr = prim.options[prim.selectedIndex].value; var s1 = document.getElementById('s1'); s1.src = pr; } </script> body <div class="prim" align="center"> Database <select id="prim" onchange="ddl_changed(this)"> <option value=" ">Choose a data set</option> <option value="/ds2">data set 1</option> <option value="/ds3">data set 2</option> </select> </div> <iframe name="s1" id="s1" src=" "><p id="noframe">Your browser does not support frames</p> </iframe> thanks Tonight is one of those nights - which seem to be coming more often - where I just can't seem to do anything right. Here is the menu I'm using embedded in HTML: Code: <td width="40%" align="center"><font color="#000099"><b> <select id="Aircraft"> <option value="0">N148LH</option> <option value="1">N149LH</option> <option value="2">N150LH</option> <option value="3">N151LH</option> <option value="4">N152LH</option> <option value="5">N153LH</option> <option value="6">N155LH</option> <option value="7">N156LH</option> <option value="8">N157LH</option> <option value="9">N159LH</option> <option value="10">N162LH</option> <option value="11">N163LH</option> </select></b></font></td> Now I want to use that code to trigger default values for my Empty Weights. This is what I have and isn't working: Code: var selectmenu=document.getElementById("Aircraft") if (Aircraft=0) { df.ew.value = 1569.41; df.ew_mom.value = 135909.2; } if (Aircraft=1) { df.ew.value = 1570.11; df.ew_mom.value = 135929.76; } Any help is appreciated. If anyone is interested the page this is on is here. Hi Coders, I was wondering if anyone knows how you would create a link when clicked will change the width of the content. I have a feeling this will use jQuery? E.g. A link saying 'expand' will change the width of the body to 1000px and change the link to 'contract'. When the link 'contract' is clicked it will change the width back to 800px and change the link to 'expand' Thanks in advance! Haydn. Dear All, The things needs to be work like if I click one of the NA radio button all other radio buttons and comments ,text box, span text needs to be disabled. But the code used below is disabling all the fields. Also if first question NA radio button is clicked first question all other fields should be disabled and shown with red color. If I click on the 2nd question first question fields needs to be enabled and only 2nd question needs to be enabled. The questions will be dynamically loaded based on some other conditions. I am stuck with something on the below. Could you please help to achieve the below concept? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head> <body> <script language="javascript"> function enable_text(status) { status=status; var form = document.forms[0]; var rads = form.elements.radio1; for (var i=0; i < rads.length; i++) { var color = rads[i].checked? "red" : ""; document.getElementById("check"+i).style.backgroundColor = color; document.getElementById("check"+i).disabled = status; } } </script> <body onload=enable_text(false);> <div> <form name="form1" method="post" action=""> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tr> <td class="PortletText1" nowrap><strong>ALL Data</strong></td> <td class="PortletText1" nowrap><strong>YES</strong></td> <td class="PortletText1" nowrap><strong>NO</strong></td> <td class="PortletText1" nowrap><strong>N/A</strong></td> <td class="PortletText1" nowrap><strong>Comments</strong></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td class="PortletText1" nowrap>Data 1:</td> <td class="PortletText1" nowrap><input type="radio" name="radio1" id="check0"/></td> <td class="PortletText1" nowrap><input type="radio" name="radio1" id="check1" /></td> <td class="PortletText1" nowrap> <input type="radio" name="radio1" id="check2" onClick="enable_text(this.checked)" /></td> <td class="PortletText1" nowrap><input type="text" id="other_text0" name="other_text"/></td> </tr> <tr> <td class="PortletText1" nowrap>Data 2:</td> <td class="PortletText1" nowrap><input type="radio" name="radio1" id="check3" /></td> <td class="PortletText1" nowrap><input type="radio" name="radio1" id="check4" /></td> <td class="PortletText1" nowrap><input type="radio" name="radio1" id="check5" onClick="enable_text(this.checked)" /></td> <td class="PortletText1" nowrap><input type="text" id="other_text1" name="other_text"/></td> </tr> <tr> <td class="PortletText1" nowrap>Data 3:</td> <td class="PortletText1" nowrap><input type="radio" name="radio1" id="check6" /></td> <td class="PortletText1" nowrap><input type="radio" name="radio1" id="check7" /></td> <td class="PortletText1" nowrap><input type="radio" name="radio1" id="check8" onClick="enable_text(this.checked)" /></td> <td class="PortletText1" nowrap><input type="text" id="other_text2" name="other_text"/></td> </tr> <tr> </div> </form> </body> </html> </body> </html> thanks in advance. Regards sona i am trying to change my background image after click on given in grid option. any body show me complete code in java script. resource: HP Laptop Repair and Solution Service Center in Delhi Hi, what would be the best way to have a hidden array of possible text directed at a textarea and then if something is not within that array "onfocus", a certain select option is chosen within that form? Thanks Hopefully someone can help a newbie with this. I have a map with onclick areas. When you click these areas, a popup window displays a text file. This is rather cumbersome, so I thought of using a popup box instead of a window and linking this to an onmouseover and onmouseout event. The only problem I have is trying to find out how to dump the contents of the text file into the popup box using the simplest means. The URL of the map I am trying to do this with is: http://www.intercitycharters.com/Weather/Summary.php Any suggestions? var selwindow = window.open('child1.html','_blank','resizable=yes,width='+(screen.width-500)+',height='+(screen.height-500)+''); selwindow.document.selectform.childText.value=document.getElementById('pdetails1').value; I am using this code to assign a value for textbox in the child window. It works well in Internet Explorer, but it shows an error when run in Firefox. It shows: selwindow.document.selectform is undefined. Here, "childText" is the current window textbox id, "pdetails1" is the child window text box id,"select form" is child window form id Hello guys, I've problem with connected database to textbox the value doesn't change. I tried with dropdownlist ,still the same problem. what's the best tool for it. var TextBox3 = document.getElementById("<%=TextBox3.ClientID %>"); var x = TextBox3.value; <asp:TextBox ID="TextBox3" runat="server" DataSourceID="SqlDataSource5" DataTextField="status" DataValueField="status"> </asp:TextBox> <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:RFIDConnectionString %>" SelectCommand="SELECT status from reader where reader_id=2"></asp:SqlDataSource> Thank you I have a simple problem, I can't get the status bar to change. I am very new to javascript, and I am trying to practice some simple commands, and the onMouseOver event is suppose to change the status bar in my window. I can get it to change for onMouseOut but not onMouseOver. Here is what I have so far <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Exam</TITLE> </HEAD> <BODY> <H3>My Page</H3> <a href="http://www.google.com" onMouseOver="window.status='Visit google.';return true;" onMouseOut="window.status='Come back soon ';return true;">Visit Google</a> </BODY> </HTML> I have a script where I need to change input values automatically, and I just can't find the right code for it. Here's a little of my code below, can anyone help me, please? Code: document.getElementById("Id").innerHTML="Text here"; Hi, I'm creating web application that picks out a randomly chosen image from google, and displays it in the browser window every time it is refreshed. What I'm struggling with is that I want the browser window to resize automatically to exactly fit the image displayed. I know how to resize a browser window, but I want it done dynamically. Can anyone help me with this? hey, is there any way i can change an elements properties in window open? i click a link and it opens a window with window.open, and i want to take something from the current page and place it inside a textarea within the opened window.. is it possible? Hello guys. I've been struggling on how to make this work. I have a problem in Javascript when it comes to passing of value in a input type field. page1.html Code: <html> <head><title></title></head> <form action="" method="post> <input type="text" name="weight" value=""><a href="hw_calculator.html" target="name" onclick="window.open('hw_calculator.html','name','height=270,width=370,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes'); return false;"> calculate </a> </form> </html> hw_calculator.html Code: <html> <head> <title> Height Converter (Metric/Standard) </title> </head> <body> <FORM> <INPUT type=hidden value="(Math.round((P.value * 0.45359)*100))/100" name=K_expr> <INPUT type=hidden value="(Math.round((K.value / 0.45359)*100))/100" name=P_expr> <INPUT type=hidden value="(Math.round((F.value * 30.48 + I.value * 2.54)*100))/100" name=C_expr> <INPUT type=hidden value="(Math.floor(C.value / 30.48))" name=F_expr> <INPUT type=hidden value="(Math.round(((C.value - (Math.floor(C.value / 30.48) * 30.48)) / 2.54)*100))/100" name=I_expr> <INPUT type=hidden value="(Math.round(P.value * 0.45359))" name=K_exprrnd> <INPUT type=hidden value="(Math.round(K.value / 0.45359))" name=P_exprrnd> <INPUT type=hidden value="(Math.round(F.value * 30.48 + I.value * 2.54))" name=C_exprrnd> <INPUT type=hidden value="(Math.floor(C.value / 30.48))" name=F_exprrnd> <INPUT type=hidden value="(Math.round((C.value - (Math.floor(C.value / 30.48) * 30.48)) / 2.54))" name=I_exprrnd> <h2>Height Converter</h2> <table border="0" bgcolor="#FFFF99" cellspacing="6" cellpadding="6"> <tr> <td colspan> <p class="conv" style="margin-top: 10px; margin-bottom: 10px"><b>STANDARD</b></p> </td> <td></td> <td colspan> <p class="conv" style="margin-top: 10px; margin-bottom: 10px"><b>METRIC</b></p> </td> </tr> <tr> <td> <p class="conv" style="margin-top: 10px; margin-bottom: 10px">Feet : <input maxLength=1 size=1 value=0 name=F> Inches : <input maxLength=2 size=1 value=0 name=I> </td> <td> <p class="conv" style="margin-top: 10px; margin-bottom: 10px"> = </p> </td> <td> <p class="conv" style="margin-top: 10px; margin-bottom: 10px"><input maxLength=3 size=1 value=0 name=C disabled> cm.</p> </td> </tr> <tr> <td class="conv" colspan="2"> <input type="button" name="Taste" value="Calculate" onclick="if (rounded.checked == true) { eval('C.value = ' + this.form.C_exprrnd.value); eval('K.value = ' + this.form.K_exprrnd.value) } else { eval('C.value = ' + this.form.C_expr.value); eval('K.value = ' + this.form.K_expr.value) }"> <INPUT type=checkbox name="rounded" value="rounded" checked disabled><font size="1" face="Verdana">Rounded Result</font> </td> </tr> </table> <p class="conv" style="margin-top: 10px; margin-bottom: 10px"> </body> </html> I want the value of Code: <input maxLength=3 size=1 value=0 name=C disabled> , this is from hw_calculator.html, to be passed on the Code: <input type="text" name="weight" value=""> on page1.html. How can I do this? Huge thanks. |