• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

JavaScript Conditional Operator(i.e., ?)

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 284
Netbeans IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"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.
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic