Solved

Text Heading based on contents of Option dropdown

Posted on 2006-06-22
5
189 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

680 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