/    Sign up×
Community /Pin to ProfileBookmark

activating function

Hello, I’m pretty new to javascript and I was wondering how to activate a certain function based on what I have selected in a drop down menu. I’m trying to make a page that will have a drop down menu of catagories to choose from, then a search box, then a go button. When you select a catagory, it will activate a certain function that will search in that catagory for what you typed. So far, I have everything except a way to select the function.
Thanks,
Vogonpoet

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JPnycMar 01.2005 — Search what? The page? A database? A function is "activated" by an event. Most often, a user triggered event. These are called "event handlers". If you want a button, as you said, then the event handler is onclick="functionName()", which would go inside the HTML tag for that button. Well it can go other places too, but we'll start with that.
Copy linkTweet thisAlerts:
@vogonpoetauthorMar 01.2005 — I'm trying to make an "enhanced" Google search page, mostly out of laziness and to try making something besides things in tutorials. I am trying to have a menu that will add either "filetype:", "site:", etc to the front of the query. So far, this is what I have:

<script>

function filetype(){

var name = document.query.q.value

endValue = ("filetype:" +name)
document.query.q.value = endValue
document.query.submit();
}


function site(){

var name = document.query.q.value

endValue = ("site:" +name)
document.query.q.value = endValue
document.query.submit();
}

</script>

</head>

<body>

<form name="query" method="get" target="_blank"

action="http://www.google.com/search">

<input type="text" name="q" size="12">

<select>

<option>--------------------</option>

<option>Search for file type</option>

<option>Search in site</option>

</select>

<input type="button" value="find" onClick="selection()">

<input type="reset" value="reset" name="B2">

</form>

The "selection()" will hopefully be where the menu selection will add "filetype:" or others to the beginning. I'm just not sure if there is an "onSelect" event handler for the menu or where to put it.

Thanks again,

Vogonpoet
Copy linkTweet thisAlerts:
@JPnycMar 01.2005 — Yes, the onselect is an event of the select box (the drop down). But then you don't need a button. As soon as they select, that's it.
Copy linkTweet thisAlerts:
@ArsenalMar 01.2005 — Please note that getElementById is alot better than form_name.object_name
Copy linkTweet thisAlerts:
@vogonpoetauthorMar 01.2005 — Thank you very much for the help, JPnyc and Arsenal! Your advice really helped me get the page to work.
×

Success!

Help @vogonpoet spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...