PDA

View Full Version : JavaScript error: HTTP Status 404 - /0



adusumalli
Jul 2nd, 2009, 07:18 PM
Hi I am getting this Java Script error:
HTTP Status 404 - /0
when i try change the dropdown values.

Actually I have two dropdowns based on two dropdown values needs to change the page. In first dropdown I have two values. when i select a value from 1st dropdown, the selected dropdown values should be diplayed in second dropdown. It works fine upto that. After displaying 2nd dropdown values , when i choose one of the values from 2nd dropdown I need to get the value of 1st dropdown as well as 2nd dropdown value. but it's failing in scripting and throws the above error in browser. I am using the following script code.



function MM_jumpMenu3(targ,selObj,uvalue,restore)
{
var s = selObj.options[selObj.selectedIndex].value; // this is value of 2nd dropdown.
var u = uvalue.options[uvalue.selectedIndex].value; // this is value of 1st dropdown.
alert('value of s>> '+s);
alert('value of u>> '+u);
if ( s.substring(0,1) != '_' && u.substring(0,1) != '_' )
{
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'&'"+uvalue.options[uvalue.selectedIndex].value+"'");
alert('eval>>'+eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'&'"+uvalue.options[uvalue.selectedIndex].value+"'")); // here i am getting the error. same time in browser getting error and then popup this alert message.
}
else
{
s = s.substring(1, s.length);
eval( s );
}
}


thanks in advance.

adusumalli
Jul 4th, 2009, 09:17 AM
any body give an idea on this ??

ckeyrouz
Jul 5th, 2009, 08:37 AM
Can you please post the result of the alert without the eval:

alert('eval>>'+eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'&'"+uvalue.options[uvalue.selectedIndex].value+"'"));

let it be like this:
alert(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'&'"+uvalue.options[uvalue.selectedIndex].value+"'");

I am not able to see the problem with this alert.

adusumalli
Jul 6th, 2009, 09:47 PM
hi thanks for reply. I am getting from the alert as you said.

parent.location='ozCalDay.jsp?csvid=43'&'users'

Now I change it as parent.location='ozCalDay.jsp?csvid=43&users' this it works fine and page is displaying

hey thanks a lot.

ckeyrouz
Jul 6th, 2009, 10:11 PM
If you feel that I did help you in solving the problem, kindly click on the button thank user since I want to increase my credit in this forum.
Thank you.

adusumalli
Jul 7th, 2009, 12:09 AM
hi , in this functionality i have one more doubt in Javascript i am getting 1st dropdown value which is 'users' after that i have to execute the following logic.



if ( _pps.getValue(_ahsPage, "CAL_UI_NEW").equals("Y") && !_req.getParam("nofwd").equals("Y") )
{
DbServerConfig.releaseConnection(conn);
out.println( org.oz.common.ui.html.HtmlFwd.renderFwdHtml( _ahsPage, "ozCalCal.jsp?day="+_req.getParam("day")+"&csvid="+_req.getParam("csvid")+"&userview="+_req.getParam("userview") ) );
return;
}


here, i am not getting _req.getParam("userview") this value which is 'users' in JS method. but able to get the _req.getParam("csvid") value which is '43' in above JS method.

can you suggest me on this ??

thanks

adusumalli
Jul 7th, 2009, 12:13 AM
hi , in this functionality i have one more doubt in Javascript i am getting 1st dropdown value which is 'users' after that i have to execute the following logic.



if ( _pps.getValue(_ahsPage, "CAL_UI_NEW").equals("Y") && !_req.getParam("nofwd").equals("Y") )
{
DbServerConfig.releaseConnection(conn);
out.println( org.oz.common.ui.html.HtmlFwd.renderFwdHtml( _ahsPage, "ozCalCal.jsp?day="+_req.getParam("day")+"&csvid="+_req.getParam("csvid")+"&userview="+_req.getParam("userview") ) );
return;
}


here, i am not getting _req.getParam("userview") this value which is 'users' in JS method. but able to get the _req.getParam("csvid") value which is '43' in above JS method.

can you suggest me on this ??

thanks

ckeyrouz
Jul 7th, 2009, 04:25 AM
Can you please post the code of how your are sending the parameters to this file?
I mean in the file that is calling this one.

adusumalli
Jul 7th, 2009, 06:23 AM
Actually My functionality is, I have 2 dropdown values in page. In 1st dropdown i have two values. based these values (1st dropdown values) 2nd dropdown values should be displayed. when i choose the 2nd dropdown values the page will reload based on selected values in 1st & 2nd dropdown. To execute this functionality i need to pass the 1st dropdown value. but it's not able to do that.
Here is the code for dropdown values


<td class=verySmall align=center valign=top>
<select name=userview id=userview class="selInputSmall" onChange="changeDropDown(this.value)">
<option value="users" >Users</option> // These are 1st dropdown values/
<option value="views" >Views</option>
</select>
</td>
<td class=verySmall align=right valign=top>
<div id="users" style="display: block;">
<%=_p.get("by_user")%>:
<%
if (_vUsers.size() > 0) out.println( UserUtil.renderUserByDropdown( _ahsPage, _vUsers, _req, "userview", "ozCalDay.jsp", "selInputSmall"));
%>
</div>
<div id="views" style="display: none;">
<%=_p.get("display")%>:
<%
if ( _vCalShareView.size() > 0 ) out.println( CalendarShareView.renderViewByDropdown( _ahsPage, _vCalShareView, _req, "ozCalDay.jsp", "selInputSmall") );
else out.println( "<a href=\"javascript:OZ_openBrWin3('ozCalLOVUserSel.jsp', 'calUserPopup');\">"+AhsStringUtil.limitLength( sCalDispUsers, 48 )+"</a>" );
%>
</div>
</td>


This method calling from the above code.



public static String renderUserByDropdown ( AhsPageWebBean ahsPage, Vector vUsers, AhsRequest _req, String userview, String jumpUrl, String className )
{
OzPromptStd _prompt = new OzPromptStd( ahsPage );
//Vector vEntries = getEntries( ahsPage );
StringBuffer buf = new StringBuffer();

// WP is with Param
String jumpUrlWP = jumpUrl+"?";
for (Enumeration e=_req.getRequest().getParameterNames(); e.hasMoreElements(); )
{
String paramName = (String) e.nextElement();
if ( paramName == null || paramName.equals("") || paramName.equals("csvid") )
continue;
String paramVal = _req.getParam( paramName );
if ( paramVal == null || paramVal.equals("") )
continue;

jumpUrlWP += paramName + "=" + paramVal + "&";
}

buf.append( "<select name=\"calShareViewNA\" class=\""+className+"\" onChange=\"MM_jumpMenu3('parent',this, document.getElementById('userview'))\">" );
for (int i=0; i<vUsers.size(); i++)
{
FwkUserEO users = (FwkUserEO) vUsers.get(i);
buf.append( " <option value=\""+jumpUrlWP+"csvid="+users.getID()+"\" " );
if ( _req.getInt("csvid",-1) == users.getID() )
buf.append( "selected" );
buf.append( "> " + users.getName() );
}
buf.append( "</select>" );
return buf.toString();
}


From the above method onchange JS method is calling


function MM_jumpMenu3(targ,selObj,uvalue,restore)
{
var s = selObj.options[selObj.selectedIndex].value;
var u = uvalue.options[uvalue.selectedIndex].value;
if ( s.substring(0,1) != '_' && u.substring(0,1) != '_' )
{
alert('test>>'+targ+".location='"+selObj.options[selObj.selectedIndex].value+"&"+uvalue.options[uvalue.selectedIndex].value+"'");
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"&"+uvalue.options[uvalue.selectedIndex].value+"'");
}
else
{
s = s.substring(1, s.length);
eval( s );
}
}


from the above JS method i am calling this jsp: ozcalDay.jsp



if ( _pps.getValue(_ahsPage, "CAL_UI_NEW").equals("Y") && !_req.getParam("nofwd").equals("Y") )
{
DbServerConfig.releaseConnection(conn);
out.println( org.oz.common.ui.html.HtmlFwd.renderFwdHtml( _ahsPage, "ozCalCal.jsp?day="+_req.getParam("day")+"&csvid="+_req.getParam("csvid")+"&userview="+_req.getParam("userview") ) );
return;
}


thanks..

ckeyrouz
Jul 7th, 2009, 06:44 AM
Ok I got it now:
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"&"+uvalue.options[uvalue.selectedIndex].value+"'");

this command is missing the keyword userview
your code should be like this:

eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"&userview="+uvalue.options[uvalue.selectedIndex].value+"'");

