Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The right bracket from my input definition displays on my form 3

Status
Not open for further replies.

CdnRebel

Programmer
Apr 5, 2003
39
CA
How do I stop the right bracket from my input definition from displaying on my form? I'm using javascript so I can re-display the value the user has entered. Here is a sample of the code:

<tr>
<td>First Name: </td>
<td><INPUT TYPE=&quot;text&quot; name=&quot;firstname&quot;
<%
out.println(&quot;value='&quot;+fname+&quot;'&quot;);
%> >
</td>
 
why not instead:

<tr>
<td>First Name: </td>
<td><INPUT TYPE=&quot;text&quot; name=&quot;firstname&quot; value=&quot;<% out.println( fname ); %>&quot; />
</td>

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
I tried that and the right bracket disappears, but the javascript ends up showing up in the textbox on the form.
 
>>&quot;the javascript ends up showing up in the textbox on the form&quot;

what javascript? you're using a server side language between <% and %>, right?


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Are you sure (as jemminger suggests) that there isn't some other JavaScript function causing the problem? Have you tried to comment out your &quot;out.println(...)&quot; to make sure that this line is actually causing the problem.

Pete.


Web Developer / Aptrix CMS (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Okay, for the lack of a better word (because it wasn't html code inside my jsp), &quot;<%out.println(fname);%>&quot; ends up displaying inside my textbox and yes, when I comment out the &quot;out.println(...)&quot;, the textbox displays fine.

Mary
 
hi Mary,

the code between your <% and %> tags is server-side Java, not javascript. HUGE difference: the Java code MUST be in a .jsp page or some other page that is going to be processed by a .jsp or servlet container. if you are seeing the raw Java code in your browser, it is not being processed by the webserver. be sure that the page is of the correct type ( .jsp etc ) and that you are running it through a webserver, not just viewing directly from your hard drive.

javascript executes client-side, and will not have access to this &quot;fname&quot; server-side variable.



=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
My code is in a .jsp page. The calling program is .html and takes the code through a webserver. The java code only displayed when I tried it as you suggested. My original and current problem still is the right html bracket appearing on the form.
 
hi Mary,

this works fine for me in Tomcat 4.1.29:

Code:
<%
  String fname = &quot;foo&quot;;
%>

 <INPUT TYPE=&quot;text&quot; name=&quot;firstname&quot; 
  value=&quot;<% out.println( fname ); %>&quot; />

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
there could be other errors on your page - show the whole source to your page

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 

Of course... It is possible that the variable
Code:
fname
has a '>' character at the end of it.

What happens if you output fname elsewhere... maybe at the top of the body tag, you could put:

Code:
<body>
   <!-- <%=fname%> -->
   ...

Then view source and see what you have...

Just a thought ;o)

Dan
 
Mary,
You might want to create a backup of your file before you start &quot;commenting out&quot; sections of your code. You must also make sure that you get the comment command correct (try saying that 10 times really fast!).

In JSP you'll need to use &quot;//&quot; at the start of the line. You cannot use:
Code:
<!--
<%
   ...
%>
-->
since this will only comment out the code in the browser. The JSP code will still be executed by the webserver.

Example:
Code:
<!--
<%
	out.print(&quot;value='&quot;+fname+&quot;'&quot;);
%>
-->
This will output (assuming fname=pete):
Code:
<!--
value='pete'
-->
in the browser, which shouldn't display anything in the browser screen. However, the JSP code has still executed.

You should use:
Code:
<%
//	out.print(&quot;value='&quot;+fname+&quot;'&quot;);
%>
Which will tell the JSP server, not to execute the code following the comment.

Looking at your original post, I have done some further testing. The code (even though it is invalid is still ok to test with):
Code:
<tr>
    <td>First Name:  </td>
    <td><INPUT TYPE=&quot;text&quot; name=&quot;firstname&quot;
<%
	String fname=new String();
	fname=&quot;pete&quot;;
    out.println(&quot;value='&quot;+fname+&quot;'&quot;);
%> > 
</td>
when served from a JSP server, performs as expected. The result was:
Code:
First Name: [b]pete[/b]
where the bold &quot;pete&quot; is an input box.

The same code served from the file system performs (as expected) very differently. And yes, an extra HTML bracket is displayed:
Code:
First Name: [blank input box] >

You MUST ensure that JSP files are served from a JSP (Apache-Tomcat is one such example) Server.

What is the URL that you are entering into your browser???

Pete.


Web Developer / Aptrix CMS (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Pete,

Thanks. The JSP server was the problem. We didn't have one at the office and the area my code was moved into at school doesn't appear to have one either. I was just working from my desktop at the office. The info on the comments was very helpful as well. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top