I have this script and form that I alteret so that I can pass a variable. The original was called by onSubmit='return validateForm()'. After altering the script, only onClick will work. If using onSubmit, it just submits thr form no matter checked og not.
Can anybody tell me why the difference in behavior?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function validateForm(a) {
var radios = document.getElementsByName('tjek' + [a]);
var radiosChecked = false;
var i = 0;
while (!radiosChecked && i < radios.length) {
if (radios[i].checked) radiosChecked = true;
i++;
}
if (!radiosChecked) {
alert("Du skal vælge en mulighed!")
return false;
}
}
</script>
</head>
<body>
<form name="Form" action="http://google.com" method="get">
<input name="tjek1" type="radio" value="" />
<input name="tjek1" type="radio" value="" />
<input type="submit" value="Send" onClick="return validateForm(1)" />
</form>
<form name="Form" action="http://bing.com" method="get">
<input name="tjek2" type="radio" value="" />
<input name="tjek2" type="radio" value="" />
<input type="submit" value="Send" onClick="return validateForm(2)" />
</form>
</body>
</html>
I see no difference in behavior: live demo.
The used code, in which I essentially only changed the onclick to onsubmit, and only in the first form:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function validateForm(a) {
var radios = document.getElementsByName('tjek' + [a]);
var radiosChecked = false;
var i = 0;
while (!radiosChecked && i < radios.length) {
if (radios[i].checked) radiosChecked = true;
i++;
}
if (!radiosChecked) {
alert("Du skal vælge en mulighed!")
return false;
}
}
</script>
</head>
<body>
<form name="Form" onsubmit="return validateForm(1)" action="http://google.com" method="get">
<input name="tjek1" type="radio" value="" />
<input name="tjek1" type="radio" value="" />
<input type="submit" value="Send" />
</form>
<form name="Form" action="http://bing.com" method="get">
<input name="tjek2" type="radio" value="" />
<input name="tjek2" type="radio" value="" />
<input type="submit" value="Send" onClick="return validateForm(2)" />
</form>
</body>
</html>
Related
I tried to build a form in home.jsp
<form method="POST" action="uploadfile" th:action="#{/uploadfile}" enctype="multipart/form-data">
<input type="file" name="file" accept=".xls"/> <br/><br/>
<label for="fname">order address:</label>
<input type="text" id="address" name="address" size="50">
<label for="lname">order account:</label>
<input type="text" id="account" name="account" size="50"><br/><br/>
<label for="lname">:</label>
<button type="submit">summit/button>
</form>
result.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/style.css" rel="stylesheet">
<meta charset="UTF-8">
<title>result</title>
</head>
<body>
<div th:if="${message}">
<h2 th:text="${message}"/></div>
<form action="/download" method="post">
<text name="filename" type="text" value="${downloadfile}"/><br/>
<input type="submit" value="download XML" />
</form>
</body>
</html>
here is my controller
#PostMapping("/uploadfile")
public ModelAndView uploadFile(#RequestParam("file") MultipartFile file,
#RequestParam(name="address", required = false) String myaddress,
#RequestParam(name="account", required = false) String myaccount
)
{
....................
..................
ModelAndView model = new ModelAndView("result"); //tried to return this parameters
model.addObject("excecontentslist",tempExcelcontentList); //tried to show the contents of Excel
model.addObject("message",consequencemsg);//tried to show the message we have
model.addObject("downloadfile",xmlfilename); //tried to show the xml which is gonna download
return model;//got 404 error when all things has been done
}
all I trying to do was to send datas which is model to result.jsp to show the data out there,but it doesn't work,just showed the 404 error ,any idea?
I get this error when ever I try to load this web page:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet" type="text/css" th:href="#{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}"/>
<link rel="stylesheet" type="text/css" th:href="#{/css/main.css}"/>
<title>Competition</title>
</head>
<body>
<div>
<p th:text="'Name: ' + ${competition.name}" />
<p th:text="'Date: ' + ${competition.date}" />
<p th:text="'Venue: ' + ${competition.Venue}" />
<div th:if="${competition.competitors != null}">
<h3>Competitors</h3>
<ul>
<li th:each="item : ${competition.competitors}" th:text="${item}"></li>
</ul>
</div>
<h4>Add Competitor.</h4>
<form action="#" th:action="#{/competitions/{id}(id=${competition.id})}" th:object="${email}" method="post">
<p>User email: <input type="text" th:field="*{text}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
</div>
<p th:text="${competition.id}"></p>
</body>
</html>
I added the org.unbescape dependency to my pom.xml.
I started getting this error when I added the the URL to the form
(This line:)
th:action="#{/competitions/{id}(id=${competition.id})}"
It looks like you are using a older version of org.unbescape. The class UriEscape was introduced in versin 1.1.0. Ref here
Can you try by upgrading the org.unbescape version to 1.1.1 as follows?
<dependency>
<groupId>org.unbescape</groupId>
<artifactId>unbescape</artifactId>
<version>1.1.1.RELEASE</version>
</dependency>
i have create some custom page for my mikrotik hotspot
but i have problem with it
with default hotspot theme when i checked "HTTP-CHAP" client users login without any error
but with my custom error client users can't login into hotspot and they saw this error "web browser did not send challenge response (try again, enable JavaScript)"
this is my custom HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!--META-->
<link href="css/font-awesome.min.css" type="text/css" rel="stylesheet">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<title>ورود کاربر</title>
</head>
$(if chap-id)
<form name="sendin" action="$(link-login-only)" method="post">
<input type="hidden" name="username" />
<input type="hidden" name="password" />
<input type="hidden" name="dst" value="$(link-orig)" />
<input type="hidden" name="popup" value="true" />
</form>
<script type="text/javascript" src="/md5.js"></script>
<script type="text/javascript">
<!--
function doLogin() {
document.sendin.username.value = document.login.username.value;
document.sendin.password.value = hexMD5('$(chap-id)' + document.login.password.value + '$(chap-challenge)');
document.sendin.submit();
return false;
}
//-->
</script>
$(endif)
<!--STYLESHEETS-->
<!--SCRIPTS-->
<script type="text/javascript" src="/jquery.min.js"></script>
<!--Slider-in icons-->
<body id="login-body">
<form name="login-form" class="login-form" action="" method="post">
<div class="header">
<center><p style="text-align: center;"><img src="images/logo.png" /></p></center><!--END TITLE-->
</div>
<div class="content">
<form name="login" action="$(link-login-only)" method="post"
$(if chap-id) onSubmit="return doLogin()" $(endif)>
<input type="hidden" name="dst" value="$(link-orig)" />
<input type="hidden" name="popup" value="true" />
<input name="username" type="text" required="required" placeholder="نام کاربری خود را وارد نمایید" class="login-input" onfocus="this.value=''" size="30" /><!--END USERNAME-->
<input name="password" type="password" required="required" placeholder="رمز عبور خود را وارد نمایید" class="login-input" onfocus="this.value=''" size="30" /><!--END PASSWORD-->
<button class="login-btn" type="submit">اتصال <i class="fa fa-sign-in fa-lg"></i></button>
<font color="#AC2925"><center>$(if error) $(error) $(endif)</center></font>
</div>
</form>
</body>
<script type="text/javascript">
<!--
document.login.username.focus();
//-->
</script>
</html>
I have a testt.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.thymeleaf.org ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Advanced Test</title>
</head>
<body>
<form action="#" th:action="#{getClasses}" method="GET">
<br />
<br />
<p style="margin-left: 35px">Submit fully classified package names</p>
Class Name: <input type="text" name="class_name" size="90px"></input>
<input type="text" name="classes" size="90px" th:field="${foo}"></input>
<input type="submit" value="Submit" ></input> <br />
</form>
</body>
</html>
And have the following code in the controller method:
model.addAttribute("foo", "foo");
return "testt";
Why "foo" is not populating in the html? If instead of String i add an object and try to get its variable it works fine.
i think if you want use it like this you should use th:value instead of th:field
You need this th:field=__${foo}__,
have a look at the doc here:http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html
I'm experimenting with jQuery Mobile and have run into a problem on my Windows Phone 7 browser.
Whenever I add a button to the page, either <input type='button'> or <button>, the whole page doesn't render in the WP7 IE.
When I view the same page in IE7 (using IETester) I get a Script Error "Object doesn't support this property or method" Line 17 Char 45703, and then the page doesn't render.
Here's the html that's generated for my page:
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" /><link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
<script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>
<title>
iplan
</title></head>
<body>
<div data-role="page" data-theme="b">
<div data-role="header">
<h1>
mobile login</h1>
</div>
<div data-role="content">
ello
<form name="aspnetForm" method="post" action="default.aspx" id="aspnetForm">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTIzNjAxMDE2M2Rk5Yr3L4N9Yyh0TZrUHAh3ZX6rJck=" />
</div>
<label for="ctl00_ContentPlaceHolder1_txtUsername" id="ctl00_ContentPlaceHolder1_lblUsername">Username</label>
<input name="ctl00$ContentPlaceHolder1$txtUsername" type="text" id="ctl00_ContentPlaceHolder1_txtUsername" />
<br />
<label for="ctl00_ContentPlaceHolder1_txtPassword" id="ctl00_ContentPlaceHolder1_Label1">Password</label>
<input name="ctl00$ContentPlaceHolder1$txtPassword" type="password" id="ctl00_ContentPlaceHolder1_txtPassword" />
<br />
<input type="submit" name="ctl00$ContentPlaceHolder1$btnLogin" value="Login" id="ctl00_ContentPlaceHolder1_btnLogin" />
<span id="ctl00_ContentPlaceHolder1_Label2">Boo</span>
</form>
</div>
<div data-role="footer">
© 2011</div>
</div>
</body>
</html>
When I remove that <input type="submit" ... the page renders correctly.
Any ideas?
I had the same problem. Turned out I was using an out of date version of jQuery.
Solved this by using the most recent version.