check the changes I have done in RED

adusumalli
Jul 7th, 2009, 07:39 PM
hi, now i got the 1st dropdown value also when i use ur above statement. one more thing, when i change the 2nd value in 1st dropdown ( I said in previous post in 1st dropdown i have only 2 values those are 'users' and 'views'), based on that the 2nd dropdown values will changed. It's happening. but when i choose 2nd dropdown value in the following of the request parameter id is taking correctly but 1st dropdown value it take 'users' instead of 'views' in this code.



if ( _pps.getValue(_ahsPage, "CAL_UI_NEW").equals("Y") && !_req.getParam("nofwd").equals("Y") )
{
DbServerConfig.releaseConnection(conn);
out.println( org.oz.common.ui.html.HtmlFwd.renderFwdHtml( _ahsPage, "ozCalCal.jsp?day="+_req.getParam("day")+"&csvid="+_req.getParam("csvid")+"&userview="+_req.getParam("userview") ) ); // here userview = 'views' instead of 'users'
return;
}


These are 1st and 2nd dropdown values as i post earlier.


<td class=verySmall align=center valign=top>
<select name=userview id=userview class="selInputSmall" onChange="changeDropDown(this.value)">
<option value="users" >Users</option>
<option value="views" >Views</option>
</select>
</td>
<td class=verySmall align=right valign=top>
<div id="users" style="display: block;">
<%=_p.get("by_user")%>:
<%
if (_vUsers.size() > 0) out.println( UserUtil.renderUserByDropdown( _ahsPage, _vUsers, _req, "userview", "ozCalDay.jsp", "selInputSmall"));
%>
</div>
<div id="views" style="display: none;">
<%=_p.get("display")%>:
<%
if ( _vCalShareView.size() > 0 ) out.println( CalendarShareView.renderViewByDropdown( _ahsPage, _vCalShareView, _req, "userview", "ozCalDay.jsp", "selInputSmall") );
else out.println( "<a href=\"javascript:OZ_openBrWin3('ozCalLOVUserSel.jsp', 'calUserPopup');\">"+AhsStringUtil.limitLength( sCalDispUsers, 48 )+"</a>" );
%>
</div>
</td>


