473,400 Members | 2,145 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,400 software developers and data experts.

onclick Javascript Problem

Hello,

I have found myself in the position of having to manage & "hack" a web
site built by someone else. I am trying to make a modification to the
javascript code and have been unable to get this working. I admit that
I am a total javascript beginner, but have read google & purchased the
o'reilley javascript book. So far, all I've been able to achieve are
numerous javascript errors!

Currently, we have a drop-down box which triggers an "onchange" event.
I would like to reproduce some of this functionality with a simple
button or text link & therefore need to use the "onclick" event.

Current javascript for "onchange" looks like this:

function setExtent(obj){

var sExt=obj.value;

if(sExt==""){
return;
}

var x1,y1,x2,y2;
var s;

//get coordinates from string
var i = sExt.indexOf(",");

if(i>0) {
x1 = parseFloat(sExt.slice(0,i));
sExt = sExt.slice(i+1);
}

i = sExt.indexOf(",");

if(i>0) {
y1 = parseFloat(sExt.slice(0,i));
sExt = sExt.slice(i+1);
}

i = sExt.indexOf(",");

if(i>0) {
x2 = parseFloat(sExt.slice(0,i));
sExt = sExt.slice(i+1);
}

y2 = parseFloat(sExt);

// alert(x1+","+y1+","+x2+","+y2);

//get map
var map = top.mapwindow.document.mapApplet.getMap();

//get FloatRectangle object
var ext = map.getExtent();
//set Extent boound
ext.setBounds(x1,y1,x2,y2);
//change map extent
map.setExtent(ext, null);

//force repaint
map.updateMap();

}

The HTML for the drop down box looks like this:

<select name="theme" size=1 onChange="setExtent(this)">
<option value="10350350,3380230,10582000,3531280">Location </option>
</select>

So basically what happens is when someone selects that option from the
drop down list, they are taken to the coordinates on the map (per the
"value").

How can this be duplicated using a text link or button with
"onclick"??

Thanks a bunch for your help!
Jul 20 '05 #1
5 10745
"Jim Bond" <ma***************@yahoo.com> wrote in message
news:1b**************************@posting.google.c om...
Hello,

I have found myself in the position of having to manage & "hack" a web
site built by someone else. I am trying to make a modification to the
javascript code and have been unable to get this working. I admit that
I am a total javascript beginner, but have read google & purchased the
o'reilley javascript book. So far, all I've been able to achieve are
numerous javascript errors!

Currently, we have a drop-down box which triggers an "onchange" event.
I would like to reproduce some of this functionality with a simple
button or text link & therefore need to use the "onclick" event.

Current javascript for "onchange" looks like this:

function setExtent(obj){

var sExt=obj.value;

if(sExt==""){
return;
}

var x1,y1,x2,y2;
var s;

//get coordinates from string
var i = sExt.indexOf(",");

if(i>0) {
x1 = parseFloat(sExt.slice(0,i));
sExt = sExt.slice(i+1);
}

i = sExt.indexOf(",");

if(i>0) {
y1 = parseFloat(sExt.slice(0,i));
sExt = sExt.slice(i+1);
}

i = sExt.indexOf(",");

if(i>0) {
x2 = parseFloat(sExt.slice(0,i));
sExt = sExt.slice(i+1);
}

y2 = parseFloat(sExt);

// alert(x1+","+y1+","+x2+","+y2);

//get map
var map = top.mapwindow.document.mapApplet.getMap();

//get FloatRectangle object
var ext = map.getExtent();
//set Extent boound
ext.setBounds(x1,y1,x2,y2);
//change map extent
map.setExtent(ext, null);

//force repaint
map.updateMap();

}

The HTML for the drop down box looks like this:

<select name="theme" size=1 onChange="setExtent(this)">
<option value="10350350,3380230,10582000,3531280">Location </option>
</select>
So you pass reference to c

So basically what happens is when someone selects that option from the
drop down list, they are taken to the coordinates on the map (per the
"value").

How can this be duplicated using a text link or button with
"onclick"??

Thanks a bunch for your help!


<button onclick="setExtent(document.getElementById('theme' ))">Go!</button>
Jul 20 '05 #2
Won't work if scripting is disabled. You should always document.write
elements that are completely script-dependant (think about it.)
You need a submit button nested in a noscript tag to complete this solution
(as well as a little server-side code of course.)

| <button onclick="setExtent(document.getElementById('theme' ))">Go!</button>
|
|
Jul 20 '05 #3
"Vjekoslav Begovic" <vj*******@inet.hr> wrote in message news:<bj**********@sunce.iskon.hr>...
"Jim Bond" <ma***************@yahoo.com> wrote in message
news:1b**************************@posting.google.c om...
Hello,

I have found myself in the position of having to manage & "hack" a web
site built by someone else. I am trying to make a modification to the
javascript code and have been unable to get this working. I admit that
I am a total javascript beginner, but have read google & purchased the
o'reilley javascript book. So far, all I've been able to achieve are
numerous javascript errors!

Currently, we have a drop-down box which triggers an "onchange" event.
I would like to reproduce some of this functionality with a simple
button or text link & therefore need to use the "onclick" event.

Current javascript for "onchange" looks like this:

