Solved

Javascript onsubmit script / string

Posted on 2016-07-20
3
71 Views
Last Modified: 2016-07-21
I have an onsubmit process that looks like

<form onsubmit="return confirm('Are you sure you want to change the dates on this reservation to those new dates?');"

What I'd like to do is change that string to incorporate some text from some form fields in the document.

I tried

onsubmit="return confirm('Are you sure you want to change the dates on this reservation to '+document.getElementByID('datepicker3').value+' to '+document.getElementById('datepicker4').value');"

but alas - it didn't work nor have any of the other variations kinda similar to that.

What am I missing?  

Thanks in advance!
0
Comment
Question by:erzoolander
3 Comments
 
LVL 9

Expert Comment

by:lisfolks
ID: 41721975
Your statement has an extra tick mark... is that in the code? Breaking it up for readability, it looks like this:

onsubmit="
return confirm(
'Are you sure you want to change the dates on this reservation to ' +
document.getElementByID('datepicker3').value +
' to ' +
document.getElementById('datepicker4').value'
);
"

See the extra tick mark at the end of the bolded part?
0
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 41722014
or for easier readability, move it to its own function:
<form onsubmit="return checkForm()">
...
</form>
<script>
function checkForm() {
    var dt3 = document.getElementByID('datepicker3').value;
    var dt4 = document.getElementByID('datepicker4').value;
    return confirm('Are you sure you want to change the dates on this reservation from '+dt3+' to '+dt4);
}
</script>

Open in new window

0
 
LVL 1

Author Closing Comment

by:erzoolander
ID: 41723729
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now