File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes form name as a value of textbox. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "form name as a value of textbox." Watch "form name as a value of textbox." New topic
Author

form name as a value of textbox.

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 751
I want to set a value of textbox my form name which i can see in URL.

e.g
if my URL is this :
http://localhost:8080/Tools/jsp/ContactDetails.jsp

than he value of text box should be

"ContactDetails.jsp"

How do i achieve that... anybody any idea ???


Jigar Naik


Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Why are you not setting this value on the server when the page is rendered? Than you would not need JavaScript

If for some strange reason you want to use JavaScript


Eric
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 751
I tried your code :


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script>
window.&o&n&l&o&a&d = function(){
alert("Here");
var url = document.location.href
var dirs = url.split("/");
var page = dirs[dirs.length-1];
[B]Line 12if(indexOf("?")>-1)page = page.split("?")[0];

if(indexOf("#")>-1)page = page.split("#")[0];
document.form1.text2.value = page;
}
</script>
</head>
<body>
<form action="" name="form1">
<input type="text" name="text1"><br>
<input type="text" name="text2"><br>
<input type="text" name="text3"><br>
<input type="submit" name="submit">
</form>
</body>
</html>[/B]

but it is giving error object required at line no 12
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 751
i got it... thanks a lot.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: form name as a value of textbox.
 
Similar Threads
Obtain Get Parameters using HttpServletRequest
Servlet Mapping
Losing session attribute
Retaining drop down values on page submit
how to change the URL