Click to See Complete Forum and Search --> : passing JSP String to an Javascript Variable


gnanesh
07-14-2003, 09:19 AM
folks

i am returning an value from Java Objects inside Scriptlet tags and i need to pass this to an "var" inside an JavaScript, please let me know how can i pass , i tried using below , but getting syntax error

var str = "<%=value%>"; // this is an Expression tag in JSP

Any help is appreciated

Thanks
GG

Khalid Ali
07-14-2003, 10:26 AM
whats the error you are getting?

gnanesh
07-14-2003, 10:35 AM
Khalid

Thanks for the response, by the way here is the code i.e. a FORM tag which i am generating from an DynamicObject(java class) i will be passing this generated FORM to an Javascript variable

<FORM name="vcc_form" id="vcc_form" class="vcc_form_class">
<fieldset style="border:blue solid 1px"><legend id="legend_vcc">
<b><font color="#0000FF">VCC</font></b></legend><div align= "center">
<label for="vcc.vcc_number_input_text"><b>VCC Number:</b></label>
<input type="text" name="vcc.vcc_number_input_text" value="0.38" id="vcc.vcc_number_input_text" class="vcc.vcc_number_input_text_class ">
</input>
<br>
<label for="vcc.vcc_type_input_text"><b>VCC Type:</b></label>
<input type="text" name="vcc.vcc_type_input_text" value="ubr" id="vcc.vcc_type_input_text" class="vcc.vcc_type_input_text_class ">
</input>
<br>
<br>
<input type=submit value="create" name=create_ vcc>
<input type=submit value="update" name=update_vcc>
<input type=submit value="delete" name=create_ vcc>
<input type=submit value="search" name=update_vcc>
<br><br></div> </fieldset></FORM>

Based on some values , but if i print using

System.out.println(str);

this will work but if i pass that too

document.getElementById("").innerHTML = "str";

I am getting a error saying Expected ";"

Let me know if i need to do any delimitation for Form attributes

Thanks
Gnanesh

Khalid Ali
07-14-2003, 11:01 AM
id you leave
document.getElementById("").innerHTML = "str";
id("") empty on purpose?...just curious

gnanesh
07-14-2003, 11:05 AM
this is what i am doing :-

var str = <%=value%>; // this i will get from DynamicObject class

alert(str); //
document.getElementById('displayForm').innerHTML = "<%=value%>";

"displayForm" is the id value of an DIV tag,

Let me know about this

Regards
\Gnanesh

Khalid Ali
07-14-2003, 11:14 AM
Here try this link..I just put it together for you to get the concept..

http://68.145.35.86/dev/jsp/testjsp.jsp

gnanesh
07-14-2003, 12:32 PM
I did the same way , but don't know why i am getting this kind of problem saying "Line xxx
"Error:Expected ';'

Let me know this is what i am doing now :-

var str = '<%=value%>';
alert(str);
document.getElementById('displayForm').innerHTML = "str";


To the var str i am passing the '<form>
rest goes here----
</form>'

and don't know why i am getting this kind of problem

This piece giving lot of troubles, As i need this to be done today itself

Thanks & Regards
Gnanesh

Khalid Ali
07-14-2003, 01:53 PM
Well first of you need to take a look at the code I posted/link I posted.

You'd notice few things.
You can only access document.getElementById once document is loaded.Therefore you need to do perform that corm creation once the page loads and that you can do in onload event of the body tag..take a good look at code of the link I posted for you above...

gnanesh
07-14-2003, 02:43 PM
I found out some thing from the resulted string i.e from

<%=value%>

when i pass this value to the javascript var like

var str = "<%=value%>;

i was not able to display because of some ending quotes when i generate an HTML out of DynamicObject , If i do like this below

" <FORM name='vcc_form' id='vcc_form' class='vcc_form_class'><fieldset style='border:blue solid 1px'><legend id='legend_vcc'><b><font color='#0000FF'>VCC</font></b></legend><div align='center'>"+
" <label for='vcc.vcc_number_input_text'><b>VCC Number:</b></label><input type='text' name='vcc.vcc_number_input_text' value='0.38' id='vcc.vcc_number_input_text' class='vcc.vcc_number_input_text_class '></input>"+
" <br> <label for='vcc.vcc_type_input_text'><b>VCC Type:</b></label><input type='text' name='vcc.vcc_type_input_text' value='ubr' id='vcc.vcc_type_input_text' class='vcc.vcc_type_input_text_class '></input>"+
" <p><input type=submit value='create' name=create_vcc> "+
" <input type=submit value='update' name=update_vcc> "+
" <input type=submit value='delete' name=delete_vcc> "+
" <input type=submit value='search' name=search_vcc> "+
" <br><br></div> </fieldset></FORM> ";

It does work good, I really don't know how to separate these in my DynamicObject,

Let me know your suggestions

Regards
GG

Khalid Ali
07-14-2003, 04:49 PM
jus use the code in the link I posted...and you should be ok

gnanesh
07-14-2003, 04:52 PM
Got it ,

Thanks for your help

Regards
GG

Khalid Ali
07-14-2003, 05:07 PM
:D
You are welcome..

shilpatendulkar
05-30-2006, 09:49 AM
Here try this link..I just put it together for you to get the concept..

http://68.145.35.86/dev/jsp/testjsp.jsp
I have same problem listed in forum. I tried to execute the link provided above , it gives DNS error. If you read this post could you send working URL for the same problem ? thanks