Solved

Javascript not firing from onclick event

Posted on 2009-06-29
5
660 Views
Last Modified: 2013-11-19
Hi,

I am trying to fire a small javascript function from a form button.  The problem is that I can not even get it to fire when I click - if you look at the code I have put an alert at the top just to take a string to see if it is working.

What have I got wrong

Thanks
<form id="frm_app_button" name="frm_app_button" action="" method="post"> 
    <input type="text" name="AppId" id="AppId" />
    <input type="submit" name="Submit" value="Submit" id="submit" onclick="AppWarning('yes');"  />
    </form>
 
 
function AppWarning( str )
	{
	alert (str);
	var jstr = "The following ids will be approved.  Is this correct" ;
	var vals = document.frm_app_button.AppId.value;
	var x = jstr + ' ' + vals;
	var answer = Confirm: (x);
		{
		if (answer)
			alert("You said: Ok");
		else
			alert("You said: Cancel");
		}
	}

Open in new window

0
Comment
Question by:wobbled
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24737155
Is the function defined within <script> tags?
0
 
LVL 17

Author Comment

by:wobbled
ID: 24737193
Yes it is - I just missed them off when copying them into the code window for the question
0
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24737204
You have to put your javascript inside script tags.

Also, as a test, try this:

<input type="submit" name="Submit" value="Submit" id="submit" onclick="AppWarning('yes'); return false;"  />

This should fire the alert but not submit the form.  It's possible the form is being submitted and killing your alert before you see it.

It looks like you're trying to do an "Are you sure?" button.  If that's the case, there are much simpler ways to do that.

Here's an example:

http://www.codingforums.com/showthread.php?t=143947
<form id="frm_app_button" name="frm_app_button" action="" method="post"> 
    <input type="text" name="AppId" id="AppId" />
    <input type="submit" name="Submit" value="Submit" id="submit" onclick="AppWarning('yes');"  />
    </form>
 
<script> 
function AppWarning( str )
        {
        alert (str);
        var jstr = "The following ids will be approved.  Is this correct" ;
        var vals = document.frm_app_button.AppId.value;
        var x = jstr + ' ' + vals;
        var answer = Confirm: (x);
                {
                if (answer)
                        alert("You said: Ok");
                else
                        alert("You said: Cancel");
                }
        }
</script>

Open in new window

0
 
LVL 15

Accepted Solution

by:
mohan_sekar earned 250 total points
ID: 24737210
small typo in your code -> change the original statement to var answer = confirm(x);
0
 
LVL 17

Author Closing Comment

by:wobbled
ID: 31656991
Cheers for that - I didn't see the typo.

Thanks to everyone who posted a reply
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem to copy file 14 52
15 puzzle in Javascript/html 2 44
Calculating percentage 2 30
How do i use the await event in php echo 5 19
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question