JavaScript - Envoke Pop-up On Submit & Post Data
This one is tricky. I can do this in php, however, I would like to keep everything on the same page. In a nutshell I'd like my users to export some data but after they click the export button I need them to input a key which will then be placed into a variable and the posted.
Here's a simplified version of how script works without the key: Code: <?PHP if(isset($_POST['Export'])){ $file = $_POST['Export']; $hostname = $_SERVER['SERVER_NAME']; $hostname = str_replace('www.', '', $hostname); $file_location = "http://".$hostname."/filelocation/".$file; $list = file_get_contents("$file_location"); # filename for download $filename = "$file.txt"; header("Content-Disposition: attachment; filename=\"$file\""); header("Content-Type: text/plain"); echo $list; } ?> <form action="" method="post"> <input type=hidden value="$file" name="Export"> <input type=submit value="Export"></form> I know this is a javascript category and I have php. However, what I want is javascript. My users cannot access the page (traditionally) because a key needs to first be submitted. This is what I need help with > Find a way to use javascript when the 'Export' button is pressed to open a pop-up window for the user to submit their key. > Place there key into a variable. From there I can use PHP to post the variable, extract the data and allow the user to export. Something like this: Code: if(isset($_POST['Export'])){ //The user pressed the export button - use javascript to envoke pop-up //<!--javascript pop-up code--> //The user submitted their key - place it in a variable //<!--javascript code to post key into variable--> $key = $_GET['key']; $file = $_POST['Export']; $hostname = $_SERVER['SERVER_NAME']; $hostname = str_replace('www.', '', $hostname); $file_location = "http://".$hostname."/filelocation/".$file."php?key=".$key; $list = file_get_contents("$file_location"); # filename for download $filename = "$file.txt"; header("Content-Disposition: attachment; filename=\"$file\""); header("Content-Type: text/plain"); echo $list; } ?> <form action="" method="post"> <input type=hidden value="$file" name="Export"> <input type=submit value="Export"></form> If I can get the user to place a key in a simple input box (through a javascript pop-up after they've clicked the button) then I can post the variable and retrieve the data. Any ideas? Similar TutorialsHi friends, i'm using greybox on my website, and using survey. i want when click submit button then post form data to opened greybox window.. but can't.... my form actions <form action="anket.php?islem=ok" method="post" onSubmit="javascript:return GB_showCenter('Anket',this.action, 280, 350)" > greybox window open, but can't show post data.. can anyone help me ? sorry for may bad english Hi everyone, I have a problem with something I am trying to do. I have a submit button and once I press it I want it to add a post value to my website. For example my website is www.something.net/test.php and once I press it I want it to refresh the site and becomes something like www.something.net/test.php&ca=test In other words I want it to use POST and then using GET I can get the value of the POST. I have posted this under javascript because I believe I have a problem with the javascript I use. Here is the javascript and the button I use Javascript Code: function reload(val) { //var val=form.accept.id; self.location='test.php?ca=' + val ; } Button Code: <form name='form1' method='post' action='' STYLE='margin: 0px; padding: 0px;'> <input type='submit' name='accept' id='trial' value='Approve' onclick=\"reload(test)\" /> </form></div></td>"; Can you please help me with that? I am trying to get a Javascript "script" to do a function for me. I am trying to write a a script that will run while the webpage is open, that is selected a randomized 9 digit number Less than 350000000 that will be put into a textbox and submitted. I want a adjustable time when it submits. Could this be made into an <iframe>? Also, this has to do it to a different website, not the one locally being opened. Thank you for your help. I am trying to follow this article on doing a POST request with AJAX and PHP and it works fine, but as soon as I switch from the default submit button to an image I get an error. I would really appreciate any assistance on why switching the submit button to an image would affect it. Thanks http://www.hiteshagrawal.com/ajax/form-post-in-php-using-ajax/comment-page-1 Hey Guys, A litttle new to web coding so bare with me(hope this is posted in the right section). Im workin on a backend panel where i populate a simple table with a few text boxes in there so they can update some values. I also have at the end of every row in the table an Edit, Delete & Save button. When i hit the save button i would like to update that entry in the database. My Problem is that i need a value from the table before hitting a submit button, and the element names are dynamically created meaning ill likely need a variable sent from php to javascript and once i have the value in javascript ill need to send it back over to the php to manipulate and send to the server. From wat i can gather using 'document.form.element.value' is the best way to go, hence why i posted this in javascript when most of my code is php. PLEASE HELP Hi all, im sure this will be pretty simple, at the moment i have some code which sends text from a textarea to a php file, the php file then stores the data into a database. the javascript post is as follows: Code: var text = document.getElementById(area).value; http.open('post', 'autosave.php?text='+text); there is a little bit more to this(just a handle response). My issue is that when the data is passed through javascript newlines and breaks disappear, so when i call the saved data it is presented as one long string with no formatting. i tried the nl2br() function and htmlspecialchars() function in the php file that the javascript passes the data to, this made no difference. I then tried to replace /n with <br /> in the javascript before passing the text variable again this made no differnce. Does anyone have any ideas how to keep formatting during this process? Hi guys, hoping you can help me out again, with this new problem. I've got a form which is acting as a calculator. Once the calculation is complete I want it so when the user presses a 'print' button it takes certain parts of the form data and displays them in a new window which would be designed for printing. how can i go about this using only javascript? thanks I want to use Javascript to submit a form - without filling the form in physically Is this possible? Let's say a web page has a form that submit First Name and Last Name to the next page Instead of filling in the form and hitting submit, can I submit the data in variables and call the next page somehow using Javascript? Thanks OM Hello all, I need my form to submit to two sources, zoho crm and broker office. One is used to create a contact list and the other is an insurance quote engine. Problem one. How can I use javascript to force my form to submit data to both sites? The bigger problem is they use different names for the same field. In other words one wants to recieve a vaule as first_name and the other wants it as firstName. Thanks in advance. Hi, I have a problem with sending data from a form to a php script with AJAX. To test if it works, I try to send data from the form, print it in the php with "echo", and then put it back in the initial html file. My Javascript code is: Code: function registerPrivateUser() { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support AJAX!"); return; } var postData="firstName="+ document.getElementById("txtFirstName").value; var url="classes/users/checkRegistration.php"; xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("POST",url,true); //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); xmlhttp.send(postData); } The function stateChanged, basically says: Code: if (xmlhttp.readyState==4) { var strResponse; strResponse=xmlhttp.responseText; alert('Response:' + xmlhttp.responseText); } checkRegistration.php looks like this: PHP Code: <? session_start(); $firstName=$_POST['firstName']; echo($firstName); ?> The problem is that the response is empty, but I don't know why. I have checked the input data and the postData variable says "firstName="+input (e.g. "firstName=Robert"), so that's not the error. I have read several forum posts here, but still haven't figured out what I'm doing wrong. If anyone could please tell me, I would appreciate it alot. Hello Everybody, I have a scenario where in i have 2 divisions, TOP and BOTTOM. In the BOTTOM Division i have a list box and Submit button in a form. User can select an item from the list box and click on the submit button. After user clicks the submit button i want to display some data/graph in the bottom division. However with my current code i see that on clicking the submit button , the data is displayed on a fresh page. Please guide me if this is possible or should i use a different logic. The code goes here. Code: <html> <head> <TITLE> Display Graph </TITLE> <script type="text/javascript"> function processData(form) { var BoardNumber = document.forms[0].elements[0].value; var BoardIndex = document.forms[0].elements[0].selectedIndex; alert("Selected board is :" + BoardNumber + ":Selected Index is :" + BoardIndex); document.write("Trying to print some data : "); document.write("<br>"); document.write("The board number is " + BoardNumber); } </script> <style type="text/css"> body { background-color : #fefefe; font-family:arial , verdana, sans-serif; text-align : center; } .page { margin-bottom : 10px ; text-align : left; font-size: 12px; background-color : 00ff00; background-repeat:repeat-y; border:1px solid #666666; height : auto; } .Down { margin-top : 10px ; text-align : left; font-size: 12px; background-color : ff0000; background-repeat:repeat-y; border:1px solid #666666; height : auto; } .header{ padding : 3px; background-color:#f3f3f3; } .content {padding : 10px; margin-left : 100px; } </style> </haed> <body> <div class = "page"> <div class = "header"><h1> My Company Name </h1> </div> <div class = "content"> <!-- The main Page Goes here --> <h2> Top DIVISION </h2> <p> This is test page. This is test page. This is test page. This is test page. This is test page. This is test page. This is test page. This is test page. This is test page. This is test page. This is test page. This is test page. This is test page. This is test page. </p> </div> </div> <div class = "Down" name="Down"> <h2> BOTTOM DIVISION </h2> <p> Down : I NEED TO DISPLAY DATA/GRAPH in the same division. Not in a fresh page???? <BR> <B> SELECT THE BOARD NUMBER and PRESS THE BUTTON "Process Request" </B> <form name = "SelectColor"> <select name = "boardnum"> <option selected = "selected " value = " " > select board </option> <option value = "Board_7125">7125</option> <option value = "Board_7325">7325</option> <option value = "Board_7335">7335</option> <option value = "Board_7340">7340</option> <option value = "Board_7342">7342</option> <option value = "Board_7400">7400</option> <option value = "Board_7401">7401</option> <option value = "Board_7405">7405</option> <option value = "Board_7420">7420</option> <option value = "Board_7550">7550</option> </select> <input type="button" name="process" id="process" value="Process Request..." onclick="processData(this.form)" /></p> </form> </p> </div> </body> </html> Hi. Please help. I have a credit card donation page and what I wanted to do is after they click the submit button and transaction is successfult I wanted to capture the donation amount they enter from the donation page and show it to the next page. I know that is possible but I just don't know how to do it. I am new in Javascript and still consider as a baby. Can someone please help? Thanks in advance.
Hi, I have a form that when you click submit gives a warning box asking if to continue code below Now when I type in the text field and press enter it doesn't submit nor does it pop up the warning box, how would I do this Code for submit button Code: <script LANGUAGE="JavaScript"> <!-- function submitMyForm() { var agree=confirm("ARE YOU SURE ?"); if (agree) return true ; else return false ; } // --> </script> Code: <form action="admin-delete.php" method="post" name="cp_delete" id="cp_delete"> <input type="text" name="cp_delete_bg" id="cp_delete_bg"> <input type="submit" name="submit" value="submit" onclick="return submitMyForm()"/> </form> I've got the following 2 fields in my form: <input type="file" name="filename" id="filename" value="filename"> <input type="submit" name="submit" value="Upload Image" /> Now I want to hide both of them as soon as the submit button is pressed. Problem is that I'm a javascript noob and I can't find it with google :S Can someone help me? Hi all Is using the real form submit button a problem in any way? Can it actaully send a form when a person uses 'enter' in a text field. When I use this submit, it triggers my validation which is great. Code: <input type="submit" value="OnSubmit validate" /> However this way doesn't seem to trigger my validation although It may solve the above form send problem (if that realy exists). How do I get it to act the same as real submit so it will trigger validation like onsubmit above? Code: <input type="button" value="Send Feedback" onclick="this.form.submit()" /> LT does any of that make sense? all ideas helpful and appreciated I have created some online software which uses form data to submit to another page. The problem is that I have other submit buttons in the same form which submit to different pages (depending on which button is pressed). The first submit button works fine but all the others only work once. Code: <input class="cssbutton" type='submit' value='Button1' onclick="wbform.action='page1.php'; target='mainFrame'; return true;"> <input class="cssbutton" type='submit' value='Button2' onclick="wbform.action='page2.php'; target='_blank'; return true;"> <input class="cssbutton" type='submit' value='Button3' onclick="wbform.action='page3.php'; target='topFrame'; return true;"> <input class="cssbutton" type='submit' value='Button4' onclick="wbform.action='page4.php'; target='topFrame'; return true;"> <input class="cssbutton" type='submit' value='Button5' onclick="wbform.action='page5.php'; target='_blank'; return true;"> <input class="cssbutton" type='submit' value='Button6' onclick="wbform.action='page6.php'; target='_blank'; return true;"> Any ideas my friends? I am trying to auto submit a login form remotely using .submit() . It's submitting, but for some reason if I use submit() the login isn't processing. However, if I turn off the auto submit and use an actual submit button it logs in just fine. Now, in the form tag there is a call onsubmit for some validation, does .submit() trigger that form onsubmit="" function? Is there something that happens differently when a user clicks a button verses the .submit(). Thanks! Paul Hi all, I'm designing something to addon to an existing product. I'm struggling with some javascript problems. I want to submit a hidden field when you click on an image button, rather than it being an actual submit button. It's going to submit the value "1" to a PHP page, but I don't want it to actually have to GO to the PHP page, just submit it within the webpage. Is this possible? Thanks Hello all. I'm working on a project for school and for the life of me I cannot get this to display properly. I'm trying to write a page where a user inputs their billing/shipping info and can click on a box to have it copied over to the opposite form. I've gotten code from several different places, including my text book, but when I call the external .js file, nothing happens. Code: <script type="text/javascript" src="display.js"> </script> I have a separate .js file that I am also using, with similar code that functions perfectly, except when I just add this code to the file, then none of it loads. The only reason that I have this in a .js file is that my XHTML needs to validate in strict. Code: function FillBilling(f) { if(f.billingtoo.checked == true) { f.billingCame.value = f.shippingName.value; f.billingAddress.value = f.shippingAddress.value; f.billingCity.value = f.shippingCity.value; f.billingState.value = f.shippingState.value; f.billingZip = f.shippingZip.value; /* If more fields are used, just expand the parameters above to include the additional fields. */ } } document.write("<form action='FormProcessor.html' name='display' method='get' enctype='application/x-www-form-urlencoded' onsubmit='return confirmSubmit()'>>"); document.write("Shipping Information"); document.write("Name:"); document.write("<input type='text' name='shippingName' size='50'>"); document.write("<br>"); document.write("Address:"); document.write("<input type='text' name='shippingAddress' size='50'>"); document.write("<br>"); document.write("City:"); document.write("<input type='text' name='shippingCity' size='25'>"); document.write("<br>"); document.write("State:"); document.write("<input type='text' name='shippingState' size='2' maxlength='2'>"); document.write("Zip Code:"); document.write("<input type='text' name='shippingZip' size='10'>"); document.write("<input type='checkbox' name='billingtoo'"); onclick='FillBilling(this.form)'> document.write("<br>"); document.write("<br>"); document.write("<em>Copy to billing fields.</em>"); document.write("<br>"); document.write("Billing Information"); document.write("<br>"); document.write("Name:"); document.write("<input type='text' name='billingName' size='50'>"); document.write("<br>"); document.write("Address:"); document.write("<input type='text' name='billingAddress' size='50'>"); document.write("<br>"); document.write("City:"); document.write("<input type='text' name='billingCity' size='25'>"); document.write("<br>"); document.write("State:"); document.write("<input type='text' name='billingState' size='2' maxlength='2'>"): document.write("Zip Code:"); document.write("<input type='text' name='billingZip' size='10'>"); document.write("<input type='submit'>"); document.write("<input type='reset'>"); document.write("</form>"); please help me. For the record, im a noob at javascript & if there was a lvl below noob id use it to Anyways, my code blow is supposed to automate on a website i use a quantity & submit with just one click using javascript. The help i got wasn't successful as it dosnt act as a URL or interact with the webpage & i need it to be used as a URL. My Goal is to make a simple php page which i already have & a list of links. Now the links will be made up of javascript as soon as i get a working example i can edit. When i click the links, on the webpage it automatically sets quantity & hits the Sell submit button for me, however it dosnt work & im desperate to get it fixed. On the webpage is a slider that sets the quantity, i can manually set quantity as we have to use a slider we click & drag left or right then we click Sell & it sells the type of drugs which is part of the game we wanted. I grabbed the POST info using Live Headers firefox plugin. I hope someone can fix this for me. Live Headers info: Code: POST /fiends.php drugtype=lsd&sqty=5201 Javascript Code: Code: 1."href="javascript: 2.var doc = document; 3.var aForm = doc.createElement("form"); 4.doc.getElementsByTagName("body")[0].appendChild(aForm); 5.aForm.setAttribute("action", "http://www.greedinc.com/fiends.php?drugtype=lsd&sqty=5201"); 6.aForm.setAttribute("method", "POST"); 7. 8.var aInput = doc.createElement("input"); 9.aForm.appendChild(aInput); 10.aInput.setAttribute("type", "hidden"); 11.aInput.setAttribute("name", "drugtype"); 12.aInput.value = "lsd"; 13. 14.aInput2 = doc.createElement("input"); 15.aForm.appendChild(aInput2); 16.aInput2.setAttribute("type", "hidden"); 17.aInput2.setAttribute("name", "sqty"); 18.aInput2.value = '5201'; 19.aForm.submit();"> As a reminder, The javascript i need will act as a URL on my own hosted php page. I will then open the PHP page as a sidebar in my browser which will be firefox. Then when im on the website in question on the specific page, in staid of click & dragging the slider thats part of the POST/Submit that changes the Quantity of what i want sell & then click Sell. I want the javascript acting as a URL to do that for me from the sidebar page. Really hope someone can fix this for me because I've been at it for nearly 3 weeks now & its starting to wear me down to a point where I'm eating Jelly Babies |