Solved

Text Heading based on contents of Option dropdown

Posted on 2006-06-22
5
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

615 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