943,544 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 12382
  • JSP RSS
You are currently viewing page 1 of this multi-page discussion thread
May 26th, 2009
0

scriptlet in javascript

Expand Post »
hii..
I want to use a scriplet variable in javascript.
i used
<%! int i;>
<% i=0; %>
<input type="text" id="itemValue" onchange=changeValue('<%i%>')>

it works fine if i give alert(i) in
changeValue function.
Otherwise it gives error i is undefined.
Plz help me. I don't want to bother user by increasing one user click.
Plz help what is the reason ????

i m using struts 1.2

Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mamatachaudhari is offline Offline
20 posts
since Apr 2009
May 26th, 2009
0

Re: scriptlet in javascript

Try this:
changeValue('<%=i%>')
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
May 27th, 2009
0

Re: scriptlet in javascript

Click to Expand / Collapse  Quote originally posted by javaAddict ...
Try this:
changeValue('<%=i%>')
Thanks for reply....
It's not working..
when i first time load my project it gives me error like i is undefined
But after giving an alert it works fine...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mamatachaudhari is offline Offline
20 posts
since Apr 2009
May 27th, 2009
0

Re: scriptlet in javascript

Thanks for reply....
It's not working..
when i first time load my project it gives me error like i is undefined
But after giving an alert it works fine...
What do you mean giving an alert. Post the code that works
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
May 27th, 2009
0

Re: scriptlet in javascript

Click to Expand / Collapse  Quote originally posted by javaAddict ...
What do you mean giving an alert. Post the code that works
This is my input text field

JSP Syntax (Toggle Plain Text)
  1. <input type="text" id="productQuantity" size="5" onchange="changeQuantity(this.form,'<bean:write property="productCode" name="product"/>','<%=z %>');"/>

And this is my javaScript function is..


JavaScript Syntax (Toggle Plain Text)
  1. function changeQuantity(form,productCode,index)
  2. {
  3. //alert("z==="+productCode);
  4. lengthOfItems=form.productCombo.options.length;
  5. lengthOfProducts=form.productCombo2.options.length;
  6. alert("index"+index);
  7. changeItemValueNew(form,productCode,index);
  8. }

after giving that alert messsage it works otherwise not.

}
Last edited by peter_budo; May 27th, 2009 at 11:01 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mamatachaudhari is offline Offline
20 posts
since Apr 2009
May 27th, 2009
0

Re: scriptlet in javascript

First of all describe better what do you mean by this:
after giving that alert messsage it works otherwise not.

Also, firstly does the method being called correctly?

Try this to check the above:
JSP Syntax (Toggle Plain Text)
  1. function changeQuantity(form,productCode,index)
  2. {
  3. alert("Method called");
  4. }

Then see if the arguments are passed correctly:
JSP Syntax (Toggle Plain Text)
  1. function changeQuantity(form,productCode,index)
  2. {
  3. alert(productCode);
  4. alert(index);
  5. }

Then try your code with alert messages between the other commands (like debugging) to see what is wrong
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
May 27th, 2009
0

Re: scriptlet in javascript

Create the variable in the javaScript
and store the value in it
then use it


JSP Syntax (Toggle Plain Text)
  1. function changeQuantity(form,productCode,index)
  2. {
  3. var z=productCode;
  4. var y=index;
  5. lengthOfItems=form.productCombo.options.length;
  6. lengthOfProducts=form.productCombo2.options.length;
  7. alert("index"+index);
  8. changeItemValueNew(form,z,y);
  9. }
Reputation Points: 2
Solved Threads: 1
Newbie Poster
amarjeetsingh is offline Offline
21 posts
since Feb 2009
May 27th, 2009
0

Re: scriptlet in javascript

Create the variable in the javaScript
and store the value in it
then use it

JSP Syntax (Toggle Plain Text)
  1. var z=productCode;
  2. var y=index;
I don't believe that it will solve the problem. If this will execute correctly:
JSP Syntax (Toggle Plain Text)
  1. var z=productCode;
  2.  
  3. changeItemValueNew(form,z,y)
then this will also:
JSP Syntax (Toggle Plain Text)
  1. changeItemValueNew(form,productCode,index);
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
May 27th, 2009
0

Re: scriptlet in javascript

Create the variable in the javaScript
and store the value in it
then use it


JSP Syntax (Toggle Plain Text)
  1. function changeQuantity(form,productCode,index)
  2. {
  3. var z=productCode;
  4. var y=index;
  5. lengthOfItems=form.productCombo.options.length;
  6. lengthOfProducts=form.productCombo2.options.length;
  7. alert("index"+y);
  8. changeItemValueNew(form,z,y);
  9. }

if you do calulation in java script, then you must be attentative
about the data type of the variable

java script is not strictly check the datatype of the variable

i do n't know what have you done in
JSP Syntax (Toggle Plain Text)
  1. changeItemValueNew(form,z,y)

method
Reputation Points: 2
Solved Threads: 1
Newbie Poster
amarjeetsingh is offline Offline
21 posts
since Feb 2009
May 27th, 2009
0

Re: scriptlet in javascript

i do n't know what have you done in
JSP Syntax (Toggle Plain Text)
  1. changeItemValueNew(form,z,y)

method
We still don't know if the code before the call of that method is executed
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Jsp output in pdf file
Next Thread in JSP Forum Timeline: sleep a jsp page for a certain time





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC