/    Sign up×
Community /Pin to ProfileBookmark

more alert boxes on one page…

Dear All!
I tried to put more alert boxes on one page and I got always the same alert clicking on each button!?

I ment it if I click the first to get the first alert, second button second alert, third button third alert,etc.
But it did not work.:mad:

What is the problem??
How to solve?
Many thanks!
M

to post a comment
JavaScript

17 Comments(s)

Copy linkTweet thisAlerts:
@marijaauthorJan 28.2009 — Please, help someone!
Copy linkTweet thisAlerts:
@FangJan 28.2009 — Show the code you have.

Patience, we are giving of our free time to help others.
Copy linkTweet thisAlerts:
@marijaauthorJan 28.2009 — </script>

<script type="text/javascript">

function myfunction()

{

alert("Ana");

}

</script>

<form>

<input type="button" onclick="myfunction()" value="a)">

</form>

<script type="text/javascript">

function myfunction()

{

alert("Marija");

}

</script>

<form>

<input type="button" onclick="myfunction()" value="b)">

</form>

<script type="text/javascript">

function myfunction()

{

alert("Robert");

}

</script>

<form><input type="button" onclick="myfunction()" value="c)">

</form>
Copy linkTweet thisAlerts:
@MaydayJan 28.2009 — You need to use unique identifiers for your functions

</script>

<script type="text/javascript">

function myfunction[COLOR="Red"]a[/COLOR]()

{

alert("Ana");

}

</script>

<form>

<input type="button" onclick="myfunction[COLOR="red"]a[/COLOR]()" value="a)">

</form>

<script type="text/javascript">

function myfunction[COLOR="red"]m[/COLOR]()

{

alert("Marija");

}

</script>

<form>

<input type="button" onclick="myfunction[COLOR="red"]m[/COLOR]()" value="b)">

</form>

<script type="text/javascript">

function myfunction[COLOR="red"]r[/COLOR]()

{

alert("Robert");

}

</script>

<form><input type="button" onclick="myfunction[COLOR="red"]r[/COLOR]()" value="c)">

</form>
[/QUOTE]
Copy linkTweet thisAlerts:
@skywalker2208Jan 28.2009 — You need to use unique identifiers for your functions[/QUOTE]

Or if you plan to use the same function over and over, but the string changes then pass the string in the parameters of the function.
Copy linkTweet thisAlerts:
@MaydayJan 28.2009 — Or you could do that. Replace where I orinignally said "need to" with "could". ?
Copy linkTweet thisAlerts:
@marijaauthorJan 28.2009 — :eek:

Dear All!

Thank You!

But I don tknow what are her ethe identifiers!

Sincerely,

M


(It shoudl be 3 buttons, pressing each should activate another answer on alert box!)
Copy linkTweet thisAlerts:
@skywalker2208Jan 28.2009 — :eek:

Dear All!

Thank You!

[B]But I don tknow what are her ethe identifiers![/B]

Sincerely,

M


(It shoudl be 3 buttons, pressing each should activate another answer on alert box!)[/QUOTE]

The doesn't make sense. I can't even figure out what you were going for there.
Copy linkTweet thisAlerts:
@marijaauthorJan 28.2009 — :eek: I appologose, started with that acutaly yesterday. Made a page with throw, sorry, and this should be function immitatin the alert box order! (withthe same effect!)

Please if u can help me with translation to the dummies speech!

THAK U ALL!

M
Copy linkTweet thisAlerts:
@marijaauthorJan 28.2009 — What is identifier?
Copy linkTweet thisAlerts:
@skywalker2208Jan 28.2009 — Mayday is talking about you declaring the same function 3 times on a page. If you want three different functions then you need to name them 3 different things. What i was saying is if the function is going to perform the same action, but some variable changes like the string you want to pop up in the alert box then pass thing string through the functions parameters.
Copy linkTweet thisAlerts:
@marijaauthorJan 28.2009 — Click on a should show "a dog", on b "a cat" and on c "a mouse". But all show "A mouse."

What is identifier in this situation?

Please help someone!

Thanks in advance!

M
Copy linkTweet thisAlerts:
@marijaauthorJan 28.2009 — :eek:

Many thanks, Skywalker, but how to do that? I tried to strt each with <html><body> and finnish that way but did nto work ( well I dont know, just dont know where to find out!!!)
Copy linkTweet thisAlerts:
@marijaauthorJan 28.2009 — <script type="text/javascript">

function myfunction(){alert("A dog");}

</script>

<form><input type="button" onclick="myfunction()" value="a)"></form>

<br>

<br>

<script type="text/javascript">

function myfunction(){alert("A cat ");}

</script>

<form><input type="button" onclick="myfunction()" value="b)"></form>

<script type="text/javascript">

function myfunction(){alert("A mouse");}

</script>

<form><input type="button" onclick="myfunction()" value="C"></form>
Copy linkTweet thisAlerts:
@marijaauthorJan 28.2009 — ...to pass the string in the parameters of the function... unfortunately just dont get it ...
Copy linkTweet thisAlerts:
@skywalker2208Jan 28.2009 — [code=php]
<script type="text/javascript">
function myfunction(mystring)
{
alert(mystring);
}
</script>
<form>
<input type="button" onclick="myfunction('string1')" value="a)">
</form>

<form>
<input type="button" onclick="myfunction('string2')" value="b)">
</form>

<form><input type="button" onclick="myfunction('string3')" value="c)">
</form>
[/code]


If you look there is only one function declaration, but there are three calls to the same function passing a string value (string1, string2, string3).
Copy linkTweet thisAlerts:
@MaydayJan 28.2009 — Skywalker's solution will work very well for you. However, as I noted in my original suggestion, your problem lies in the fact that the way you set it up, you keep declaring your function as "myfunction" each time, yet you are trying to get it to return 3 different things - the function needs to be called something different if you use it multiple times. - note the [COLOR="Red"]red[/COLOR] numbers in the amended code below

<script type="text/javascript">

function myfunction(){alert("A dog");}

</script>

<form><input type="button" onclick="myfunction()" value="a)"></form>

<br>

<br>

<script type="text/javascript">

function myfunction[COLOR="red"]1[/COLOR](){alert("A cat ");}

</script>

<form><input type="button" onclick="myfunction[COLOR="red"]1[/COLOR]()" value="b)"></form>

<script type="text/javascript">

function myfunction[COLOR="red"]2[/COLOR](){alert("A mouse");}

</script>

<form><input type="button" onclick="myfunction[COLOR="red"]2[/COLOR]()" value="C"></form>
[/QUOTE]






You don't HAVE to call them myfunction1 and myfunction2, I simply named them as an example. They could just as easily be myfunctioncat, myfunctionmouse, myfunctiondog or myfunctionhugo, myfunctiongeorge, myfunction382, or whatever.



So, you can change your code as suggested by Skywalker, or if you leave your code as typed, just make sure each function is named differently.
×

Success!

Help @marija 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 4.26,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...