This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript Conditional Operator(i.e., ?) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JavaScript Conditional Operator(i.e., ?)" Watch "JavaScript Conditional Operator(i.e., ?)" New topic
Author

JavaScript Conditional Operator(i.e., ?)

Shyam Kasthala
Ranch Hand

Joined: Mar 30, 2006
Posts: 48
Hello,
Can any one tell me how to use conditional operator(?) in javascript in window.location.Can any one tell me what this means : -

window.location="project.jsp?module="+document.frm.module.options[document.frm.module.selectedIndex].text;

I have 4 combo boxes where the second and third combo box values depend on the first combo box value and third combo box value depend on the second.I am able to write the code for the first half but struggling to write for the second half.

function getpname()
{
window.location="project.jsp?pid="+document.frm.pid.options[document.frm.pid.selectedIndex].text;
}
The above code is running fine.
But there is some problem in the following code that i am unable to understand.

function getsname()
{window.location="project.jsp?module="+document.frm.module.options[document.frm.module.selectedIndex].text;
}
All the combo boxes are in the same jsp page.
Please tell me how to use the conditional operator(?) with window.location.
Please solve this.Thank you.


Thanks & Regards<br /> Shyam Kasthala<br />ILFS Infotech Limited
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Hello kasthala
Can any one tell me how to use conditional operator(?) in javascript in window.location.Can any one tell me what this means : -

window.location="project.jsp?module="+document.frm.module.options[document.frm.module.selectedIndex].text;

i am not sure if i understanding you.
In the previous statement there arent any condicional operator.
It's an URL.

Regards


SCJP, OCMJD, OCMJEA
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9924
    
158

"project.jsp?module="+document.frm.module.options[document.frm.module.selectedIndex].text;


The ? is not a conditional operator(i guess, you are confusing it with Java's conditional operator). Anything following the ? in the query string represents the parameter key-values that are being passed as part of the URL. In this case, a parameter with the name 'module' is being passed a value evaluated out of the expression document.frm.module.options[document.frm.module.selectedIndex].text.


[My Blog] [JavaRanch Journal]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60755
    
  65

Originally posted by jaikiran pai:

The ? is not a conditional operator


Yes, it is. Just not in this case because it's part of a string.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: JavaScript Conditional Operator(i.e., ?)
 
Similar Threads
call javascript function from external JS file
in dropdown problem
Servlets
value of the textbox to a scriplet in JSP
Script using array