Closed Thread Icon

Topic awaiting preservation: Drop down box and JavaScript (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8767" title="Pages that link to Topic awaiting preservation: Drop down box and JavaScript (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Drop down box and JavaScript <span class="small">(Page 1 of 1)</span>\

 
Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 07-21-2003 23:44

Hi, guys. How are you?
Well, could I ask you this, please?
I did exercise called Select-and-Go Navigation yesterday.
The script came from here.
It seemed working fine. But my text book said:

code:
<html>
<head>
<title>Select-and-Go Navigation</title>

<script type="text/javascript">
<!--

function jumpPage(newLoc){

newPage = newLoc.options[newLoc.selectedIndex].value;

if(newPage != ""){

window.location = newPage;

}

}


-->
</script>

</head>

<body onLoad = "document.myForm.newLocation.selectedIndex=0">

<form name="myForm">

<select name="newLocation" onChange = "jumpPage(this.form.newLocation)">

<option value="" selected>Select a topic</option>
<option value="a.htm">Selecting menu items</option>
<option value="b.htm">Working with radio buttons</option>
<option value="c.htm">Setting one field with another</option>
<option value="d.htm">Validating Zip codes</option>
<option value="e.htm">Validating email addresses</option>

</select>

</form>
</body>
</html>



And here is my only html version:

code:
<html>
<head>
<title>Select-and-Go Navigation</title>



</head>

<body >

<form name="myForm">

<select >

<option value="" selected>Select a topic</option>
<option value="a.htm">Selecting menu items</option>
<option value="b.htm">Working with radio buttons</option>
<option value="c.htm">Setting one field with another</option>
<option value="d.htm">Validating Zip codes</option>
<option value="e.htm">Validating email addresses</option>

</select>

<input type="submit" value="Go there!">

</form>
</body>
</html>



This button doesn't work at all. Why????
Many thanks for reading this.
Looking forward to hearing from you.
Cya.

Hiroki Kozai

[This message has been edited by Hiroki (edited 07-22-2003).]

Blaise
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2003

posted posted 07-22-2003 01:54

Well you don't have the javascript on your page.

The javascript takes teh value of the drop down box and directs the browser to that location.

Your page just has a form a drop down box and a submit button, it doesn't know what to do with it though, you need scripting to tell it what to do.

Hope this helps, let me knoe if you want more.

Blaise.

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 07-22-2003 02:02

Hi, Blaise!
How are you?
Many thanks for your reply.
And I am really glad to hear your kind offer.
Well, can I ask you further more, please?
What I am wondering is:

Do I have to use JavaScript when I make drop-down-box work?

I mean I can make just dropdown box and submit button. But if I want to make them functional, do I have to put JavaScript between those components???

Looking forward to hearing from you.
Regards,

Hiroki Kozai

Blaise
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2003

posted posted 07-22-2003 02:48

The short answer is yes.

This is how I see it...

You want your drop down box to allow the user to select a different page,
When a user submits the form the new page is loaded.

Now javascript is an event driven language (things happen at certain instances) and there are more than one events happening in your example.

When an event happens you can use javascript to 'capture' the event and act accordingly to how you've scripted.

The first event is that the user is selecting a page, this is captured using the onChange event in the Select tag. eg: <select name="mySelectBox" onChange="myFunction()">

The second event is when the user clicks the submit button, this is captured using the onClick event on the Input tag. eg: <input type="submit" onClick="myFunction()">

the third event is the form being submitted, this automatically happens whenever a submit button is clicked, this can be captured by the onSubmit event in the form tag. eg: <form name="form1" onSubmit="myFunction()">

You can't use the onSubmit event on a drop down box because the drop down box doesn't get submitted, it's actually the form that this is happening to, there are many examples of this in javascript and the best way to find them is by trial and error.

Now myFunction is the name of the function you want to run when the event happens, you would need some Script code in your html page that performs when this function is called, as with your first example.

I won't tell you the answer just yet, I'll see if that helps, it'll be better for you if you can work it out yourself, but if you need more help then just as one more time. no problem

Cheers,

Blaise

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 07-22-2003 05:48

So in concludion:

HTML dropdown is just useless itself. It must go with some JavaScript to make things happen.And I have to chose even handler depending on what kind of html stuff I deal with.

Have I got it? I guess so.
Many many thanks, mate.
Have a good evenig.
Cya.

Hiroki Kozai

Blaise
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2003

posted posted 07-23-2003 00:43

yep that's pretty much it right.

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 07-23-2003 01:20

Hi, Blaise.
Good morning. How are you today?
Well, I wonder if you get morning there or not.
It is just about lunch time here in New Zealand.
I am going to share my cookies with my friend.
In New Zealand we have great cookies.
It will be good idea to share them.
Do you like one???
Many thanks.
Cya.

Regards,

Hiroki Kozai

« BackwardsOnwards »

Show Forum Drop Down Menu