function setExtent(obj){

var sExt=obj.value;

if(sExt==""){
return;
}

var x1,y1,x2,y2;
var s;

//get coordinates from string
var i = sExt.indexOf(",");

if(i>0) {
x1 = parseFloat(sExt.slice(0,i));
sExt = sExt.slice(i+1);
}

i = sExt.indexOf(",");

if(i>0) {
y1 = parseFloat(sExt.slice(0,i));
sExt = sExt.slice(i+1);
}

i = sExt.indexOf(",");

if(i>0) {
x2 = parseFloat(sExt.slice(0,i));
sExt = sExt.slice(i+1);
}

y2 = parseFloat(sExt);

// alert(x1+","+y1+","+x2+","+y2);

//get map
var map = top.mapwindow.document.mapApplet.getMap();

//get FloatRectangle object
var ext = map.getExtent();
//set Extent boound
ext.setBounds(x1,y1,x2,y2);
//change map extent
map.setExtent(ext, null);

//force repaint
map.updateMap();

}

The HTML for the drop down box looks like this:

<select name="theme" size=1 onChange="setExtent(this)">
<option value="10350350,3380230,10582000,3531280">Location </option>
</select>


So you pass reference to c

So basically what happens is when someone selects that option from the
drop down list, they are taken to the coordinates on the map (per the
"value").

How can this be duplicated using a text link or button with
"onclick"??

Thanks a bunch for your help!


<button onclick="setExtent(document.getElementById('theme' ))">Go!</button>


Thank you for your reply!

I think what you're telling me how to do basically just creates a
submit button that works with the drop down box, right?

If so, that isn't what I want to do.

I currently have the drop down box & that works perfectly fine with
the javascript function shown above. What I'm trying to do is
duplicate that functionality with a simple text link or button. What
I want to do has nothing to do with a drop down box. I simply posted
that as an example of what I currently have.

So, to paraphrase:

Currently, I have a drop down box on the page. Someone can select an
option from this box & be taken to coordinates on a map (see above
javascript & html).

What I want to be able to do is create a text link on the page which
can be clicked & calls the coordinates on the map. That's it! When I
try to modify the javascript code to work with a text link & the
onclick event, I always end up with javascript errors (too numerous to
post here), so I'm obviously doing something wrong.

Thanks.
Jul 20 '05 #4
"Jim Bond" <ma***************@yahoo.com> wrote:
I think what you're telling me how to do basically just creates a
submit button that works with the drop down box, right?
Right.
If so, that isn't what I want to do.

I currently have the drop down box & that works perfectly fine with
the javascript function shown above. What I'm trying to do is
duplicate that functionality with a simple text link or button. What
I want to do has nothing to do with a drop down box. I simply posted
that as an example of what I currently have.


Then you will have to modify your function setExtent(). There are many ways
to achieve functionality you want. One way is this:

function setExtent(obj){
var sExt=obj.value;


Instead of this line put:
var sExt
if (setExtent.arguments.length > 1){
sExt=setExtent.arguments[1]
}
else{
sExt=obj.value;
}

That is not elegant solution, but if you want to *duplicate* functionality
with list-boxes, I think this is quite a good because you will not have to
modify yours list-boxes.

Then, you could add your button:

<button onclick="setExtent(null,
'10350350,3380230,10582000,3531280')">Test</button>
IE6 tested.
Regards

Vjekoslav
Jul 20 '05 #5
ma***************@yahoo.com (Jim Bond) wrote in message news:<1b**************************@posting.google. com>...
Hello,

<snip>

Just to follow up, I figured out the problem. I just needed to add
"value" to the onclick event. I thought I had tried that before, but
perhaps I mis-typed something. Anyways, I can now link directly from
text or an image button. Thanks for the replies & help!
Jul 20 '05 #6

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

Similar topics

3
by: Andy | last post by:
Hi, I am complete JavaScript novice and would really appreciate some help with this code: ===================================================================== <%@LANGUAGE="VBSCRIPT"...
6
by: David | last post by:
Hi, I have text link on each record displayed. This needs to open a new small window for entering some data, I cannot seem to fix it ? Hyperlink Code as is: ..... RS("Manual") &...
5
by: Mike | last post by:
In my previous post, I wrote: > ... > GOAL: (very simple) Provide a hyperlink which, when clicked, > calls a javascript function which opens a new URL. > ... > PROBLEM: The following code...
2
by: not | last post by:
Hello All, I am trying to develop a relatively simple self-quiz form in javascript, but I'm having no luck getting it to work. What I am looking for is a script that allow the user to select...
2
by: Morten | last post by:
Hi! I'm trying to have a button open a Window using javascript. I want to open a window pointing to a specific URL and close it imediately afterwards. I've registered a javascript block in my...
2
by: darren | last post by:
I have a small Javascript problem with that mutch love web browser safari, I tested the code on all other browsers PC (Win) and Linux and IE on the mac and it seams to work ok, but for some reason...
8
by: nkoriginal | last post by:
Hi: (this is a dummy question, I know, but I tried many times and I cant) I need to insert this javascript option inside the input, I can't insert any funtion in <head> I've this two...
1
by: jobs | last post by:
re: Attributes.Add Onclick (javascript) trapping CANCEL Hello. The following asp.net/vb.net code produces a confirmation Submitbutton.Attributes.Add("onClick", "return confirm('Is this...
2
by: prasath03 | last post by:
Dear Members, I am going to create the online form creation in html with javascript, i have a problem with the following code, i got this code from internet, the following script only works in IE...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...
0
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,...

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.