JavaScript - Textbox Enter Dollar Value, Update Another With Paypal Charge Included
Looking for an example of how to take the value typed in one textbox to be calculated and update the value of a second texbox on the fly.
The calculation is, (2.9% X first textbox value) + $0.30 = second textbox value Similar TutorialsI have a textbox on my webpage where you can enter a title. I then have a button that goes to my javascript and starts a timer. Well if the user presses enter on the text box I want it to start the time. Well it goes to the code, but then like refreshes the website and starts from the start. How can I get around this? When I click the button there is no issues at all. Textbox: <input type="text" id="titleMainT" value="N/A" size="27" onkeypress="startTimer();"/> Button: <input type="button" id="startbutton" value="Start Timer" onclick="startTimer();" /> I've got this form on my page that contains a search box and a select box full of employee names. When you type a few letters in the search box it scrolls through the listbox to the first match and then if you click on that name it executes a function. Today though one of my coworkers pointed out that some people would just hit enter inside the search box and he's right about that. So I looked around and found the solution for it, it's the onkeydown event I added to the search box. Weird thing is though when you type a name in the box and hit enter it executes properly and then the page immediately reloads Without the onkeybown event, hitting Enter still makes the page reload so it's gotta be something about the form. Can anyone pick out the bug? Thanks. <form name="people_form" style="margin: 0px"> <input type="text" id="peoplesearch" name="peoplesearch" onkeydown="if (event.keyCode == 13) search_onblur()" onblur="search_onblur()" onkeyup="suggestName();" onfocus="this.value=''" style="margin: 0px 0px 5px 0px; padding: 0px; width: 215px"></input> <select onchange="display.apply(this, this.value.split(','))" size="15" id="People" name="People" style="border-style: none; height:244px; width:220px; margin-bottom: 15px;"> <option>Loading</option> </select> </form> I'm trying to update a freemarker template to do the following. Currently, there is a text input area on the page defined as: <input id="ne-tags" type="text" name="tags" value="${tags!?html}" size="50" class="ne-form-textinput"/> All I'm trying to do is add a few different keywords at the top of the page. i.e.: <div onclick=""> add this text! </div> <div onclick=""> add more text! </div> When the user clicks on the keyword, it should append it to the text already in the text input area. I tried to write and call a function, write it directly into the onclick area etc, but nothing ever happens on the page. Seems very simple, but I haven't worked with JS in many years. Can anybody give me a quick sample of how to build this? My problem is the following. I have an editable <div>: <div class='edit' id='divContent' name='divContent' ContentEditable>some text</div> If I press 'enter' two lines are skipped. I know that if I press 'shift+enter' only one line will be skipped. If I check the unformatted code of the contenteditable div, 'enter' gives me <p> and 'shift+enter' gives me <br>, which makes sense because <p> is formatted differently than <br>. So I want to change 'enter' into 'shift+enter' I have already found something to capture and kill 'return' function killReturn() { key = event.keyCode; if (key == 13) return false; } But now for some means to replace the killed 'enter' with 'shift+enter'? Thanks a lot in advance for any advise! hi. i know php but learning javascript. can anybody give me a reason why i might not wanna use the php practice of beginning every variable_name with a dollar-sign: $variable_name??? i am just accustomed to seeing my variables beginning with a dollar_sign. Thanks. So if I have three dollar amounts like .... a = 1,222.00; b = 1,323.00; c = ; d = 1,222.00; How can I alert the highest variable even though there may be 1 or more of them? Hi, I'm trying to add the total number of costs depending on the rows added to return the subtotal then later add the service charge which gives the total grand amount. I also need to add the item number when a new row is added. Can any1 help? Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>untitled</title> <script type="text/javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i<colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; //alert(newcell.childNodes); switch(newcell.childNodes[0].type) { case "text": newcell.childNodes[0].value = ""; break; case "checkbox": newcell.childNodes[0].checked = false; break; case "select-one": newcell.childNodes[0].selectedIndex = 0; break; } } } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { if(rowCount <= 1) { alert("Cannot delete all the rows."); break; } table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } </script> </head> <body > <form action="#" id="calcForm" method="post"> <table border="0" width="680" cellpadding="0" cellspacing="0"> <tr> <td width="60" align="left" valign="top"><b>Item No</b></td> <td width="3"> </td> <td width="290" align="left" valign="top"><b>Description</b></td> <td width="3"> </td> <td width="210" align="left" valign="top"><b>Part No.</b></td> <td width="3"> </td> <td width="50" align="left" valign="top"><b>QTY</b></td> <td width="3"> </td> <td width="63" align="left" valign="top"><b>Cost</b></td> </tr> </table> <table id="parts" border="0" width="680" cellpadding="0" cellspacing="0"> <tr> <td width="60" align="left" valign="top"><INPUT type="checkbox" name="chk"/> <b>1</b></td> <td width="3"> </td> <td width="290" align="left" valign="top"> <input type="text" name="partdesc[]" size="40" value="<?=$info['partdesc'][$x]?>"> </td> <td width="3"> </td> <td width="210" align="left" valign="top"> <input type="text" name="partno[]" size="30" value="<?=$info['partno'][$x]?>"> </td> <td width="3"> </td> <td width="50" align="left" valign="top"> <input type="text" name="qty[]" size="2" value="<?=$info['qty'][$x]?>"> </td> <td width="3"> </td> <td width="63" align="left" valign="top"> <input type="text" name="cost[]" size="4" value="<?=$info['cost'][$x]?>"> </td> </tr> </table> <table id="parts" border="0" width="680" cellpadding="0" cellspacing="0"> <tr> <td width="60" align="left" valign="top"> </td> <td width="3"> </td> <td width="290" align="left" valign="top"> </td> <td width="3"> </td> <td width="210" align="left" valign="top"><b>Sub Total</b></td> <td width="3"> </td> <td width="50" align="left" valign="top"> </td> <td width="3"> </td> <td width="63" align="left" valign="top"> <input type="text" name="subtotal" size="4" value="<?=$info['subtotal']?>"> </td> </tr> <tr> <td width="60" align="left" valign="top"> </td> <td width="3"> </td> <td width="290" align="left" valign="top"><INPUT type="button" value="Add Row" onclick="addRow('parts')" /><INPUT type="button" value="Delete Row" onclick="deleteRow('parts')" /></td> <td width="3"> </td> <td width="210" align="left" valign="top"><b>Service Charge</b></td> <td width="3"> </td> <td width="50" align="left" valign="top"> </td> <td width="3"> </td> <td width="63" align="left" valign="top"> <input type="text" name="charge" size="4" value="<?=$info['charge']?>"> </td> </tr> <tr> <td width="60" align="left" valign="top"> </td> <td width="3"> </td> <td width="290" align="left" valign="top"> </td> <td width="3"> </td> <td width="210" align="left" valign="top"><b>Grand Total</b></td> <td width="3"> </td> <td width="50" align="left" valign="top"> </td> <td width="3"> </td> <td width="63" align="left" valign="top"> <input type="text" name="gtotal" size="4" value="<?=$info['gtotal']?>"> </td> </tr> </table> </form> </body> </html> Hi.. I have form and i want to input data using barcode and it will display on textbox and after input on the first textbox the focus will go to next textbox untill it will go on the last textbox and on the last textbox it will automatically save the data's on the database. How is it possible? here is my sample code: Code: <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); ?> <html> <head> <script type="text/javascript"> function ini() { // Retrieve the code var code =document.getElementById ("code_read_box1").value; var code =document.getElementById ("code_read_box2").value; var code =document.getElementById ("code_read_box3").value; var code =document.getElementById ("code_read_box4").value; var code =document.getElementById ("code_read_box5").value; var code =document.getElementById ("code_read_box6").value; // Return false to prevent the form to submit return false; } </script> </head> <body onLoad="document.barcode.code_read_box1.focus()"> <form name=barcode onsubmit = "return ini()"> <input type="text" id="code_read_box1" value="" /><br/> <input type="text" id="code_read_box2" value="" /><br/> <input type="text" id="code_read_box3" value="" /><br/> <input type="text" id="code_read_box4" value="" /><br/> <input type="text" id="code_read_box5" value="" /><br/> <input type="text" id="code_read_box6" value="" /><br/> </form> </body> </html> Hello. I've been teaching myself HTML and CSS for a while, and now I've moved into the world of Javascript (but I'm still very much a beginner). For practice, I've been building a sample sign up form for a mock website, and I'm having problems with the birthdate section. The idea I had was to have MM, DD, and YYYY be the default values of my 3 textboxes (as an example for users), then set the value to nothing when the box gained focus. That all works fine, but I ran into problems when I tried to write an if statement to set the value back to MM, DD, or YYYY if the value was still nothing when the user clicked away. As it is now it just replaces the text inputted into the textbox (which of course is not good). Any ideas for what the problem might be? Code: <form name="signup" action="javascript:void(0);" method="post"> <table> <tr> <td>Date Of Birth:</td> <td> <input name="DOBmonth" type="text" value="MM" size="2" style="color: #555555;" onFocus="clearDOBmonth()" onBlur="restoreDOBmonth()" /> <input name="DOBday" type="text" value="DD" size="2" style="color: #555555;" onFocus="clearDOBday()" /> <input name="DOByear" type="text" value="YYYY" size="4" style="color: #555555;" onFocus="clearDOByear()" /></td> </tr> <tr> <td></td> <td><button name="Submit" type="submit" style="font-size: 1em;">Sign Up</button></td> </tr> </table> </form> <script type="text/javascript" language="javascript"> <!-- document.signup.DOBmonth.value="MM"; document.signup.DOBday.value="DD"; document.signup.DOByear.value="YYYY"; function clearDOBmonth() { document.signup.DOBmonth.value="";} function clearDOBday() { document.signup.DOBday.value="";} function clearDOByear() { document.signup.DOByear.value="";} function restoreDOBmonth() { if ('document.signup.DOBmonth.value = ""') { document.signup.DOBmonth.value = "MM"; // alert(document.signup.DOBmonth.value); } } //--> </script> Another side question, if I set a variable equal to the value of a textbox, then change the value of the variable, does that also change the value of the textbox? or is the variable no longer associated with the textbox. Example: Code: var a = document.form.textbox.value; a = blue; does document.form.textbox.value = blue? or is var a now completely independent of the textbox value? Thanks! Hi codingforums.com, i have been working on a programm for some time and now i have decided to include some javascript to it and have only very limited knowledge so i copied something from a website and tried to modifiy it but only with partial success. Would be awesome if someone can guide me a littlebit. So i have 2 select boxes and want the second one to be filled depending on the chosen option from the first one. And 'on the fly' so with imediate change. So now i have the following code which gives me the first selectbox sucessfully filled with 'customers' in that case but i dont manage to give the second one listed in order, the are all on the same line displayed as one option. here my code: Code: <?php //read html header require('html/header.html'); //error display error_reporting(E_ALL); ini_set('display_errors', 1); include('conn.php'); ?> <div align="center"> <form name="classic"> <select name="customer" size="5" onChange="updatesystem(this.selectedIndex)"> <?php //prepare SQL query $query = "SELECT * FROM VIA_CUSTOMER ORDER BY ACRONYM ASC"; //parsing sql statement $statement = oci_parse($conn, $query); //execute sql statement and display results if(oci_execute($statement)) { while(ocifetchinto($statement, $result, OCI_ASSOC)) { echo "<option align='center' value='".$result['ACRONYM']."'"; if(isset($_GET['VIA_CUSTOMER']) && $_GET['VIA_CUSTOMER'] == $result['ACRONYM']) { echo "selected='selected'"; } echo ">".$result['ACRONYM']."</option>"; } } oci_free_statement($statement); ?> </select> <select name="system" size="5" style="width: 150px" onClick="alert(this.options[this.options.selectedIndex].value)"> </select> </form> </div> <script type="text/javascript"> var customerlist=document.classic.customer var systemlist=document.classic.system var system=new Array() system[0]=["ARRAY0", "<?php //prepare SQL query $query = "SELECT NAME FROM VIA_SYSTEM WHERE IDCUSTOMER = 1 ORDER BY NAME ASC"; //parsing sql statement $statement = oci_parse($conn, $query); //execute sql statement and display results if(oci_execute($statement)) { while(ocifetchinto($statement, $result, OCI_ASSOC)) { echo $result['NAME']; } } oci_free_statement($statement); ?>", "ARRAY0.1", "ARRAY0.2"] system[1]=["ARRAY1", "ARRAY1.1", "ARRAY1.2"] system[2]=["ARRAY2"] system[3]=["ARRAY3"] system[4]=["ARRAY4"] function updatesystem(selectedsystemgroup){ systemlist.options.length=0 if (selectedsystemgroup>=0){ for (i=0; i<system[selectedsystemgroup].length; i++) systemlist.options[systemlist.options.length]=new Option(system[selectedsystemgroup][i].split("|")[0], system[selectedsystemgroup][i].split("|")[1]) } } </script> <? //include html footer require('html/footer.html'); ?> now my problem is within this piece of code: Code: <?php //prepare SQL query $query = "SELECT NAME FROM VIA_SYSTEM WHERE IDCUSTOMER = 1 ORDER BY NAME ASC"; //parsing sql statement $statement = oci_parse($conn, $query); //execute sql statement and display results if(oci_execute($statement)) { while(ocifetchinto($statement, $result, OCI_ASSOC)) { echo $result['NAME']; } } oci_free_statement($statement); ?> how can i get the Code: WHERE IDCUSTOMER = 1 to be chosen from the first select box because $_GET wont work obviously and how can i display the results all as single arrays and not one single line? i know this might be a lot to ask but im still learning and cant get past this with just searching google. This is a picture of the output, the first select is good but the second one is the issue and the 'ARRAY0.1' is just dummy data (not from database) so it should be displayed as single lines like so: LSM SQL*LIMS TEST i would be eternally grateful for whom can help me out with this. Regards, The Noob [delete]
hey all, I have had a go at another calculator I am making and got stuck. I want to use the F value determined by the first toggle button in the calculation. I dont understand why the calculation wont work as it is stated in the if/else statement. Any suggestions what i am doing wrong? here is the code: Code: <script type="text/javascript"> function toggle(btn) { var radioSelection = btn.value; if (radioSelection == "PO") { var F = 0.7; } else { var F = 1; } } function toggle(btn) { var radioSelection = btn.value; var weightInput = document.getElementById("weightRow"); var CPsInput = document.getElementById("CPsRow"); var creInput = document.getElementById("creRow"); var CHFInput = document.getElementById("CHFrow"); var LDOutput = document.getElementById("LDrow"); var MDOutput = document.getElementById("MDrow"); if (radioSelection == "MD") { weightInput.style.display = "none"; CPsInput.style.display = "block"; creInput.style.display = "block"; CHFInput.style.display = "block"; MDOutput.style.display = "block"; LDOutput.style.display = "none"; } else { weightInput.style.display = "block"; CPsInput.style.display = "none"; creInput.style.display = "none"; CHFInput.style.display = "none"; MDOutput.style.display = "none"; LDOutput.style.display = "block"; } } function calculate() { var LD = 1; var MD = 1; var VD = 7.3; var CPd = 1.5; var Cl = 1; var S = 1; var T = 1; var weight = document.getElementById("weight").value - 0; var CHD = document.getElementById("CHD").value; var creatinine = document.getElementById("creatinine").value - 0; var CPs = document.getElementById("CPs").value -0; if (CHD == "Y") { Cl = 23 + (0.88 * creatinine); LD = (VD * weight * CPd) / (S * F); MD = (CPs * Cl * T) / (F * S); } else { Cl = 57 + (1.02 * creatinine); LD = (VD * weight * CPd) / (S * F); MD = (CPs * Cl * T) / (F * S); } var LD = Math.floor(LD / 125) * 125 var MD = Math.floor(MD / 62.5) * 62.5 document.getElementById('LD').innerHTML = LD + " micrograms - NOTE: if loading dose is above 500micrograms, give in divided doses of no more than 500micrograms at one time"; document.getElementById('MD').innerHTML = MD + " micrograms"; document.getElementById('F').innerHTML = F; document.getElementById('S').innerHTML = S; } </script> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <strong>Please select the route to be used for administering digoxin:</strong><br /> <input type="radio" name="route" value="PO" checked onclick="toggle(this);">Oral<br /> <input type="radio" name="route" value="IV" onclick="toggle(this);">Intravenous<br /> <br /> <br /> <strong>Now select whether you wish to calculate a Loading or Maintenance dose:</strong><br /> <input type="radio" name="dosage" value="LD" checked onclick="toggle(this);">Loading Dose<br /> <input type="radio" name="dosage" value="MD" onclick="toggle(this);">Maintenance Dose<br /> <br /> <br /> <table> <tr id="CPsRow" style="display:none"> <td class="style19">Patient's Digoxin Level</td><td class="style17"><input id='CPs' value=""/> micrograms/L </td><td> <ul> <li>Ensure that the level has been taken at least 6 hours post dose. Time to steady state is 10-14 days after initiation/dose change (if renal function is normal).</li> </ul> </td> </tr> <tr id="weightRow" style="display:block"> <td class="style19">Weight</td><td class="style17"><input id='weight' value=""/> kg</td> </tr> <tr id="creRow" style="display:none"> <td class="style19">Creatinine</td><td class="style17"><input id='creatinine'/> mmol/L</td> </tr> <tr id ="CHFrow" style="display:none"> <td class="style19">Chronic Heart Failure </td><td class="style18"><select id='CHD'> <option value="N">No</option><option value="Y">Yes</option></select></td> </tr> </table><br /> <input type="button" onclick="calculate()" value="Calculate!"/><input id="Reset" type="reset" value="Reset" /> <br /> <br /> <br /> <br /> <table> <tr id="LDrow" style="display:block"><td><strong>Loading dose: </strong> </td><td id='LD' /></td></tr> <tr id="MDrow" style="display:none"><td><strong>Maintenance dose: </strong> </td><td id='MD' /></td></tr> <tr><td><strong>Bioavailability factor used: </strong></td><td id='F' /></td></tr> <tr><td><strong>Salt factor used: </strong> </td><td id='S' /></td></tr> </table> Hi I'm pretty new to javascript.. infact very new, only 4 days old , and I'm like this --> Anyway, I want to add a link in this menu . I want the link to be where the text " Go to the front page, Want to know more about us?, Keep in touch with us, call any time you want " How do I do that? cheers! here's the page : http://www.mts-photo.com/fotter_nav.html Code: <!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=iso-8859-1" /> <title>Jquery Tutorial : Horizontal animated menu</title> <link type="text/css" href="css/menu.css" rel="stylesheet" media="screen" /> <script type="text/javascript" src="inc/jquery.js"></script> <script type="text/javascript" src="inc/menu.js"></script> </head> <body> <div id="wrapper"> <ul id="menu"> <li><a href="test.html" title="Go to the front page", >Home</a> </li> <li><a href="#" title="Want to know more about us?">About Us</a></li> <li><a href="#" title="Keep in touch with us, call any time you want">Contact Us</a></li> <li><a href="#" title="Ny link">Nylink 1</a></li> </ul> </div> </body> </html> Hi all, I have this idea - and there might be something already out there that can do it for me - but I don't even really know how to phrase what I'm looking for. Basically, I want the user to be able to enter a word in a text box. When the form is submitted, that word is included in the text in the resulting page in several places. Maybe this example will work well: The text on the website might be this: Quote: Yesterday for lunch I ate a delicious _________. It was the first time in a while I had eaten a _________ and it was even better than I expected it would be. In fact, it was so good that I immediately ran to the store and purchased a whole box of ________s. A user would come to the site and be prompted for a type of food. If they entered banana in the text box and submitted the form, the resulting page would then read: Quote: Yesterday for lunch I ate a delicious banana. It was the first time in a while I had eaten a banana and it was even better than I expected it would be. In fact, it was so good that I immediately ran to the store and purchased a whole box of bananas. Is this even possible? And if so, how difficult would it be to do? Thanks a bunch for the help! Hi all, I am having some problems with the below multiple image upload script. Code: <script type="text/javascript"> set_cookie ( "uid", "14" ); </script> <script type="text/javascript"> $(function(){ $('#swfupload-control').swfupload({ upload_url: "upload-file.php", file_post_name: 'uploadfile', file_size_limit : "10240", file_types : "*.jpg;*.png;*.gif", file_types_description : "Image files", file_upload_limit : 100, flash_url : "jquery/swfupload/swfupload.swf", button_image_url : 'jquery/swfupload/wdp_buttons_upload_114x29.png', button_width : 114, button_height : 29, button_placeholder : $('#button')[0], debug: false }) .bind('fileQueued', function(event, file){ var listitem='<li id="'+file.id+'" >'+ 'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+ '<div class="progressbar" ><div class="progress" ></div></div>'+ '<p class="status" >Pending</p>'+ '<span class="cancel" > </span>'+ '</li>'; $('#log').append(listitem); $('li#'+file.id+' .cancel').bind('click', function(){ var swfu = $.swfupload.getInstance('#swfupload-control'); swfu.cancelUpload(file.id); $('li#'+file.id).slideUp('fast'); }); // start the upload since it's queued $(this).swfupload('startUpload'); }) .bind('fileQueueError', function(event, file, errorCode, message){ alert('Size of the file '+file.name+' is greater than limit'); }) .bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){ $('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued); }) .bind('uploadStart', function(event, file){ $('#log li#'+file.id).find('p.status').text('Uploading...'); $('#log li#'+file.id).find('span.progressvalue').text('0%'); $('#log li#'+file.id).find('span.cancel').hide(); }) .bind('uploadProgress', function(event, file, bytesLoaded){ //Show Progress var percentage=Math.round((bytesLoaded/file.size)*100); $('#log li#'+file.id).find('div.progress').css('width', percentage+'%'); $('#log li#'+file.id).find('span.progressvalue').text(percentage+'%'); }) .bind('uploadSuccess', function(event, file, serverData){ var item=$('#log li#'+file.id); item.find('div.progress').css('width', '100%'); item.find('span.progressvalue').text('100%'); var pathtofile='<img src="uploads/'+file.name+'" height="120px" width="120px"></img>'; item.addClass('success').find('p.status').html(pathtofile); }) .bind('uploadComplete', function(event, file){ // upload has completed, try the next one in the queue $(this).swfupload('startUpload'); }) }); </script> Process Page (upload-file.php) Code: <script type="text/javascript"> function get_cookie ( uid ) { var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' ); if ( results ) return ( unescape ( results[2] ) ); else return null; } </script> <?php include('includes/config.php'); $uploaddir = 'uploads/'; $file = $uploaddir . basename($_FILES['uploadfile']['name']); $size=$_FILES['uploadfile']['size']; if($size>10485760) { echo "error file size > 10 MB"; unlink($_FILES['uploadfile']['tmp_name']); exit; } if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { $uploadedfiles = ($_FILES); $files = $uploadedfiles; foreach($files as $value) $a_id = $_COOKIE['a_id']; $u_id = '<script type="text/javascript">var x = get_cookie ( "uid" );</script>'; { $insert = "INSERT INTO images (a_id, u_id) VALUES ('$a_id', '$u_id')"; mysql_query($insert) or die(mysql_error()); } echo "success"; } else { echo "error ".$_FILES['uploadfile']['error']." --- ".$_FILES['uploadfile']['tmp_name']." %%% ".$file."($size)"; } ?> Basically the problem I am having that when the row is entered into the database, it always inputs a 0 for a_id and u_id, I have tried this with php cookies, php sessions and now I am trying with javascript cookies. Why wont the included file read the cookies? Is their anyway to pass data into this script? I believe that Code: upload_url: "upload-file.php", is the issue, I cant seem to parse any data into this file? Any help would be greatly appreciated, this is driving me nuts! I few sites said to (in the js file) put the varible in <%= %> these tags but thats not doing any good. Is there some other part needed to this I'm missing. The javascript I'm using is in a file I included in my VS project.
I have this which runs on keyup in a textbox but i dont want it to run if the pressed key is enter, how would i go about that? Code: function getList() { var xmlhttp; 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) { showDiv('#', 'result'); document.getElementById("result").innerHTML=xmlhttp.responseText; } } var user = document.getElementById('friendsSearch').value; xmlhttp.open("GET","../friendSearch.php?username="+user,true); xmlhttp.send(); } Good day! I created a login page and I have the username which is a textbox type, department and i use option and a submit button.. I want that when i open my webpage automaticallt the cursor was on the textbox and when i am done in typing my username and i press the enter key the focus would be on the option which where i can choose my department and when i am done choosing my department and i press the enter key i automatic login and go to the department page. Here is the code: PHP Code: <?php session_start(); //require_once 'conn.php'; $db_name="dspi"; mysql_connect("localhost", "root", "") or die("Cannot connect to server"); mysql_select_db("$db_name")or die("Cannot select DB"); $department = mysql_real_escape_string($_POST['department']); $username = mysql_real_escape_string($_POST['username']); $sql=mysql_query("SELECT `Department`, `Username` FROM `tbllogin` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mysql_error()); $ct = mysql_num_rows($sql); if($ct == 1) { $row = mysql_fetch_assoc($sql); if($row['Department']=='Accounting') { header('location: Company.php'); } elseif($row['Department']=='Engineering') { header('location: Company.php'); } elseif($row['Department']=='Finishing_Goods') { header('location: Company.php'); } elseif($row['Department']=='HRAD') { header('location: Company.php'); } elseif($row['Department']=='MIS') { header('location:Company.php'); } elseif($row['Department']=='Packaging_and_Design') { header('location:Company.php'); } elseif($row['Department']=='Production') { header('location:Company.php'); } elseif($row['Department']=='Purchasing_Logistic') { header('location:Company.php'); } elseif($row['Department']=='QA_and_Technical') { header('location:Company.php'); } elseif($row['Department']=='Supply_Chain') { header('location:Company.php'); } else { header('location:dspi_login.php'); echo"Incorrect Username or Department"; } } ?> <!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=iso-8859-1" /> <title>Login</title> <script> function searchKeyPress(e) { // look for window.event in case event isn't passed in if (window.event) { e = window.event; } if (e.keyCode == 13) { document.getElementById('submit').focus(); } } </script> <style type="text/css"> <!-- BODY { background-image: url(layout_image/bgroundv09.png); background-attachment: fixed; } #Dept_Frame { position:absolute; width:229px; height:49px; z-index:1; left: 441px; top: 262px; } #Department_Option { position:absolute; width:186px; height:32px; z-index:2; left: 455px; top: 275px; } #Submit_Frame { position:absolute; width:82px; height:35px; z-index:3; left: 516px; top: 320px; } #Submit_Button { position:absolute; width:60px; height:29px; z-index:4; left: 525px; top: 328px; } #Username_ImageText { position:absolute; width:130px; height:55px; z-index:5; left: 319px; top: 208px; } #User_Frame { position:absolute; width:230px; height:46px; z-index:6; left: 441px; top: 216px; } #Username_Textbox { position:absolute; width:182px; height:23px; z-index:7; left: 457px; top: 228px; } --> </style> </head> <body> <form id="form1" name="form1" method="post" action=""> <div id="Department_Option"> <select name="department" onkeypress="searchKeyPress(event);"> <option>Choose your Department. . . . . . </option> <option value="Accounting" <?php if($_POST['department'] == 'Accounting') echo "selected='selected'"; ?>>Accounting</option> <option value="Engineering" <?php if($_POST['department'] == 'Engineering') echo "selected='selected'"; ?>>Engineering</option> <option value="Finishing_Goods" <?php if($_POST['department'] == 'Finishing_Goods') echo "selected='selected'"; ?>>Finishing Goods</option> <option value="HRAD" <?php if($_POST['department'] == 'HRAD') echo "selected='selected'"; ?>>HRAD</option> <option value="MIS" <?php if($_POST['department'] == 'MIS') echo "selected='selected'"; ?>>MIS</option> <option value="Packaging_and_Design" <?php if($_POST['department'] == 'Packaging_and_Design') echo "selected='selected'"; ?>>Packaging and Design</option> <option value="Production" <?php if($_POST['department'] == 'Production') echo "selected='selected'"; ?>>Production</option> <option value="Purchasing_Logistic" <?php if($_POST['department'] == 'Purchasing_Logistic') echo "selected='selected'"; ?>>Purchasing and Logistics</option> <option value="QA_and_Technical" <?php if($_POST['department'] == 'QA_and_Technical') echo "selected='selected'"; ?>>QA and Technical</option> <option value="Supply_Chain" <?php if($_POST['department'] == 'Supply_Chain') echo "selected='selected'"; ?>>Supply Chain</option> </select> </div> <div id="Submit_Button"> <input type="Submit" name="submit" value="Submit" id="submit" onclick="doSomething();"/> </div> <div id="Dept_Frame"><img src="layout_image/subframev02.png" width="229" height="50" /></div> <div id="Submit_Frame"><img src="layout_image/subframev02.png" width="80" height="46" /></div> <div id="Username_ImageText"><img src="layout_image/userv01.png" width="131" height="62" /></div> <div id="User_Frame"><img src="layout_image/subframev02.png" width="229" height="50" /></div> <div id="Username_Textbox"> <input name="username" type="text" size="30" /> </div> </form> </body> </html> I hope that somebody help me to solve my problem Hello everyone, I got this cool javascript for an all-in-one search engine at javascriptkit.com: http://www.javascriptkit.com/script/cut130.shtml I can already execute the script by clicking on the submit button, but I also want to execute the script by pressing the enter key within the text area. Can anyone please guide me through accomplishing this goal? Thanks, RK2 ============================== The code is as follows: Code: <script language="JavaScript"> <!-- // // Script by Jari Aarniala [www.mbnet.fi/~foo -- foo@mbnet.fi] // // This script makes it easy to choose with which search engine // you`d like to search the net. You may use this if you keep this // text here... // function startSearch(){ searchString = document.searchForm.searchText.value; if(searchString != ""){ searchEngine = document.searchForm.whichEngine.selectedIndex + 1; finalSearchString = ""; if(searchEngine == 1){ finalSearchString = "http://www.altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=.&q=" + searchString; } if(searchEngine == 2){ finalSearchString = "http://av.yahoo.com/bin/query?p=" + searchString + "&hc=0&hs=0"; } if(searchEngine == 3){ finalSearchString = "http://www.excite.com/search.gw?trace=a&search=" + searchString; } if(searchEngine == 4){ finalSearchString = "http://www.hotbot.com/?SW=web&SM=MC&MT=" + searchString + "&DC=10&DE=2&RG=NA&_v=2&act.search.x=89&act.search.y=7"; } if(searchEngine == 5){ finalSearchString = "http://www.infoseek.com/Titles?qt=" + searchString + "&col=WW&sv=IS&lk=noframes&nh=10"; } if(searchEngine == 6){ finalSearchString = "http://www.lycos.com/cgi-bin/pursuit?adv=%26adv%3B&cat=lycos&matchmode=and&query=" + searchString + "&x=45&y=11"; } if(searchEngine == 7){ finalSearchString = "http://netfind.aol.com/search.gw?search=" + searchString + "&c=web&lk=excite_netfind_us&src=1"; } location.href = finalSearchString; } } // --> </script> <basefont face="Verdana, Arial, sans-serif"> <form name="searchForm"> <table width=320 border cellpadding=3 cellspacing=2 bgcolor=444444> <tr> <td bgcolor=lightblue><font size=1 face="Verdana, Arial, sans-serif">Search for:<br> <td bgcolor=lightblue><font size=1 face="Verdana, Arial, sans-serif">Search from: <td bgcolor=lightblue> <tr> <td bgcolor=navajowhite><input style="background: dddddd" name="searchText" type="text"> <td bgcolor=navajowhite> <select style="background: dddddd" name="whichEngine"> <option selected>Altavista <option>Yahoo! <option>Excite <option>Hotbot <option>Infoseek <option>Lycos <option>AOL Netfind </select> <td bgcolor=navajowhite><input type="button" value="Send" onClick="startSearch()"> </select> </table> </form> <font size=1>Script by <a href="http://www.mbnet.fi/~foo/">Jari Aarniala</a>, <a href="mailto:foo@mbnet.fi">foo@mbnet.fi</a> Hi, Just wondering if you guys can help me to make the following script to work when the enter/return key is pressed, intead of having to click on the button? Code: <Script language=JavaScript> function read_model (form) { ModelVar =form.model_input.value; window.location= ("http://www.sony.co.uk/product/dsc-t-series/" + ModelVar + "/tab/technicalSpecs"); } </script> <form name=model_form action="" method=GET> Enter Sony Model Number (e.g. dsc-tx5): <input type=text name=model_input value="" size=9> <input type=button name=model_button value=Click onClick="read_model(this.form)"> </form> <script language=JavaScript> document.model_form.model_input.focus(); </script> I've searched the net for ways of achieving this, but for some reason none of the code i've tried works..! Also, if this make a difference, the page will mainly be used in Firefox. I'd be really greatfull if someone can help me with this, Thanks! |