This method is in JAva, when i choose 'views'(2nd value in 1st dropdown) in 1st dropdown, the following method is execute to display values in 2nd dropdown based on 'views'


public static String renderViewByDropdown ( AhsPageWebBean ahsPage, Vector vCalShareView, AhsRequest _req, String userview, String jumpUrl, String className )
{
OzPromptStd _prompt = new OzPromptStd( ahsPage );
Vector vEntries = getEntries( ahsPage );
StringBuffer buf = new StringBuffer();

// WP is with Param
String jumpUrlWP = jumpUrl+"?";
for (Enumeration e=_req.getRequest().getParameterNames(); e.hasMoreElements(); )
{
String paramName = (String) e.nextElement();
if ( paramName == null || paramName.equals("") || paramName.equals("csvid") )
continue;
String paramVal = _req.getParam( paramName );
if ( paramVal == null || paramVal.equals("") )
continue;

jumpUrlWP += paramName + "=" + paramVal + "&";
}

buf.append( "<select name=\"calShareViewNA\" class=\""+className+"\" onChange=\"MM_jumpMenu3('parent',this,document.getElementById('userview'))\">" ); // Here same javascript method will execute after that it goes to the if condition of ozcalDay.jsp which is the first code in this post.
for (int i=0; i<vCalShareView.size(); i++)
{
CalendarShareView csv = (CalendarShareView) vCalShareView.get(i);
buf.append( " <option value=\""+jumpUrlWP+"csvid="+csv.getID()+"\" " );
if ( _req.getInt("csvid",-1) == csv.getID() )
buf.append( "selected" );
buf.append( "> " + csv.getName() );
}
buf.append( "<option value=\"#\"> ---------- " );
buf.append( "<option value=\"_OZ_openBrWin3('ozCalLOVUserSel.jsp', 'calUserPopup');\"> "+_prompt.get("setup") ); // the _ at the start will call js
buf.append( "</select>" );
return buf.toString();
}


is it bcoz of by default selected value is 'users' in 1st dropdown ? or <select name="calShareViewNA" is same ?

thanks

ckeyrouz
Jul 7th, 2009, 07:46 PM
Can you please post the code of the js function changeDropDown that is called onchange of the userview select.

adusumalli
Jul 7th, 2009, 07:50 PM
Here, always it takes the 1st dropdown value as 1st time i choose either 'users' or 'views' .
Even when i change the 1st dropdown value it takes into the req.getParameter as old value .

adusumalli
Jul 7th, 2009, 07:51 PM
this is changedropdown js function.



function changeDropDown(which) {
if (which == "views") {
document.getElementById('views').style.display = "";
document.getElementById('users').style.display = "none";
}
else {
document.getElementById('views').style.display = "none";
document.getElementById('users').style.display = "";
}
}

adusumalli
Jul 7th, 2009, 08:00 PM
In the MM_jumpMenu3 js function , second time
the value of "s" is >> ozCalDay.jsp?userview=views&csvid=41 ( userview=views is fist time i choose the value in 1st dropdown)
value of "u" is >> users
and alert('test>>' +targ+".location='"+selObj.options[selObj.selectedIndex].value+"&userview="+uvalue.options[uvalue.selectedIndex].value+"'" ) = parent.location='ozCalDay.jsp?userview=views&csvid=41&userview=users'

in this js function, in the above result it keeping the old 1st dropdown value.

ckeyrouz
Jul 7th, 2009, 08:06 PM
The code seems to be correct, but I want you to post the result of the following alert:

in the beginning of the function : alert(uvalue.selectedIndex)

adusumalli
Jul 7th, 2009, 08:22 PM
when 'users' is there in 1st dropdown the result of alert(uvalue.selectedIndex) = '0' ,
if it is 'views' the result of alert(uvalue.selectedIndex) = '1'.

but value of s is >> ozCalDay.jsp?userview=views&csvid=43 is showing.

when i choose 'users' first time, value of s is >> ozCalDay.jsp?userview=users&csvid= always it takes.

when i chosse 'views' first time, value of s is >> ozCalDay.jsp?userview=view&csvid= always it takes.

but csvid is changing based on 2nd dropdown selected value. bcoz of that i think it takes first time selected value in request.getParameter in ozCalDay.jsp

thanks

adusumalli
Jul 8th, 2009, 05:32 PM
hi do i need to update any thing in my code regarding to get first dropdown value in request.getParameter ?

adusumalli
Jul 8th, 2009, 10:32 PM
Hey Now i am able to get the individual values of 1st dropdown and 2nd dropdown. By default in 1st dropdown 'users' is selected . How do i pass that selected value ('users') to the request.getParameter for first time?

ckeyrouz
Jul 8th, 2009, 10:42 PM
I think you were doing it the right way.
Am not able to see the error, just give me some time I am trying to debug it deeply by simulating the same code you have written and I will be back to you.

adusumalli
Jul 8th, 2009, 11:11 PM
By Default onChange js function MM_jumpMenu3 is not calling. so when we change the value from 2nd dropdown then only this MM_jumpMenu3 js function will call and then we can pass 1st dropdown value and 2nd dropdown value. After that in the following code, we can get those values. But I need get the _req.getParam("userview") value as 'users' by default. How do i get that value ??


if ( _pps.getValue(_ahsPage, "CAL_UI_NEW").equals("Y") && !_req.getParam("nofwd").equals("Y") )
{
// Forward: we serialize the session back to DB, close the connection, and fwd
DbServerConfig.releaseConnection(conn);
out.println( org.oz.common.ui.html.HtmlFwd.renderFwdHtml( _ahsPage, "ozCalCal.jsp?day="+_req.getParam("day")+"&csvid="+_req.getParam("csvid")+"&userview="+_req.getParam("userview") ) );
return;
}

adusumalli
Jul 9th, 2009, 08:41 PM
How do I get the _req.getParam("userview") value as 'users' by default first time ??

ckeyrouz
Jul 9th, 2009, 08:51 PM
Sorry for being late I was trying to find the most dynamic solution for it but for the time being you can do it like this:
String userview = (_req.getParam("userview") != null) ? _req.getParam("userview") : "users";
if ( _pps.getValue(_ahsPage, "CAL_UI_NEW").equals("Y") && !_req.getParam("nofwd").equals("Y") )
{
// Forward: we serialize the session back to DB, close the connection, and fwd
DbServerConfig.releaseConnection(conn);
out.println( org.oz.common.ui.html.HtmlFwd.renderFwdHtml( _ahsPage, "ozCalCal.jsp?day="+_req.getParam("day")+"&csvid="+_req.getParam("csvid")+"&userview="+userview) );
return;
}

