473,800 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

opening a form with a different option selected other than the default

Anyone know how to do this with javascript? I'm trying to avoid
creating two different forms because then changes become that much
harder to manage. Thanks in advance . . .
~ Jon LaRosa
jlarosa at alumni dot brown dot edu

I would like to create 2 links to a form that do the following:

A) one link would open the form with one option of a drop down list
selected
B) the other link would open the same form with a different option of
a drop down list selected

for example, the links:
Click here to search our books
Click here to search our photos

Both links open a search form, library.html, but in one case "books"
is the automatically selected search type and in the other case
"photos" is automatically selected.

I.E. in the first case, we have: <select name="searchTyp e">
<option SELECTED>books</option>
<option>photo s</option>
</select>

and in the second we have: <select name="searchTyp e">
<option>books </option>
<option SELECTED>photos </option>
</select>
Jul 23 '05 #1
1 1485
On 7 Apr 2004 12:03:48 -0700, Jonathan LaRosa <jl*****@alumni .brown.edu>
wrote:
Anyone know how to do this with javascript? I'm trying to avoid
creating two different forms because then changes become that much
harder to manage. Thanks in advance . . .
~ Jon LaRosa
jlarosa at alumni dot brown dot edu

I would like to create 2 links to a form that do the following:

A) one link would open the form with one option of a drop down list
selected
B) the other link would open the same form with a different option of
a drop down list selected


[snip]

It would be best to use server-side support to dynamically write the
selected attribute to the appropriate option element. You could specify
the one to select through the search (query) part of the URI:

<a href="library.h tml?type=books" >Search our books</a>
<a href="library.h tml?type=photos ">Search our photos</a>

If server-side support is not available, you could add this below the form
on the library.html page:

var form = document.forms[ 'formName' ],
type = form.elements[ 'searchType' ];

if( -1 != location.search .indexOf( 'type=photos' )) {
type.selectedIn dex = 1;
type.options[ 1 ].defaultSelecte d = true;
else if( -1 != location.search .indexOf( 'type=books' )) {
type.selectedIn dex = 0;
type.options[ 0 ].defaultSelecte d = true;
}

Assuming the HTML you presented in your original post.

Hope that helps,
Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2

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

Similar topics

10
2883
by: Andres Eduardo Hernando | last post by:
Hi, I'm not entirely sure this is the right group to ask this question, but I saw a similar one above, and the group's charter is not clear enough about it, so, here I go: ;) What is the standard behavior (if any) when the same name is attached to more than one field in a <form>? An example (that closely resembles the problem I'm working on) will be (this is a standard radio group without a default selected option): <form ...> <input...
5
5879
by: Raffi | last post by:
Hi folks, I'm new to JavaScript and need some help. I have a form with a select field. Depending on what is selected in this field, I want to display or not display another select field. For example first field asks the user if they drive, if the user selects "NO" the form doesn't change. If they select "YES", another field appears with different makes to chose from. If they change back to "NO" the second field dissapears again.
10
2850
by: Doug O'Leary | last post by:
Hey, all. I have a perl script which generates the html listed below. I cleaned it up a bit since the perl CGI module creates some really ugly html code. I've looked at this thing 8 ways to Sunday, but I can't see anything wrong. When I hit the "Add" button, it immediately executes the action of the form skipping the validate_form function completely. I've tried the script section towards the top of the html as well as just before...
5
1886
by: cmc_dermo | last post by:
I have a form that has a select list. A user chooses a value and the page refreshes showing the selected value in the dropdown box. So I want to use Javascript to get the selected query from the form. I then want to pass it as a hidden field. So for example the section of the page I'm interested in will look like
2
3495
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button "No", he should not have the option of clicking on any of the six checkboxes. See Code attached. Thank you so much in advance for your help as I can't get to make this combo work. <p>Did you have any problems finding any of the information...
3
2342
by: Bill | last post by:
I'm using the POST method to submit a simple form html page with yes/no and checkbox fields to an asp response page which stores the values in a new dim string, then uses it to build a new table using ADO. I'm getting sometimes correct values, sometimes null values (when I know I pass a valid default value) and other times multiple values! I know what the values coming over are because I do a response.write to see it before the error...
19
8297
by: Taras_96 | last post by:
Hi everyone, How do you detect that a form element has been changed? This thread: http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/9ae1c9d419264380/125a82c9be127790?lnk=st&q=checking+html+form++(updated+OR+edited+OR+changed)&rnum=28&hl=en#125a82c9be127790 suggests that you attach onChange event handlers to every form element, and when the handler fires you update a global 'isChanged' variable. This technique...
1
1471
by: paintedjazz | last post by:
I am using the following javascript to make a popup menu allow the user to navigate to different pages on a website. Yet it is opening windows as if I have <base target="some-name"> defined in the body. <script language=javascript> <!-- Begin function navigate() { open(document.popupForm.popup.options
21
6577
jinalpatel
by: jinalpatel | last post by:
I have three option buttons (1 option group): construction projects, non construction projects and aquisition projects. I have created a form with more than 35 data entry fields for each of this options.ex.frmConstructionProjects,frmNonconstructionProj, frmAquisitionProjects When user selects an option fromm the options group it should open the respective subform. Private Sub optProject_Click() If Me.optProject.Value = 1 Then...
0
9695
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
10287
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
10260
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
10042
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9099
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
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4156
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
3770
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2956
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.