Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Onclick script question

Status
Not open for further replies.

bryanfl100

Technical User
Dec 2, 2005
17
US
In the java code below is there a way that if someone clicks on the 'Order Now' link it pops up and alert saying "Please call us to order." if only the following happens:

1. The data in the hyperlink is not "Dell"

The java code is: <A HREF="javascript:eek:rderNow('computers.id%3D$data[computers.id]')" class="ordernow">Order Now</A>
 
Code:
<script>
function popup()
	{
		alert("please call to order");
	}
</script>
<html>


<button onClick="javascript:popup();"> call to order </button>
<html>
You can call the function popup in when you call
Code:
"javascript:orderNow('computers.id%3D$data[computers.id]')"

Is this what your looking for?

I don't know the answer but my good friend Google does.
 
no.

change your anchor tag to something like this:

Code:
<A HREF="#" onclick="if(this.innerHTML.indexOf('Dell')>-1)orderNow('computers.id%3D$data[computers.id]');return false;" class="ordernow">

it might be better for you to modify your orderNow function though.

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Hummm... the script did not work. Is there something I am missing?
 
let's do this again.

Code:
<a href="#" onclick="dispatch('computers.id%3D$data[computers.id]',this.innerHTML); return false;">

Code:
function dispatch(s,t) {
    // if Dell shows up, don't redirect
    if ( t.indexOf('Dell')>-1 ) {
        alert('call us');
    } else {
        orderNow(s);
    }
}

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
For some reason it does not popup an alert box saying 'call us' and the URL only shows a # sign and does not insert the data in the actual URL. Seems to be closer though :)
 
my misunderstanding. i apologize. try this:
Code:
function dispatch(s) {
    // if Dell shows up, don't redirect
    if ( s.indexOf('Dell')>-1 ) {
        alert('call us');
    } else {
        orderNow(s);
    }
}

Code:
<a href="#" onclick="dispatch('computers.id%3D$data[computers.id]'); return false;">Order Now</a><br />

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Excellent script! The only thing I see is this:

1. dispatch needs to be orderNow for example:
onclick="orderNow('computers.id%3D$data[computers.id]');

2. The alert was on 'Dell' and what I needed was the alert to be on everything else but 'Dell'

Thanks for the assistance so far!
 
1) no, i wrote another function to handle it. that's what the dispatch function does.

2) just do this:

Code:
function dispatch(s) {
    // if Dell does not show up, redirect
    if ( s.indexOf('Dell')>-1 ) {
        orderNow(s);
    } else {
        alert('call us');
    }
}

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top