so by default it will be user this means before the page loads, but it is a bit static and it might solve your problem until you figure out a better solution, like putting the default value in the database or in properties file or even in the web.xml, it is upon you.

Hope this hleps.

adusumalli
Jul 9th, 2009, 11:02 PM
hi.Now it's working . with the following statement
String userview = (!_req.getParam("userview").equals("") ) ? _req.getParam("userview") : "users";

But , when i change 1st dropdown value as 'views' and based on 'views' 2nd dropdown values will be changed. upto it works fine. but when i change 2nd dropdown value on 'views' it's not maintaining in dropdown. it goes to 'users' in 1st dropdown .

ckeyrouz
Jul 9th, 2009, 11:19 PM
If I understand what you are really doing then the page is being reloaded after the change in the second drop down list.

So in brief the page is being reset.

A solution for it is this:

in your servlet after this line:
String userview = (!_req.getParam("userview").equals("") ) ? _req.getParam("userview") : "users";

put the followingL
_req.setAttribute("userview",userview );

in your jsp file do the following:
String userview = (request.getAttribute("userview") != null) ? (String)request.getAttribute("userview") : "-1";


in your java script and in the onload of the body do this:

<body onload="setComboVal()">.......etc etc /body>

in the script add the following function

function setComboVal()
{
var selOption = "<%=userview>";
if(selOption != "-1")
{
var zOpts = document.getElementById("userview").options;
for(var i=0; i< zOpts.length; i++)
{
if(zOpts[i].value == selOption)
{
zOpts[i].selected = true;
break;
}
}
}
}

adusumalli
Jul 10th, 2009, 12:47 AM
based on changing the values in both dropdowns it works fine. but it maintains as 'users' always. when i change the 2nd dropdown values on 'views'(1st dropdown 2nd value).

I used the following code for 1st dropdown.


<td class=verySmall align=center valign=top>
<select name=userview id=userview class="selInputSmall" onChange= "changeDropDown(this.value)">
<option value="users" >Users</option>
<option value="views" >Views</option>
</select>
</td>

This is for 2nd dropdown but in same jsp.


<td class=verySmall align=right valign=top>
<div id="users" style="display: block;">
<%=_p.get("by_user")%>:
<%
if ( _req.getParam("userview").equals("users"))
{
if (_vUsers.size() > 0) out.println( UserUtil.renderUserByDropdown( _ahsPage, _vUsers, _req, "userview", "ozCalDay.jsp", "selInputSmall"));
}
%>
</div>
<div id="views" style="display: none;">
<%=_p.get("display")%>:
<%
if ( _vCalShareView.size() > 0 )
out.println( CalendarShareView.renderViewByDropdown( _ahsPage, _vCalShareView, _req, "userview", "ozCalDay.jsp", "selInputSmall") );
else
out.println( "<a href=\"javascript:OZ_openBrWin3('ozCalLOVUserSel.jsp', 'calUserPopup');\">"+AhsStringUtil.limitLength( sCalDispUsers, 48 )+"</a>" );
%>
</div>
</td>
<input type="hidden" name="userview" value="<%=userview%>" >


JS method for changing 1st dropdown values.


function changeDropDown(which) {
if (which == "views") {
document.getElementById('views').style.display = "";
document.getElementById('users').style.display = "none";
}
else {
document.getElementById('views').style.display = "none";
document.getElementById('users').style.display = "";
}
}

adusumalli
Jul 10th, 2009, 06:09 AM
Hi, In the onLoad I wrote following logice Now it's works fine.


function setComboValue() {
document.getElementById('userview').value = "<%=userview%>";
alert('alert value1>>'+document.getElementById('userview').value);
if (document.getElementById('userview').value == "views")
{
document.getElementById('views').style.display = "";
document.getElementById('users').style.display = "none";
}
else
{
document.getElementById('views').style.display = "none";
document.getElementById('users').style.display = "";
}
}

little bit problem is : by default 'users' displaying based on 'users' values are displaying in 2nd dropdown. when i change to 'views' in 1st dropdown, based on 'views' 2nd dropdown values are displaying and works good. Again when i try to change the 1st dropdown to 'users' it is changing but the 2nd dropdown values are not displaying.
In this case req.getparameter not getting 'users' bcoz here page is not reloading. so what's the solutions to this.

