473,836 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onChange of listbox to update link?

I have a PHP page that generates a list box with several options in it.

I would like to have a "view" link next to the list box. When the user
changes the contents of the list box, I would like the view link to
update to point to the image representing that selection. So for
example, if the list box held names of images I would want the view link
to always point at the correct image.

To further complicate this matter, the selections of the listbox are in
PHP variables.

I basically have little to no experience with javascript and could use
some guidance in figuring this out.

Thanks.

Jason
jl*****@NoSpamA ustin.rr.com
Jul 23 '05 #1
1 9719
John Doe wrote:
I have a PHP page that generates a list box with several options in it.

I would like to have a "view" link next to the list box. When the user
changes the contents of the list box, I would like the view link to
update to point to the image representing that selection. So for
example, if the list box held names of images I would want the view link
to always point at the correct image.
You just need to change the href of the link behind the 'view'
button/link.

To further complicate this matter, the selections of the listbox are in
PHP variables.
Browsers do not understand PHP. You must write HTML so that the
JavaScript can use the values. You could put the link values
into the document in a meta tag, or as an array in a script
element, but I think using the value attribute of an option is
better.

I basically have little to no experience with javascript and could use
some guidance in figuring this out.


Here is a script that offers two solutions - the first I think
is better. If the user has JavaScript enabled, they click the
'View' button and are taken to the new location (image,
whatever). If not, the selected URL is passed to the server,
where you can return the new link and send them to the new link
anyway.

The second is more what you have asked for, but if JS is not
enabled, then the link should by default go somewhere that
explains why the link doesn't work.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Select </title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<script type="text/javascript">

function gotoLink(s){
var newLink = s[s.selectedIndex].value;

// If no selection made
if (newLink == '') {
alert("Please select a destination");
return false;
}

// If a selection has been made, go there
document.locati on = newLink;
}

function updateLink(s,p) {
var a;
if (document.getEl ementById){
a = document.getEle mentById(p);
} else if (document.all){
a = document.all[p];
}

// Update the link based on selection
a.href = s[s.selectedIndex].value;
a.innerHTML = s[s.selectedIndex].text;
}

</script>
</head>
<body>
<!-- uses a form. If JS enabled, takes user to link
when 'view' button clicked. If JS not enabled,
form submitted to server, can handle new link there.
-->
<form action="" onsubmit="
gotoLink(this.l inkSelect);
return false; // If JS enabled, stops form submission;
">
<table>
<tr><td>
<select name="linkSelec t">
<option value="" selected>Pick a destination</option>
<option value="http://www.google.com" >Google</option>
<option value="http://www.yahoo.com"> Yahoo</option>
</select>
</td><td>
<input type="submit" value="View">
</td></tr>
</table>
</form>

<!-- Changes the href of 'view' link onchange. Does not use
a form
-->
<table><tr><t d>
<select onchange="updat eLink(this,'pic Link');">
<option value="" selected>Pick a destination</option>
<option value="http://www.google.com" >Google</option>
<option value="http://www.yahoo.com"> Yahoo</option>
</select>
</td><td>
<a id="picLink"
href="enableJS. html">Select a destination</a><br>
</td></tr>
</table>
</body>
</html>


--
Rob
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5763
by: Lee Mundie | last post by:
Hi there, Simple problem here but can't seem to fix it! Okay, I have a select list from which people choose avatars... the list is option values ie. <option>Worm</option> <option>Frog</option> etc etc and is in an include file... where the word i.e. worm sources the image ..images/worm.gif - simple so far...
3
1639
by: NewmanBT | last post by:
As you can see from the code below, several textboxes will be dynamically created and each will be tied to an org. The ChangeComment function should allow for an update to the database whenever the value of the associated textbox changes. However, I'm having trouble associating the textbox to the org. strOrg is a global variable which changes throughout the runtime. How do I capture its value at each stage a textbox is created so that...
2
3334
by: Alpha | last post by:
How do I change the selected item in a listbox according to a Combox's selected item on the same form? The Combox is from a different table in the same dataset as the Listbox uses. Combox's ValueMember is a ID that is a column in the table that the listbox uses. Is there a way to link these 2's relation so that when the user changes the selection in the Combox the list box would automacticall changes to reflect the items that's linked to...
3
8174
by: James Radke | last post by:
Hello, I was curious, is it possible to create drag and drop interface from listbox to listbox on a webform application (i.e. vb.net)? Basically the application would need to load multiple listboxes with values from a database, allow the user to drag and drop from a listbox to a different listbox and would 'move' the item and update the database accordingly? If so, would anyone have any examples of how to do this?
6
9992
by: Mark | last post by:
Hello. I have a listbox whose rowsource is set to a saved query (call it "qry_customer_list.") When I add customers to my database, I call the listbox Requery method so that the listbox will display the customers that I added. Unfortunately, the listbox display does not change. If I close the form and reload it, then the listbox will show the new customers. Any suggestions on how to fix this?
3
4303
by: Kevin Walzer | last post by:
I'm trying to set the active item in a Tkinter listbox to my application's currently-defined default font. Here's how I get the fonts loaded into the listbox: self.fonts=list(tkFont.families()) self.fonts.sort() for item in self.fonts: self.fontlist.insert(END, item) #self.fontlist is the
1
10957
by: sklett | last post by:
I've setup the simplest of tests; A form with a ListBox and a Button. The ListBox is bound to a List<string>. When you click the Button, a new string is added to the list. I can't for the life of me get the ListBox to update when new items are added to it's DataSource! <code> List<stringdateTimeStringList = new List<string>(); private void button1_Click(object sender, EventArgs e) {
3
2493
by: deejayquai | last post by:
Hello Simple one this I guess, but I'm quite stuck at the moment. I would like to update the records displayed in my listbox (lstStudents) using criteria selected from my combo (cboForm) in a form. My basic code is:
0
9825
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9671
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10596
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9382
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6980
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4459
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4021
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.