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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Script Error 1

Status
Not open for further replies.

portalguy123

Programmer
Sep 19, 2006
40
US
Hello Experts,

I am dynamically generating textboxes using javascript and validating the values inserted into these textboxes.

I have the following line of code in my jsp ..

<a name="calendarAnchor<%=count%>" id ="calendarAnchor<%=count%>" href="#" onClick ="cal1.select(document.forms[0].<%=prefix%>completionDate{actionForm.insertItems[<%=count%>].completionDate},'calendarAnchor<%=count%>','MM/dd/yyyy');return false;"> Select Completion Date</a>

The bolded line of code is givng an error "Expected )" when the javascript function seelct is is invoked..

FYI .. the select function is defined as follows..

function CP_select(inputobj, linkname, format)

Can you please let me know what the problem might be ..

Thanx in advance.

-Bob
 
Why are you using curly braces inside a Javascript function call?

Lee
 
Code:
<a name="calendarAnchor<%=count%>" id ="calendarAnchor<%=count%>" href="#" onClick ="cal1.select(document.forms[0].<%=prefix%>completionDate[COLOR=red]{[/color]actionForm.insertItems[<%=count%>].completionDate[COLOR=red]}[/color],'calendarAnchor<%=count%>','MM/dd/yyyy');return false;"> Select Completion Date</a>

Code:
onClick ="cal1.select(document.forms[0].<%=prefix%>completionDate(actionForm.insertItems[<%=count%>].completionDate),'calendarAnchor<%=count%>','MM/dd/yyyy');return false;">
 
Hello Tollacious ,

Thanx for the reply, I am using the curly braces within the call becuase thats the name of the element , its named like that becuase I need to map these values back to the actionform with in the portal.

Do you think the curly braces used in the name of the elemnt are causing this error.If so is there a workaround for this ..

Thanks again..
 
Your curly braces aren't inside a character string value. Think about how Java would handle a variable name with a curly brace in it.

Please show the final HTML output of your code, not the server side scripting, too. Neither you nor we can see the real HTML on the page as long as the scripting is intact.

Lee
 
Hello trollacious,

Here's teh generated HTML code.

<td>
<input TYPE="text" NAME="portlet_1_1completionDate{actionForm.insertItems[0].completionDate}" VALUE="" SIZE=10 />
</td>
<td>
<a name="calendarAnchor0" id ="calendarAnchor0" href="#" onClick ="cal1.select(document.forms[0].portlet_1_1completionDate{actionForm.insertItems[0].completionDate},'calendarAnchor0','MM/dd/yyyy');return false;">Select Completion Date</a>
</td>


Do you think having the curly braces in sigle quotes might solve the problem, I am gonna try that now..

Thanks j4606 ,

But thats not what I need to do I have to pass the actual name of the input type text element which includes the curly braces.



 
Curly braces in a name are definitely looking for trouble. Try this:
Code:
document.forms[0].elements['portlet_1_1completionDate{actionForm.insertItems[0].completionDate}']

That still doesn't look correct, and using square brackets in a form element name is also looking for trouble for the same reason.

Lee
 
Thanks Lee!

Guess what it works , btu I still dont get it what do you think was wrong with my approach..
 
You mean the part that didn't work? Like I said, curly braces and square brackets are reserved characters in Javascript, and you have to handle element names and IDs containing those characters more carefully. I've found that people who write code that contains stuff like that generally create more errors (like the example in this posting) in their code.

Lee
 
Thanks Lee!

Actually I am kinda new to to javascript and I am disappointed not to find any standard documentation for javascript, is the w3schools the official documentation for standard javascript, or is there any other source.

Coming back to curly braces no where did I see that they are special characters so as to be able to use the escape sequence.
 
A simple Google search for "Javascript documentation" will provide you with all sorts of links. Here's a good one:


As well, Javascript isn't part of the W3C standard, and is used in a variety of environments other than web browsers. It's officially known as ECMAScript, and the standards are here:


If you use Java Server Pages (and it sounds like you do), C, C++, Java, PHP, Perl, or a variety of other C-related programming languages, what happens if you put a curly brace or square bracket in a variable name? Something like:

Code:
int some{int};
long this[long];

When you access page elements the way you originally wrote your code, you named a property of an object using BOTH square brackets and curly braces, then tried to access it directly by its name. This can be handled using the associative arrays, as the final result shows (and which I always use now anyway), but that's the only way (so far).

Lee
 
Hello Experts!

The following java script code is giving an error when I click on the anchor.Any suggestions or anythign you see that might be wrong.Please let me know.

Thanks
Bob

Code:
<a id="portlet_1_1calendarAnchor" href="javascript:alert(getNetuiTagName("calendarAnchor",this));cal1.select(document[getNetuiTagName("reportsForm",this)][getNetuiTagName("date",this)],getNetuiTagName("calendarAnchor",this),'MM/dd/yyyy');return false;">Select Completion Date</a>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top