using xampp, open a .php file FROM a .php file - javascript

I'm trying to write a Roman Numeral Converter for php practice that has an input page where the user specifies whether their input is Roman or Numeric, writes the input, and hits submit. This info will then be passed via URL to an output page where the actual conversion happens. Everything for the output is done, but I can't test it because I can't figure out how to open the output php file when the user hits submit. When I change the URL to be opened to a site on the web, it works fine, but even without including the parameters to pass through the URL I just can't get it to open another php file via localhost.
The javascript to go to the output is as follows:
<script type="text/javascript">
function goToOutput(){
var newURL = "http://localhost/Code/RomanNumeral/RNEnd.php";
window.open(newURL);
return false;
}
</script>
I'll obviously have to later add the variables to the URL in order to execute the conversion, but I'm currently using RNEnd.php (which just writes "success") instead of the actual file just to test the javascript, and its not working. If I just type that newURL into my browser, it opens fine.
Any suggestions? I'd be happy to answer any clarification questions if I wasn't clear.
Thanks
whole code as requested for this specific file is here:
<html>
<head>
<link rel="stylesheet" href="RNStyle.css" type="text/css" media="screen"/>
<title>ROMAN NUMERAL CONVERTER - INPUT</title>
<script type="text/javascript">
function goToOutput(){
var newURL = "http://localhost/Code/RomanNumeral/RNEnd.php";
window.open(newURL);
return false;
}
</script>
</head>
<body background="http://upload.wikimedia.org/wikipedia/commons/5/53/Colosseum_in_Rome,_Italy_-_April_2007.jpg">
<div id="RomanNumeralInput">
<h1>ROMAN NUMERAL CONVERTER</h1>
<P>Select your input type and then enter the number.</P>
<form name="convertform" onSubmit="return goToOutput();">
<select name="valuetypes">
<option value="R">ROMAN</option>
<option value="N">NUMERIC</option>
</select>
CONVERT:
<input type="text" name="numcon">
<input type="submit" name="convertSubmit" value="CONVERT">
</form>
</div>
</body>
</html>

If you are using HTML form for SUBMIT, then you should specify the output page url in the onSubmit action.
Else if you are trying to do it through Javascript, I would suggest you use AJAX call to pass the parameters along with URL and get the output of the page and display.

Related

How to pass html form information between iframes on google sites

I am relatively new to html/ javascript, and I am trying to use google sites to build a simple store, that will send orders to a google sheet. At present, I am having difficulty passing data between iframes. In the first iframe, I am testing this snippet of code:
<!DOCTYPE html>
<html>
<input type="text" id="texttest">
<button onclick="store()" type="button">Store</button>
</html>
<script type="text/javascript">
function store() {
var myinput = document.getElementById("texttest");
sessionStorage.setItem("texttest", myinput.value);
</script>
And in the second iframe, this snippet:
<!DOCTYPE html>
<html>
<p id="output"></p>
</html>
<script>
document.getElementByID("output").innerHTML = sessionStorage.getItem("texttest");
</script>
The idea is essentially for a user to scroll through the option, input in certain fields the type and quantity of the item they want, and for those selections to be collected at the end and sent to a google sheet. However, the code below is not displaying the text entered in the "texttest" field in the "output" iframe. Any ideas or suggestions would be welcome!

download jsp project

I have jsp from server-side. When i make ajax call with jquery from client-side there is response with empty spaces which is generated by scriptlet from JSP.
JSP in its turn connects to database and retrieves login if exists and sends response - a single word.
If there is no such row it does not do anything, so the response is almost empty (when I say empty I mean there are empty spaces, tabs and line drops).
So how to remove those absolutely empty spaces in response.
The code is
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js"></script>
<script>
i = 0;
$(document).ready(function(){
$("input").keyup(function(){
$.post("checkLogin.jsp",
{
login: $('input').val(),
},
function(data,status){
$('#error').html(data.length);
});
});
});
</script>
</head>
<body>
Enter your name: <input id='input' type="text">
<p style="background-color: red;" id="error"></p>
</body>
</html>`
Try to use Maven, once run it will install all the required dependencies in your .m2(C:\Users\username) folder.
You can use the following for your reference.
http://www.mkyong.com/maven/how-to-install-maven-in-windows/
http://www.mkyong.com/maven/where-is-maven-local-repository/

Stop posting html tags in form using AngularJS

I have a form, In which I want user couldn't enter html tags or script and submit form in angularjs.
for this I'm using $sanitize but it's not working.
this is my form
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-sanitize.js"></script>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body ng-app="birthdayToDo" ng-controller="main">
<h1>Hello Plunker!</h1>
<form name="testForm" ng-submit="submitForm(testForm.$valid)" novalidate>
<input type="text" name="name" ng-model="testText"/>
<p ng-show="testForm.name.$dirty && testForm.name.$invalid && testForm.submitted" class="error">
Invalid Input
</p>
<input type="submit" value="Save"/>
</form>
</body>
</html>
as soon as he enter invalid input, It shows an error message.
I'm using this concept
$scope.SanitizeDemo=function() {
return $sce.trustAsHtml($scope.testText);
};
My Plunker
I think you are going about this the wrong way. Use a whitelist regular expression in both angularjs as well as your backend to validate the input.
For security, best practice is for each field to have a regular expression which will only allow certain valid input. A simple one for name would be /^[a-z ,.'-]+$/i. This would be on the server side to prevent any data being sent that was not valid. This could also be placed on the client side to also validate.
By default Angularjs encodes output when using {{}} to protect against XSS, so <b>abs</b> will appear as is and this is what you want from a security point of view to prevent third party script from executing on your page.
In some cases you may want to allow output of html and allow it safely but in which case you can use ng-bind-html with ng-sanitize and don't need to use $sce directly.

Javascript function add value in other html page

<head>
<script type="text/javascript">
function productID(id)
{
document.getElementsByTagName('input')[0].value = id;
}
</script>
</head>
<body>
<img src="...images/car.jpg" onclick="productID('1')">
</body>
When the user click on the image:
1) A new page open
2) The javascript function search for the first form field input in the page and write in it the productID
My question is:
How can I let this function write the productID in the first form field input in page.html that the user is already moved to it when he clicked on the image?
not in the same page!
You don't have a reference to the document or window of page.html. If you opened the link with, for example: window.open you would. This means you can't do it with JavaScript.
You can do it with the use of a server side scripting language.

Prefill an email with HTML content

I've been working on a project with a feature so that when I click a button, Outlook will open and the corresponding value stored in a variable will be in the in the body of the mail. I've tried the following code:
<html>
<head>
<title>Email This Code Snippet</title>
<script language="javascript">
function TriggerOutlook()
{
var sub = "Hi friend";
var bodycont = "<html><body>welcome</body></html>";
var body = escape(bodycont + String.fromCharCode(13));
window.location.href = "mailto:sakthivela#yahoo.com"
+ "?body=" + body
+ "&subject=" + sub
;
}
</script>
</head>
<body>
<form id="form1">
Email this Codesnippet
<input type="text" name="txtbody" id="txtbody">
</form>
</body>
</html>
But the body of the mail is <html><body>welcome</body></html> in plain text, not HTML. How do I get it formatted as HTML?
You can't. The mailto specification doesn't have that kind of control over the e-mail client invoked by the browser.
Interestingly, your code works for me as-is when Thunderbird is the default system mailer. Apparently Thunderbird is smart enough to notice that the body starts with <html> and switches to HTML-mail mode.
It would seem at first that to convince Outlook to behave similarly, you might try setting the Content-Type header in the email to "text/html". However, I don't see how this is possible using mailto since you do not have control over the headers.

Categories

Resources