adusumalli
Jul 10th, 2009, 06:01 PM
Here, I observed html code using firebug in mozilla, 3 scenario's happening.
1) By default 1st time 'users' is selected in 1st dropdown, the html code is displaying like this :


<td>
<div id = "users" style=""> // this is heilighted bcoz by default 'users' is selected
2nd dropdown values based on users
blah blah ...
</div>
<div id="views" style="display:none;"> // this is deheilighted bcoz already 'users' is there in 1st dropdown.
2nd dropdown values based on views
blah blah ..
</div>
</td>
<input type="hidden" name="userview" value="<%=userview%>"> // here is userview is 'users'

2) when i change to 'views' in 1st dropdown, the html code is displaying like this :here the page is not yet reload we change the 1st dropdown value based on that 2nd dropdown values will be changing


<td>
<div id = "users" style="display:none"> // this is deheilighted bcoz this time 'views' is selected, which is okay.
2nd dropdown values based on users
blah blah ...
</div>
<div id="views" style=""> // this is heilighted bcoz 'views' is there in 1st dropdown.
2nd dropdown values based on views
blah blah ..
</div>
</td>
<input type="hidden" name="userview" value="<%=userview%>"> // here is userview is 'users' which is okay.

3) when i change 2nd dropdown values on 'views'( in 1st dropdown), the html code is displaying like this :here the page is reloading and missing the 2nd dropdown values of 'users'


<td>
<div id = "users" style="display:none"> // this is deheilighted bcoz this time 'views' is selected, which is okay.
by_user: // here 2nd dropdown values of 'users' not showing, it suppose to show.
</div>
<div id="views" style=""> // this is heilighted bcoz 'views' is there in 1st dropdown.
2nd dropdown values based on views
blah blah ..
</div>
</td>
<input type="hidden" name="userview" value="<%=userview%>"> // here is userview is 'views' which is okay.


In 3rd scenario, when i change 2nd dropdown values of 'views' , 2nd dropdown values of 'users' not showing in html <div> tag.

ckeyrouz
Jul 10th, 2009, 06:35 PM
Your problem lies here in this code:
if ( _req.getParam("userview").equals("users"))
{
if (_vUsers.size() > 0) out.println( UserUtil.renderUserByDropdown( _ahsPage, _vUsers, _req, "userview", "ozCalDay.jsp", "selInputSmall"));
}

you have selected views and changed in the second combo box so you submitted the form and the parameter userview has arrived to the servlet as views and you have set the following condition:

if ( _req.getParam("userview").equals("users"))
{
if (_vUsers.size() > 0) out.println( UserUtil.renderUserByDropdown( _ahsPage, _vUsers, _req, "userview", "ozCalDay.jsp", "selInputSmall"));
}
so the compiler won't enter inside it because the if statement is false.

When you change back your first drop down list you are only hiding and showing the div not retrieving the data, what you should do is to remove this if:

if ( _req.getParam("userview").equals("users"))

adusumalli
Jul 10th, 2009, 10:23 PM
hi I changed my logic and remove the if condition. Now it works great. Thanks a lot . Now i finished with this pending task.

ckeyrouz
Jul 10th, 2009, 10:28 PM
Glad to hear so.
And I apologize if it took me a while to help you with it but the code is not in front of me and I cannot debug it in a quick mode.

adusumalli
Jul 10th, 2009, 10:52 PM
You helped a lot. I understand in the forums this much help is more helpfull to resolve the problems.

adusumalli
Jul 23rd, 2009, 05:38 PM
Hi, in this Issue one more thing needs to work. first time in 1st dropdown 'Users' is selected and in 2nd dropdown 'Users' related values displaying. In 2nd dropdown by default 'loginUser' value displaying by default, which is correct. When i choose 'views' in 1st dropdown, 'views' related values are displaying in 2nd dropdown. based on 2nd dropdown value selection the data will be displayed in table. Upto this is correct.

When i again choose 'users' in 1st dropdown the 2nd dropdown selected value is taking as 1st value in 2nd dropdown which is not correct. It suppose to taking 'loginUser' value.
Can you suggest what i need to change in onChange() ?

