Solved

Text Heading based on contents of Option dropdown

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Issue configuring a dropdown selector on a donation form. 13 68
Lines Not Lining Up 2 62
Swiper slider stops between pages 11 45
Stupid git question 2 57
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

930 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

11 Experts available now in Live!

Get 1:1 Help Now