Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

form name as a value of textbox.

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ???
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got it... thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic