Solved

Text Heading based on contents of Option dropdown

Posted on 2006-06-22
5
185 Views
Last Modified: 2010-04-06
Hi,

I'll simplify the problem I'm having to it's barest bones - hope it makes sense.

I have a form on which there is a "search text"  text box and a "search by" dropdown list.  Lets assume that this list only has two values :

  <select name="select">
    <option value="INT">Option A</option>
    <option value="NAM">Option B</option>
  </select>

However, the users can come to this form by two means.  Depending on which method they used to get here a different option value will be selected.

For instance if they had followed linka it would look like :

  <select name="select">
    <option value="INT" selected>Option A</option>
    <option value="NAM">Option B</option>
  </select>

if they had followed linkb it would look like

  <select name="select">
    <option value="INT">Option A</option>
    <option value="NAM" selected>Option B</option>
  </select>

How, using HTML or java can I add a line of text on the page which is linked to the selected option.  eg.  If I wanted to display :

"You have arrived here from linka"

or

"You have arrived here from linkb"

Hopefully that makes sense!
0
Comment
Question by:JoHarris
  • 3
5 Comments
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 16962364
you just need to get the context path and print accordingly...

Pseudo Code: (JSP)

String str = request.getContextPath();
<%
if(str="lina")
out.write(You have arrived here from linka);
else
out.write(You have arrived here from linkb);
%>


____Jags.
0
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 16962379
Or else simply you can just pass simple hidden variable and do a simple if condition on that...

____Jags.
0
 
LVL 30

Accepted Solution

by:
callrs earned 500 total points
ID: 16963156
<html>
<!-- FORM: SUBMIT & EXTRACT FORM DATA   - DEMO        -->
<!-- Save the form as "c:\temp\p9.htm" & Then run it -->

<!-- By EE member www.experts-exchange.com/M_876428.html  
     with parse code from www.eggheadcafe.com/articles/20020107.asp "Parsing The Querystring with Javascript -->

<script type='text/javascript'>

 // Parse the query string (part after "?" in the URL)
function parseQ(q) {
      if(q.length > 1) this.q = q.substring(1, q.length);
      else this.q = null;
      this.keyValuePairs = new Array();
      if(q) {      for(var i=0; i < this.q.split("&").length; i++) {      this.keyValuePairs[i] = this.q.split("&")[i];      }      }
this.getKeyValuePairs = function() { return this.keyValuePairs; }

 // Retrieve a value for a key
this.getValue = function(s){
      for(var j=0; j < this.keyValuePairs.length; j++) {
            if(this.keyValuePairs[j].split("=")[0] == s)
                  return this.keyValuePairs[j].split("=")[1];
            }
      return false;
      }

 // Optional code - Array of all parameters
this.getParameters = function() {
      var a = new Array(this.getLength());
      for(var j=0; j < this.keyValuePairs.length; j++) {
            a[j] = this.keyValuePairs[j].split("=")[0];
            }
      return a;
      }
this.getLength = function() { return this.keyValuePairs.length; }

}
 // Query string for value
function qS(key){return unescape(page.getValue(key));}

function onLoadF(){
      page = new parseQ(window.location.search);
      displayWelcome();
      }

function displayWelcome(){
      var w1_=qS('w1');
      var w2_=qS('w2');
      var V_=qS('select');
      if(V_!='false'){
            if(V_=="INT") out_="You have arrived from link A";
            else if(V_=="NAM") out_="You have arrived from link B";
            else out_="Unknown: "+V_;
            }
      else
            {return false;}
      document.write(out_);
      if(w1_!='false') document.write("<BR>Your first word:  "+w1_)
      if(w2_!='false') document.write("<BR>Your second word: "+w2_)
      }

</script>
<body onload='onLoadF();');">

<!-- FORM below can/should appear on separate page, which would submit to this page to parse the FORM data.
     This form is here instead just for a simpler demo -->

<FORM action="p9.htm" name=f>
Word 1 <input name='w1'>
<P>
Word 2 <input name='w2'>
<input type=submit Value="Go!">
<select name="select">
    <option value="INT" selected>Option A</option>
    <option value="NAM">Option B</option>
  </select>
</FORM>

</body>
</html>
0
 

Author Comment

by:JoHarris
ID: 16976425
That's smashing thanks - the third reply was slightly more help in that I could see how it worked.  I'm sure your answer was great too jagadeesh but I'm just a bit simple for it!

The help is much appreciated!
0
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 16976472
:-)
Thank You,
___Jags.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Web Application Architecture 6 68
query of query sort 6 89
PHP email variable syntax 3 44
Adding a hidden div to each row in a table 6 25
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now