473,326 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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="searchType">
<option SELECTED>books</option>
<option>photos</option>
</select>

and in the second we have: <select name="searchType">
<option>books</option>
<option SELECTED>photos</option>
</select>
Jul 23 '05 #1
1 1465
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.html?type=books">Search our books</a>
<a href="library.html?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.selectedIndex = 1;
type.options[ 1 ].defaultSelected = true;
else if( -1 != location.search.indexOf( 'type=books' )) {
type.selectedIndex = 0;
type.options[ 0 ].defaultSelected = true;
}

Assuming the HTML you presented in your original post.

Hope that helps,
Mike

--
Michael Winter
M.******@blueyonder.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
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...
5
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...
10
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...
5
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...
2
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...
3
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...
19
by: Taras_96 | last post by:
Hi everyone, How do you detect that a form element has been changed? This thread: ...
1
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...
21
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.