ckeyrouz
Jul 23rd, 2009, 05:42 PM
By default when you populate a new drop down list it will take by default the first option in the list unless you specify otherwise.

In your case if you are submitting the form and then re-selecting the first combo, you are resetting the values in the combo.

if this is the case then in the onchange of the first combo you have to set a default value in the second.

adusumalli
Jul 23rd, 2009, 06:07 PM
if this is the case then in the onchange of the first combo you have to set a default value in the second.

Here is my dropdown code. 2nd dropdown is in <div> tag.



<td class=verySmall align='right' valign=top>
<table><tr>
<td class=verySmall>
<select name=userview id=userview class="selInputSmall" onChange="changeDropDown(this.value)">
<option value="users" ><%=_prompt.get("by_user")%></option>
<option value="views" ><%=_prompt.get("by_custom_view")%></option>
</select>
</td>
<td class=verySmall>
<div id="users" style="display: block;">

<%
if (_vUsers != null)
out.println( UserUtil.renderUserByDropdown( _ahsPage, _vUsers, _req, "userview", "ozCalDay.jsp", "selInputSmall", _ahsPage.getLoginUserID()));
%>
</div> 2nd dropdown of 'users'
<div id="views" style="display: none;">

<%
if ( _vCalShareView.size() > 0 ) out.println( CalendarShareView.renderViewByDropdown( _ahsPage, _vCalShareView, _req, "userview", "ozCalDay.jsp", "selInputSmall") );
else out.println( "<a href=\"javascript:OZ_openBrWin3('ozCalLOVUserSel.jsp', 'calUserPopup');\">"+AhsStringUtil.limitLength( sCalDispUsers, 48 )+"</a>" );
%>
</div>
</td></tr></table>
</td>


2nd dropdown values in Javafile calling from 'UserUtil.renderUserByDropdown from above <div> tag



public static String renderUserByDropdown ( AhsPageWebBean ahsPage, Vector vUsers, AhsRequest _req, String userview, String jumpUrl, String className, int UserID )
{
OzPromptStd _prompt = new OzPromptStd( ahsPage );
//Vector vEntries = getEntries( ahsPage );
StringBuffer buf = new StringBuffer();

// WP is with Param
String jumpUrlWP = jumpUrl+"?";
for (Enumeration e=_req.getRequest().getParameterNames(); e.hasMoreElements(); )
{
String paramName = (String) e.nextElement();
if ( paramName == null || paramName.equals("") || paramName.equals("csvid") || paramName.equals("userview"))
continue;
String paramVal = _req.getParam( paramName );
if ( paramVal == null || paramVal.equals("") )
continue;

jumpUrlWP += paramName + "=" + paramVal + "&";
}

buf.append( "<select name=\"calShareViewNA\" class=\""+className+"\" onChange=\"MM_jumpMenu3('parent',this, document.getElementById('userview'))\">" );
for (int i=0; i<vUsers.size(); i++)
{
FwkUserEO users = (FwkUserEO) vUsers.get(i);
buf.append( " <option value=\""+jumpUrlWP+"csvid="+users.getID()+"\" " );
if ( _req.getInt("csvid",-1) == users.getID() )
buf.append( "selected" );
if ( _req.getInt("csvid",-1) == -1 )
{
if (users.getID() == UserID )
buf.append( "selected" );
}
buf.append( "> " + users.getName() );
}
buf.append( "</select>" );
return buf.toString();
}


As you said I set the following way in 1st dropdown onChange.


function changeDropDown(selObj) {
if (selObj == "views") {
document.getElementById('views').style.display = "";
document.getElementById('users').style.display = "none";
}
else {
document.getElementById('views').style.display = "none";
document.getElementById('users').style.display = "";
}
if (document.getElementById('userview').value == "users")
document.getElementById('calShareViewNA').value = "<%=_ahsPage.getLoginUserID()%>"; here i set . Actually here the login user value is showing in js debug. but not dispalying in output. May be the value is not set to 2nd dropdown.


so what i need to chage in above logic ?

ckeyrouz
Jul 23rd, 2009, 07:01 PM
you should replace this :

if (document.getElementById('userview').value == "users")
document.getElementById('calShareViewNA').value = "<%=_ahsPage.getLoginUserID()%>";
with this:

if (document.getElementById('userview').options[document.getElementById('userview').selectedIndex].value == "users")
{

setComboValue(document.getElementById('calShareViewNA'),"<%=_ahsPage.getLoginUserID()%>");

And you should add the following method:



function setComboValue(zObj, zValue)
{
for(var i=0; i<zObj.options.length; i++)
{
if(zObj.options[i].value == zValue)
{
zObj.options[i].selected = true;
break;
}
}
}

adusumalli
Jul 23rd, 2009, 08:26 PM
hi here I am getting as 'null' in 'zObj' from this method
function setComboValue1(zObj, zValue)

for 'zValue' it is passing loginUserID. but for 'zObj' it is passing 'null'

ckeyrouz
Jul 23rd, 2009, 08:35 PM
OK this is because you do not have the id attribute in the select.
So change this :

buf.append( "<select name=\"calShareViewNA\" class=\""+className+"\" onChange=\"MM_jumpMenu3('parent',this, document.getElementById('userview'))\">" );


to this:

buf.append( "<select name=\"calShareViewNA\" id=\"calShareViewNA\" class=\""+className+"\" onChange=\"MM_jumpMenu3('parent',this, document.getElementById('userview'))\">" );

adusumalli
Jul 23rd, 2009, 08:56 PM
hi , it is getting the values into 'zObj' but in this condition if(zObj.options[i].value == zValue) , the zObj.options[i].value is "ozCalDay.jsp?csvid=43" . but the 'zValue' is only '43' . bcoz, if u see in the following Java logic the option value is url+csvid(which is the id of 2nd dropdown)



buf.append( " <option value=\""+jumpUrlWP+"csvid="+users.getID()+"\" " );


so how do we get zObj.options[i].value is only csvid('43') ??

ckeyrouz
Jul 23rd, 2009, 09:09 PM
Sorry for that, did not pay attention to the full value of the option:
Change this:


function setComboValue(zObj, zValue)
{
for(var i=0; i<zObj.options.length; i++)
{
if(zObj.options[i].value == zValue)
{
zObj.options[i].selected = true;
break;
}
}
}

to this:



function setComboValue(zObj, zValue)
{
for(var i=0; i<zObj.options.length; i++)
{
var optVal = zObj.options[i].value;
optVal = optVal.substring(optVal.indexOf("csvid="))
if(optVal == zValue)
{
zObj.options[i].selected = true;
break;
}
}
}

adusumalli
Jul 23rd, 2009, 09:28 PM
From this statement optVal = optVal.substring(optVal.indexOf("csvid=")),
I am getting in optVal = "csvid=43" instead of only '43'.

ckeyrouz
Jul 23rd, 2009, 09:37 PM
Sorry working here and the forum at the same time.
I apologize for the mistake:

replace this:

optVal = optVal.substring(optVal.indexOf("csvid="))


with this:

optVal = optVal.substring(optVal.indexOf("csvid=")+6)

adusumalli
Jul 23rd, 2009, 10:05 PM
Hi Thanks it works fine. and in the 2nd dropdown it is showing login user.
But here I want to reload the page. becoz, when i am going 2 change the 1st dropdown value as 'users' the 2nd dropdown value is changed to 'loginuser(43)' which is okay. based on these two values the table needs to update. means it should reload the page. how it happens from this javascript ?

earlier used like:


function MM_jumpMenu3(targ,selObj,uvalue,restore)
{
var s = selObj.options[selObj.selectedIndex].value;
var u = uvalue.options[uvalue.selectedIndex].value;
if ( s.substring(0,1) != '_' && u.substring(0,1) != '_' )
{
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"&userview="+uvalue.options[uvalue.selectedIndex].value+"'");
}
else
{
s = s.substring(1, s.length);
eval( s );
}
}


like in eval i need to call ozCalDay.jsp here.

ckeyrouz
Jul 23rd, 2009, 10:34 PM
You can reload your file at any time by using this javascript code:



document.location.reload();

adusumalli
Jul 23rd, 2009, 11:28 PM
HI Thanks for your time. Now it's working in all senario's.

Hey Can you suggest which is the best practice for JavaScript in theory and Examples.

ckeyrouz
Jul 23rd, 2009, 11:32 PM
Go to this url:

http://www.w3schools.com/js/default.asp

in fact the site http://www.w3schools.com contains everything that you need to know for web.

I strongly recommend to keep it in your bookmarks and visit it from time to time, I think it is a wealth of information, not to mention that you can get certification through this site.

Hope it will help you.