scriptlet in javascript

Thread Solved

Join Date: Apr 2009
Posts: 17
Reputation: mamatachaudhari is an unknown quantity at this point 
Solved Threads: 0
mamatachaudhari mamatachaudhari is offline Offline
Newbie Poster

scriptlet in javascript

 
0
  #1
May 26th, 2009
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

Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: scriptlet in javascript

 
0
  #2
May 26th, 2009
Try this:
changeValue('<%=i%>')
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 17
Reputation: mamatachaudhari is an unknown quantity at this point 
Solved Threads: 0
mamatachaudhari mamatachaudhari is offline Offline
Newbie Poster

Re: scriptlet in javascript

 
0
  #3
May 27th, 2009
Originally Posted by javaAddict View Post
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...
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: scriptlet in javascript

 
0
  #4
May 27th, 2009
Originally Posted by mamatachaudhari View Post
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
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 17
Reputation: mamatachaudhari is an unknown quantity at this point 
Solved Threads: 0
mamatachaudhari mamatachaudhari is offline Offline
Newbie Poster

Re: scriptlet in javascript

 
0
  #5
May 27th, 2009
Originally Posted by javaAddict View Post
What do you mean giving an alert. Post the code that works
This is my input text field

  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..


  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: scriptlet in javascript

 
0
  #6
May 27th, 2009
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:
  1. function changeQuantity(form,productCode,index)
  2. {
  3. alert("Method called");
  4. }

Then see if the arguments are passed correctly:
  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
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 21
Reputation: amarjeetsingh has a little shameless behaviour in the past 
Solved Threads: 1
amarjeetsingh amarjeetsingh is offline Offline
Newbie Poster

Re: scriptlet in javascript

 
0
  #7
May 27th, 2009
Create the variable in the javaScript
and store the value in it
then use it


  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. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: scriptlet in javascript

 
0
  #8
May 27th, 2009
Originally Posted by amarjeetsingh View Post
Create the variable in the javaScript
and store the value in it
then use it

  1. var z=productCode;
  2. var y=index;
I don't believe that it will solve the problem. If this will execute correctly:
  1. var z=productCode;
  2.  
  3. changeItemValueNew(form,z,y)
then this will also:
  1. changeItemValueNew(form,productCode,index);
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 21
Reputation: amarjeetsingh has a little shameless behaviour in the past 
Solved Threads: 1
amarjeetsingh amarjeetsingh is offline Offline
Newbie Poster

Re: scriptlet in javascript

 
0
  #9
May 27th, 2009
Create the variable in the javaScript
and store the value in it
then use it


  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
  1. changeItemValueNew(form,z,y)

method
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,658
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: scriptlet in javascript

 
0
  #10
May 27th, 2009
Originally Posted by amarjeetsingh View Post
i do n't know what have you done in
  1. changeItemValueNew(form,z,y)

method
We still don't know if the code before the call of that method is executed
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JSP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC