I am new to Spring and JavaScript.
I have created a JSP file
In my first.js ,I have the following method
function firstmethod()
{
window.alert("Enter a New Number");
return true;
}
But the javascript method is not getting executed.I couldn't figure out the reason.Please suggest
The browser console error log is
Console Error log
I would first check to see if the file is showing up in your web browser correctly:
Right-click in browser window, choose "View Page Source (if you're using chrome)," navigate to the tag, find the link to your javascript file and click on it. You should see the contents of it display in your window.
If the code looks right, you might have an error in it. The browser developer tools (right-click browser window, select "Inspect Element") will sometimes display those errors in the "Console" tab.
The code seems fine. Here's a snippet for it:
function firstmethod()
{
alert("Enter a New Number");
return true;
}
<form name="firstform" method="post" action="first" onsubmit="return firstmethod()">
<input type="submit" name="button" value="Click" />
</form>
Related
I have a button which calls a Javascript function when it is pressed, that function is just redirecting to another page, it looks like this:
<input type="submit" value="Submit" id="button1" name="button1" onclick="myFunction()" />
And the function looks like this:
function myFunction() {
window.location.href = "page2.html";
}
The function is executed but the redirection does not work, it remains on the same page, but if I set a breakpoint on the function and execute it line by line using the Browser dev tools it successfully redirects to the other page.
---------EDIT---------
It works only using the Firefox dev tools, if I set the breakpoint on Chrome it still does not works.
Try setting the href to just
location.href = "page2.html".
As IE and Firefox are concerned, "/path" is invalid.
"Sorry, cannot leave comment yet"
It's the nature of your input type. Change the type to "button" and you'll be good to go!
I am a learner on HTML, PHP, Javascript.
I am currently working on a barcode scanning system. The steps are simple, scan in an order number, the system(form) will then generate another sequence number and print it out along with the scanned order number right away so that the warehouse worker can stick the print out on the scanned parcel.
Same steps keep on until the whole log of cargo done.
We have created a simplified program, and test it. If it works then we can follow the same logic to create the actual form.
Up to this point, we have successfully scan in the bar code, the form then jump into another form by using windows.open. Inside this pop up windows, it is a PDF document which's created by FPDF. By enable FIREFOX silence print feature. The pop up form can printout the label automatically. Everything good except we cannot close the popup windows. We have already drilled out every possibilities and search thru the net...couldn't find anything.
We did turn on the Firefox option dom.allow_scripts_to_close_windows to TRUE
first form
<?PHP
session_start();
if (isset($_POST['submit'])){
$_SESSION['CUSTNO']=$_REQUEST['CUSTNO'];
$_SESSION['ORDERNO']=$_REQUEST['ORDERNO'] ;
//header('Location:TESTwai.php');
echo "myFunction();";
}
?>
<html>
<body>
<form action="" method="post" name="form1"><br>
<input type="text" id="CUSTNO" name="CUSTNO" style="font-size: 24pt"/>
<input type="text" id="ORDERNO" name="ORDERNO" style="font-size: 24pt"/>
<br>
<input name="submit" type="submit" value="SUBMIT" onclick="return myFunction()"></form>
</body>
</html>
<script>
function myFunction() {
//window.open("ex.php","", "width=200, height=100");
window.open("ex.php","", "width=1000, height=1000");
myWindow.close(); // Closes the new window
}
</script>
Second pop up window form
I have put the setTimeout, close.window inside or out PHP script and still no luck.
<?php
require('pdf_js.php');
class PDF_AutoPrint extends PDF_JavaScript
{
function AutoPrint($dialog=false)
{
//Open the print dialog or start printing immediately on the standard printer
//$param=($dialog ? 'true' : 'false');
//echo $param;
//$script="print($param);";
$script="print(false);";
$this->IncludeJS($script);
}
}
$pdf=new PDF_AutoPrint();
$pdf->AddPage();
$pdf->SetFont('Arial','',20);
$pdf->Text(90, 50, 'Print me!');
//Open the print dialog
$pdf->AutoPrint('false');
ob_end_clean();
$pdf->Output();
?>
<script>
setTimeout("window.close()", 100);
</script>
Please ignore those customer, orderno. They are just dummy input...
The actual testing is just
1) press the submit button
2) pop up windows
3) auto print the label out without any system prompt
4) close the pop up windows and get back to the first form (stuck here)
It is not a issue with setTimeout method. This is the issue with window.close() . It is not a good practice to close the window within itself.Still if you its very necessary you can try the below code:
window.open('','_parent',''); //fool the browser that it was opened with a script
window.close();
You can put this in a function and call it use in setTimeout .Helpful link
I want to close a window open by this javascript written in my landing html page .
window.open(location,"_self");
in the location html page I have a button where I tried with
<div onclick="javascript:self.close();">Xyyyy</div>
<div onclick="javascript:window.close();">Xxxx</div>
None of them work.
Note: my condition in I have to open the new window in the same place.
any help is appriciated
I did a search on the subject and this page is what i found.
html (not mine)
<input type="button" name="Quit" id="Quit" value="Quit" onclick="return quitBox('quit');" />
JavaScript (not mine)
function quitBox(cmd)
{
if (cmd=='quit')
{
open(location, '_self').close();
}
return false;
}
There is even a test page.
I did a search for a bunny rabbit too (which isn't mine either).
Updated : Mar-12-2015
I did a search on the subject and this page is what i found.
I did a test with this code and confirmed it is not supported. The comments are good reading.
JavaScript (not mine)
function close_window() {
if (confirm("Close Window?")) {
window.close();
}
}
html (not mine)
close
close
I don't get completely what you are trying to do but here are some tips:
window.open("https://slackoverflow.com");
is used to open an entirely new window(can be used to open local files as well ofc)
window.close();
window.close() Closes the tab.
<a target="_blank" href="http://your_url_here.html">Page yada yada</a>
And this can be used to open a link or page in a new tab. If you play around with these for a little itll start to catch on.
I hope some of these ideas help and will help you put together what you are trying to accomplish :)
I am trying to use buttons in an html/javascript program to redirect someone to another one of my pages. Basically, I created a .jsp page that gives the user some buttons to click. If the user clicks a button, it calls a method that is supposed to open a new .jsp page that I created under the same project. However, I have no clue how to do this as I am brand new to Javascript and HTML. I provided an example below:
Sample Page
<html>
<title>Web Page</title>
<body>
<p>Please click a button to redirect you to the page you wish to go to.</p>
<br>
<form>
<input type="button" id="idname" value = "General Info " onclick="goToInfo()"/><br>
</form>
<br>
<form>
<input type="button" id="idname" value = "Other Information" onclick="goToOther()"/><br>
</form>
<script type="text/javascript">
function goToInfo(){
}
function goToOther(){
}
</script>
</body>
</html>
*For example, I have another page in my NetBeans project that is called "GeneralInfo.jsp" and I want goToInfo() to be able to redirect the person to that page. Thank you for your help.
You could use window.location to redirect the user to the corresponding JSP pages; however, you'll need to make sure your paths in the code below match the actual paths to your JSP page as mapped by your servlet or based on the absolute path relative to the application.
function goToInfo(){
window.location = '/GeneralInfo.jsp';
}
function goToOther(){
window.location = '/someOtherJSPPage.jsp';
}
If you get 404 errors when trying to redirect to your JSP page, try turning up your logging level to ALL or DEBUG so that you can see the logs from the framework or Java container, these will hopefully show you the real file paths so that you can then adjust the URL to match the actual target location.
this should open new tab with GeneralInfo.jsp when you click on the General Info button..
function goToInfo(){
window.location = "GeneralInfo.jsp";
}
you can use this method,
<input type="button" value="General Info" name="INfoPage"
onclick="document.forms[0].action = 'infoPage.jsp';" />
or the easy way is,
General Info
I'm having trouble not being too familiar with how to debug such problems. In my HTML lets say I have a form:
<form name="myForm" >
<table>
<tr>
<td>
<input type="radio" name="myType" value="val" onclick="someFunc(this.value)"checked > stuff here
<input type="radio" name="myType" value="val2" onclick="someFunc(this.value)"> stuff2 here
</td>
..
</form>
In Javascript code, I am referencing this by:
myForm.myType[0].checked
In IE this works fine, but not in Firefox. In Firefox I tried:
alert (myForm)
and also:
if (frmDateType == null)
{
alert('null!');
}
else
{
alert('not null!');
}
However, in both these cases Firefox doesn't even display an alert, it is basically doing nothing though it is fine in IE. I have installed Firebug and it doesn't show any errors (or at least I can't find them). So I'm not sure how to debug such an issue, why I don't see any errors and why Firefox doesn't like MyForm? Any tips?
You are assuming that anything with a name attribute will get a global variable that matches. This is non-standard behaviour.
You shouldn't be giving forms name attributes anyway, see the specification:
Note. This attribute has been included for backwards compatibility. Applications should use the id attribute to identify elements.
So, first replace the name attribute with an id.
<form id="myForm">
And then you can access the form via:
document.getElementById('myForm')
or
document.forms.myForm
I'm not sure as to why your Firefox is not displaying any alert; but you should check the Firefox Error Console. Simply click in your address bar and press the Alt key on your keyboard to highlight the system menu; under Tools -> Web Developer -> Web Console you will be able to see all JavaScript, HTML and CSS errors encountered on the page at load time..
--
Please make sure you are referencing the form currectly in JavaScript:
myForm = document.getElementById("myForm"); // This requires the form to have an id.
Alternatively, you can reference the form using its name (not always works!)
myForm = document.forms.myForm;